aboutsummaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/craftmine.js14
-rw-r--r--js/dungeon.js42
-rw-r--r--js/shop.js42
3 files changed, 82 insertions, 16 deletions
diff --git a/js/craftmine.js b/js/craftmine.js
index 4e6490f..61abbf7 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,8 +1,11 @@
data = {
+ name: "You",
gold: 0,
mine: 0,
miners: 0,
- level: 1
+ level: 1,
+ hp: 1,
+ icon : "H"
}
function sendRequest(url, params, callback, isFile) {
@@ -11,7 +14,10 @@ function sendRequest(url, params, callback, isFile) {
if(!isFile) xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") {
- var data = JSON.parse(xhr.responseText);
+ var data = "";
+ if(xhr.responseText) data = JSON.parse(xhr.responseText);
+ if(data.info)
+ showInfo(data.info);
if(data.error) {
showError(data.error);
return;
@@ -47,10 +53,12 @@ function withdrawMine() {
function initCraftMine() {
sendRequest("craftmine.php", "op=getCraftMine", function(ret) {
data.gold = parseInt(ret.gold); // Server's response is a string
+ data.mine = 0; // Reset mine
if(ret.shop) displayShop(ret.shop);
displayInventory(ret.inventory);
+ if(ret.dungeon) displayDungeon();
data.miners = parseInt(ret.miners);
- updateData("gold","miners");
+ updateData("gold", "mine", "miners");
})
}
diff --git a/js/dungeon.js b/js/dungeon.js
new file mode 100644
index 0000000..d20a3cf
--- /dev/null
+++ b/js/dungeon.js
@@ -0,0 +1,42 @@
+function buildDungeon(){
+ sendRequest("craftmine.php", "op=buildDungeon", function(ret) {
+ displayDungeon();
+ debitAccount(ret.cost);
+ showInfo("You can acces the dungeon now. Good Luck.");
+ });
+}
+
+function displayDungeon(){
+ var tmphtml = "<br/>";
+ tmphtml += "<button id=\"launch\" type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon()\">Launch</button>";
+ document.getElementById("tab4").innerHTML = tmphtml;
+}
+
+function launchDungeon(){
+ sendRequest("craftmine.php", "op=launchDungeon", function(ret) {
+ document.getElementById("launch").style.display = "none";
+ displayBattle(ret);
+ });
+}
+
+function displayBattle(ret){
+ var tmphtml = "<div class=\"row\">";
+ tmphtml += "<h4>Battle</h4>";
+ tmphtml += "<ul class=\"list-inline\">";
+ tmphtml += "<li>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" style=\"margin-left:30px;\"><span class=\"item-icon\">" + data.icon + "</span><br />" + data.name + "<br/> lv: " + data.level + " <span id=\"lifeMob\">hp: " + data.hp + "</span></button>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" style=\"margin-left:30px;\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "<br/> lv: " + ret[0].level + " <span id=\"lifeMob\">hp: " + ret[0].hp + "</span></button>";
+ tmphtml += "</li>";
+ tmphtml += "</ul>";
+ tmphtml += "</div>";
+ tmphtml += "<br/><br/>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"exitDungeon()\">Exit</button>";
+ document.getElementById("tab4").innerHTML = tmphtml;
+}
+
+function exitDungeon(){
+ sendRequest("craftmine.php", "op=exitDungeon", function() {
+ document.getElementById("tab4").innerHTML = "<h4>Look at how poor you are! You can't access the dungeon, it is only for the elite.</h4>";
+ showInfo("You have left the dungeon");
+ });
+}
diff --git a/js/shop.js b/js/shop.js
index 22ca85f..bda3885 100644
--- a/js/shop.js
+++ b/js/shop.js
@@ -1,12 +1,20 @@
function displayShop(ret) {
- var tmphtml = "<h4> Select an item to buy it:</h4>";
- tmphtml += "<ul class=\"list-inline\">";
- for(var i=0; i < ret.items.length; i++) {
- tmphtml += "<li>";
- tmphtml += "<button type=\"submit\" class=\"btn btn-primary\" onclick=\"buyItem('" + ret.items[i].name + "')\"><span class=\"item-icon\">" + ret.items[i].icon + "</span><br />" + ret.items[i].name + "</button>";
- tmphtml += "</li>";
+ var tmphtml = "<h3> Select an item to buy it:</h3>";
+ for(var key in ret.items){
+ if(ret.items.hasOwnProperty(key)){
+ var category = ret.items[key];
+ tmphtml += "<div class=\"row\">";
+ tmphtml += "<h4>"+key+"</h4>";
+ tmphtml += "<ul class=\"list-inline\">";
+ for(var i=0; i < category.length; i++) {
+ tmphtml += "<li>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"buyItem('" + category[i].name + "')\"><span class=\"item-icon\">" + category[i].icon + "</span><br />" + category[i].name + "</button>";
+ tmphtml += "</li>";
+ }
+ tmphtml += "</ul>";
+ tmphtml += "</div>";
+ }
}
- tmphtml += "</ul>"
document.getElementById("tab2").innerHTML = tmphtml;
}
@@ -20,14 +28,22 @@ function buildShop() {
sendRequest("craftmine.php", "op=buildShop", function(ret) {
displayShop(ret);
debitAccount(ret.cost);
+ showInfo("Your shop has been successfully created");
});
}
function addItem(ret) {
- var itemhtml = "<li>";
- 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 itemhtml = "";
+ var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]");
+ if(!itemtag){ //si c'est la première itération de l'objet
+ itemhtml += "<li>";
+ itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret[0].name + "')\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "(<span data-name=\""+ ret[0].name + "\">"+ret[1]+"</span>)</button>";
+ itemhtml += "</li>";
+ }
+ else{ // si c'est une n-ième itération
+ itemtag.innerHTML=ret[1];
+ }
+
var invcontent = document.getElementById("tab3");
if(invcontent.children.length <= 1)
@@ -40,13 +56,13 @@ function addItem(ret) {
} else
invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml;
- showInfo(ret.desc);
+ showInfo("The "+ ret[0].name + " has been successfully purchased");
}
function buyItem(name) {
sendRequest("craftmine.php", "op=buyItem&item="+name, function(ret) {
addItem(ret);
- debitAccount(ret.cost);
+ debitAccount(ret[0].cost);
});
}