aboutsummaryrefslogtreecommitdiffstats
path: root/js/dungeon.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/dungeon.js')
-rw-r--r--js/dungeon.js82
1 files changed, 69 insertions, 13 deletions
diff --git a/js/dungeon.js b/js/dungeon.js
index d20a3cf..c6ce014 100644
--- a/js/dungeon.js
+++ b/js/dungeon.js
@@ -1,41 +1,97 @@
+var timeout;
+
function buildDungeon(){
sendRequest("craftmine.php", "op=buildDungeon", function(ret) {
- displayDungeon();
+ displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first dungeon
debitAccount(ret.cost);
showInfo("You can acces the dungeon now. Good Luck.");
});
}
-function displayDungeon(){
+function displayDungeon(nb,f,firstTime){
var tmphtml = "<br/>";
- tmphtml += "<button id=\"launch\" type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon()\">Launch</button>";
+ tmphtml += "<button id=\"launch\" type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon("+nb+","+f+","+firstTime+")\">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 launchDungeon(nb,f,firstTime){
+ sendRequest("craftmine.php", "op=launchDungeon&floor="+f, function(ret) {
+ if(nb==0 && firstTime){
+ document.getElementById("launch").style.display = "none";
+ }
+ displayBattle(ret,nb,f);
});
}
-function displayBattle(ret){
+function displayBattle(ret,nb,f){
var tmphtml = "<div class=\"row\">";
- tmphtml += "<h4>Battle</h4>";
+ tmphtml += "<h4>Battle floor "+ f +"</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 += "<button type=\"button\" class=\"btn btn-primary\" id=\"perso\" style=\"margin-left:30px;\"><span class=\"item-icon\">" + data.icon + "</span><br />" + data.name + "<br/> lv: " + data.level + " hp: <span id=\"lifePerso\">" + data.hp + "</span></button>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" id=\"mob\" style=\"margin-left:30px;\">"
+ +"<span class=\"item-icon\">" + ret[nb].icon + "</span><br />" + ret[nb].name + "<br/>"
+ +" lv: " + ret[nb].level + " hp: <span id=\"lifeMob\">" + ret[nb].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;
+ displayExit();
+ battle(ret,nb,f);
+}
+
+function battle(ret,nb,f){
+ timeout=window.setTimeout(strike, 1000, ret, nb, f);
+}
+
+function strike(ret,nb, f){
+ var lvDiff = data.level-parseInt(ret[0].level);
+ var hitRate = Math.floor((Math.random() * 100) + 1);
+ var mobLife = document.getElementById("lifeMob").innerHTML;
+ var persoLife = document.getElementById("lifePerso").innerHTML;
+ if(mobLife == 0){
+ endBattle("perso",nb,f);
+ return;
+ }
+ else if(persoLife == 0){
+ endBattle("mob",nb);
+ return;
+ }
+ if(hitRate<50+10*lvDiff){
+ mobLife--;
+ document.getElementById("lifeMob").innerHTML = parseInt(mobLife);
+ }
+ else{
+ persoLife--;
+ document.getElementById("lifePerso").innerHTML = parseInt(persoLife);
+ }
+ battle(ret,nb,f);
+}
+
+function endBattle(v,nb, f){
+ window.clearTimeout(timeout);
+ if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon
+ nb++;//go to the next mob in the same floor
+ if(nb>=3){//floor changing
+ nb=0;//reset the number of the mob
+ f++;//increment the number of the floor
+ }
+ var tmphtml = "Le " + v + " a gagné.";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon("+nb+","+ f +",false)\">Next Battle</button>"
+ document.getElementById("tab4").innerHTML = tmphtml;
+ displayExit();
+ sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb);
+}
+
+function displayExit(){
+ var 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() {
+ window.clearTimeout(timeout);
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");
});