diff options
author | piernov <piernov@piernov.org> | 2016-04-25 19:10:53 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-04-25 19:10:53 +0200 |
commit | 8770f9ddccfafaad935f66ccbf254624b41545f3 (patch) | |
tree | e07d2e93e95a34e9f70f22f52aafa82c09682e4b /js | |
parent | b141eb3d70b3dc2d75ee8f2bf2edba1fed71f5b6 (diff) | |
parent | 8140617aeb2f32f7095a443ca743c6d6915739c6 (diff) | |
download | candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.gz candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.bz2 candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.xz candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.zip |
Merge remote-tracking branch 'origin/alexichi' into piernov
Diffstat (limited to 'js')
-rw-r--r-- | js/craftmine.js | 5 | ||||
-rw-r--r-- | js/craftmine.js~ | 51 | ||||
-rw-r--r-- | js/guild.js | 17 | ||||
-rw-r--r-- | js/shop.js | 2 |
4 files changed, 21 insertions, 54 deletions
diff --git a/js/craftmine.js b/js/craftmine.js index 66c35fc..92fa45a 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,7 +1,7 @@ data = { gold: 0, mine: 0, - miners: 1, + miners: 0, level: 1 } @@ -49,7 +49,8 @@ function initCraftMine() { data.gold = parseInt(ret.gold); // Server's response is a string if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - updateData("gold"); + data.miners = parseInt(ret.miners); + updateData("gold","miners"); }) } diff --git a/js/craftmine.js~ b/js/craftmine.js~ deleted file mode 100644 index bc03d6c..0000000 --- a/js/craftmine.js~ +++ /dev/null @@ -1,51 +0,0 @@ -datas = { - gold: 0, - mine: 0, - miners: 1, - level: 1 -} - -function sendRequest(url, params, callback) { - var xhr = new XMLHttpRequest(); - xhr.open("POST", url); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhr.onreadystatechange = function() { - if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { - callback(xhr); - } - } - xhr.send(params); -} - - -function updateDatas(t) { - document.getElementById(t).innerHTML = datas[t]; -} - -function withdrawMine() { - sendRequest("craftmine.php", "op=withdrawMine", function() { - datas.gold += parseInt(datas.mine); - datas.mine = 0; - updateDatas("gold"); - updateDatas("mine"); - }) -} - -function initCraftMine() { - sendRequest("craftmine.php", "op=getCraftMine", function(xhr) { - var ret = xhr.responseText; - datas.gold = ret; - updateDatas("gold"); - }) -} - - -function updateMine() { - datas.mine += (datas.mineurs+1); - updateDatas("mine"); -} - -function init() { - initCraftMine(); - window.setInterval(updateMine, 1000); -} diff --git a/js/guild.js b/js/guild.js new file mode 100644 index 0000000..8d4d91b --- /dev/null +++ b/js/guild.js @@ -0,0 +1,17 @@ +function hireMiner(){ + sendRequest("craftmine.php", "op=hireMiner", function(ret) { + debitAccount(parseInt(ret.cost)); + data.miners = parseInt(ret.miners); + updateData("miners"); + } + ) +} + +function createGuild(){ + sendRequest("craftmine.php", "op=createGuild", function(ret) { + showInfo("Your guild has been successfully created"); + debitAccount(parseInt(ret.cost)); + } + ) +} + @@ -25,7 +25,7 @@ function buildShop() { function addItem(ret) { var itemhtml = "<li>"; - itemhtml += "<button type=\"submit\" class=\"btn btn-primary\" onclick=\"useItem('" + ret.name + "')\"><span class=\"item-icon\">" + ret.icon + "</span><br />" + ret.name + "</button>"; + itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret.name + "')\"><span class=\"item-icon\">" + ret.icon + "</span><br />" + ret.name + "</button>"; itemhtml += "</li>"; var invcontent = document.getElementById("tab3"); |