From 2f32bc3153b7f2c2561e4603f912573921e6449f Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 9 May 2016 20:26:51 +0200 Subject: add the use of the objects and the feature power and maxHP --- js/craftmine.js | 17 +++++++++++++++-- js/dungeon.js | 35 +++++++++++++++++++---------------- js/perso.js | 24 ++++++++++++++++++++++-- js/shop.js | 2 -- 4 files changed, 56 insertions(+), 22 deletions(-) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 77cafee..fa70809 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,8 +5,11 @@ data = { miners: 0, level: 3, hp: 5, + maxHP: 5, xp: 0, - icon : "H" + power: 3, + bonusPower: 0, + icon : "💪" } function sendRequest(url, params, callback, isFile) { @@ -41,6 +44,16 @@ function debitAccount(amount) { updateData("gold"); } +function creditAccount(amount){ + data.gold += amount; + sendRequest("craftmine.php", "op=withdrawMine&amount="+amount, function(xhr) { + var gold = parseInt(xhr); + if(isNaN(gold)) return; + data.gold = gold; + updateData("gold"); + }); +} + function withdrawMine() { sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) { var gold = parseInt(xhr); // Server's response is a string @@ -53,7 +66,7 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { - console.log(ret.perso); + //console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine if(ret.perso) updatePerso(ret.perso); diff --git a/js/dungeon.js b/js/dungeon.js index 6ebf4dd..2921c7d 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -2,7 +2,7 @@ var timeout; function buildDungeon(){ sendRequest("craftmine.php", "op=buildDungeon", function(ret) { - displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first dungeon + displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first time debitAccount(ret.cost); showInfo("You can acces the dungeon now. Good Luck."); }); @@ -45,21 +45,23 @@ function battle(ret,nb,f){ } function strike(ret,nb, f){ - var lvDiff = data.level-parseInt(ret[0].level); + var powerDiff = (data.power+data.bonusPower)-parseInt(ret[nb].power); var hitRate = Math.floor((Math.random() * 100) + 1); var mobLife = document.getElementById("lifeMob").innerHTML; var persoLife = document.getElementById("lifePerso").innerHTML; if(mobLife == 0){ data.hp = persoLife; + data.bonusPower = 0; //à revoir car l'épée doit continuer à apporter un bonus endBattle("perso",nb,f,ret); return; } else if(persoLife == 0){ data.hp = 1; + data.bonusPower = 0;//when you die you lose your sword and all your power bonus endBattle("mob",nb,f,ret); return; } - if(hitRate<50+10*lvDiff){ + if(hitRate<50+10*powerDiff){ mobLife--; document.getElementById("lifeMob").innerHTML = parseInt(mobLife); } @@ -76,15 +78,7 @@ function endBattle(v,nb, f, ret){ //To level up you have to obtain 2 xp to go to lv 3, 3 to go to lv 4, etc //A mob level 2 , if defeated gives you 2 xp, ...etc else{ - data.xp += parseInt(ret[nb].xp); - if(data.xp>=data.level){ - data.xp-=data.level; - data.level++; - //need to send the xp to the server - sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ - displayPerso(data.hp,data.xp,data.level); - }); - } + levelUp(ret[nb].xp); nb++;//go to the next mob in the same floor if(nb>=3){//floor changing nb=0;//reset the number of the mob @@ -100,8 +94,8 @@ function endBattle(v,nb, f, ret){ displayExit(); sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } - sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ - displayPerso(data.hp,parseInt(data.xp),data.level); + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level+"&power="+data.power+"&bonusPower="+data.bonusPower, function(){ + displayPerso(data.hp,data.maxHP,data.xp,data.level,data.power,data.bonusPower); }); } @@ -114,8 +108,17 @@ function displayExit(){ function exitDungeon(boss){ sendRequest("craftmine.php", "op=exitDungeon", function() { window.clearTimeout(timeout); - document.getElementById("tab4").innerHTML = "

Not available, you have to buy a ticket in the build section.

"; - if(boss) showInfo("You have beaten the final boss! CONGRATULATIONS!"); + if(boss){//if the boss is beaten + levelUp(20);//you earn 20 xp + creditAccount(1000);//you earn 1000 gold coins + var tmphtml = "

You have completed the dungeon! CONGRATULATIONS!

"; + tmphmtl += ""; + document.getElementById("tab4").innerHTML = tmphtml; + } + else document.getElementById("tab4").innerHTML = "

Not available, you have to buy a ticket in the build section.

"; showInfo("You have left the dungeon"); }); } diff --git a/js/perso.js b/js/perso.js index 02a8892..44b82eb 100644 --- a/js/perso.js +++ b/js/perso.js @@ -1,12 +1,32 @@ -function displayPerso(hp,xp,lv){ +function displayPerso(hp,maxHP,xp,lv,power,bonusPower){ document.getElementById("hp").innerHTML = hp; + document.getElementById("maxHP").innerHTML = maxHP; document.getElementById("lv").innerHTML = lv; document.getElementById("xp").innerHTML = xp; + document.getElementById("power").innerHTML = power; + document.getElementById("bonusPower").innerHTML = bonusPower; } function updatePerso(perso) { data.hp = perso.hp; + data.maxHP = perso.maxHP; data.xp = perso.xp; data.level = perso.lv; - displayPerso(perso.hp, perso.xp, perso.lv); + data.power = perso.power; + data.bonusPower = perso.bonusPower; + displayPerso(perso.hp, perso.maxHP, perso.xp, perso.lv, perso.power, perso.bonusPower); +} + +function levelUp(xp){ + data.xp += parseInt(xp); + while(data.xp>=data.level){ + data.xp-=data.level; + data.level++; + data.power++; + data.maxHP+=2; + } + //need to send the xp to the server + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level+"&power="+data.power+"&bonusPower="+bonusPower, function(){ + displayPerso(data.hp,data.maxHP,data.maxHP,data.xp,data.level,data.power,data.bonusPower); + }); } diff --git a/js/shop.js b/js/shop.js index a520a38..b6d4cee 100644 --- a/js/shop.js +++ b/js/shop.js @@ -69,10 +69,8 @@ function useItem(name) { sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) { if(!ret.item) return; if(ret.perso) updatePerso(ret.perso); - var item = document.querySelector("[data-name=\""+ret.item[0].name+"\"]"); var nb = ret.item[1]; - if(nb>=1) item.innerHTML = nb; else -- cgit v1.2.3-54-g00ecf