From 349c6fe7ecf10e5929dc27c2446853f0fe416077 Mon Sep 17 00:00:00 2001 From: alexichi Date: Wed, 27 Apr 2016 12:59:51 +0200 Subject: add loadShop() and categories in the xml file and modify the presentation of the items in the shop --- js/shop.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/shop.js b/js/shop.js index 22ca85f..efd6ac5 100644 --- a/js/shop.js +++ b/js/shop.js @@ -1,12 +1,20 @@ function displayShop(ret) { - var tmphtml = "

Select an item to buy it:

"; - tmphtml += "" document.getElementById("tab2").innerHTML = tmphtml; } @@ -40,7 +48,7 @@ function addItem(ret) { } else invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml; - showInfo(ret.desc); + showInfo("The "+ ret.name + " has been successfully purchased"); } function buyItem(name) { -- cgit v1.2.3-54-g00ecf From 2b0a84a41eeb90094d42c3c516bf99837d08a745 Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 27 Apr 2016 19:47:34 +0200 Subject: Automatically show received info --- js/craftmine.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..28583dd 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -12,6 +12,8 @@ function sendRequest(url, params, callback) { xhr.onreadystatechange = function() { if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { var data = JSON.parse(xhr.responseText); + if(data.info) + showInfo(data.info); if(data.error) { showError(data.error); return; -- cgit v1.2.3-54-g00ecf From 0133251e523b1c984b2b5cdb60c7392c18e6bd73 Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 27 Apr 2016 19:51:32 +0200 Subject: Add button for saving on server/downloading the game --- index.xhtml | 2 ++ js/craftmine.js | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'js') diff --git a/index.xhtml b/index.xhtml index aa29615..d12585f 100644 --- a/index.xhtml +++ b/index.xhtml @@ -32,6 +32,8 @@
+ +
diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..13dd0a2 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -60,6 +60,14 @@ function updateMine() { updateData("mine"); } +function saveGame() { + sendRequest("craftmine.php", "op=saveGame"); +} + +function downGame() { + window.open("craftmine.php?op=downGame", "_blank"); +} + function init() { initCraftMine(); changeTab(); -- cgit v1.2.3-54-g00ecf From 48ca3e8ee63787d567fd0fe1bcfea7158a6f9596 Mon Sep 17 00:00:00 2001 From: alexichi Date: Fri, 29 Apr 2016 21:06:59 +0200 Subject: add the option to not create 2 objects of the same type, doesn't work well --- inc/Inventory.inc | 14 ++++++++++++-- inc/shop.inc | 4 ++-- js/shop.js | 19 +++++++++++++------ 3 files changed, 27 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/inc/Inventory.inc b/inc/Inventory.inc index efe54f2..3396eb9 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -20,12 +20,21 @@ class Inventory { } private function _addItem($item) { - $this->items[] = $item; + $counter = 0; + foreach($this->items as $object){ + if($object[0] == $item){ + $counter++; + } + } + $tab = array($item,$counter+1); + $this->items[] = $tab; + return $tab; } public static function addItem($item) { $inv = self::get(); - $inv->_addItem($item); + $tab = $inv->_addItem($item); + return $tab; } private function _removeItem($item) { @@ -36,6 +45,7 @@ class Inventory { $inv = self::get(); $inv->_removeItem($item); } + } ?> diff --git a/inc/shop.inc b/inc/shop.inc index 6e30923..83b08b0 100644 --- a/inc/shop.inc +++ b/inc/shop.inc @@ -56,8 +56,8 @@ function buildShop() { function buyItem() { $item = getItem($_POST["item"]); if($item && debitAccount($item->cost)) { - Inventory::addItem($item); - echo json_encode($item); + $tab = Inventory::addItem($item); + echo json_encode($tab); //renvoyer un tableau avec comme première entrée $item et comme deuxième entrée le nombre } } diff --git a/js/shop.js b/js/shop.js index efd6ac5..00f13af 100644 --- a/js/shop.js +++ b/js/shop.js @@ -28,14 +28,21 @@ 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 = "
  • "; - itemhtml += ""; - itemhtml += "
  • "; - + var itemhtml = ""; + if(ret[1]==1){ //si c'est la première itération de l'objet + itemhtml += "
  • "; + itemhtml += ""; + itemhtml += "
  • "; + } + else if(ret[1]>1){ // si c'est une n-ième itération + document.getElementById("nbObjet").innerHTML=ret[1]; + } + var invcontent = document.getElementById("tab3"); if(invcontent.children.length <= 1) @@ -48,13 +55,13 @@ function addItem(ret) { } else invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml; - showInfo("The "+ ret.name + " has been successfully purchased"); + 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); }); } -- cgit v1.2.3-54-g00ecf From 31866085151518f468794dc71b541543e6b2f691 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 1 May 2016 11:32:08 +0200 Subject: add the beginning part of the dungeon When you have enough money you can buy a ticket and access the dungeon I made a file monsters.xml . It's a bit like the code with the shop but modified When you press the button launch in the onglet dungeon , it display "Battle!" in the console --- craftmine.php | 3 ++- data/monsters.xml | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ inc/Monster.inc | 19 +++++++++++++++++ inc/dungeon.inc | 39 ++++++++++++++++++++++++++++++++++ inc/messages.inc | 3 ++- index.xhtml | 3 +++ js/dungeon.js | 18 ++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 data/monsters.xml create mode 100644 inc/Monster.inc create mode 100644 inc/dungeon.inc create mode 100644 js/dungeon.js (limited to 'js') diff --git a/craftmine.php b/craftmine.php index 78c5e37..4cd6b00 100644 --- a/craftmine.php +++ b/craftmine.php @@ -4,7 +4,7 @@ require_once("inc/mine.inc"); require_once("inc/guild.inc"); require_once("inc/shop.inc"); require_once("inc/craftmine.inc"); - +require_once("inc/dungeon.inc"); session_start(); // Must be placed *BEFORE* $_SESSION is actually used and *AFTER* all classes are imported /** @@ -42,6 +42,7 @@ switch($op) { case "getCraftMine": sendCraftMine(); break; case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; + case "buildDungeon" : buildDungeon(); break; default: reportBadRequest(); } diff --git a/data/monsters.xml b/data/monsters.xml new file mode 100644 index 0000000..86cf422 --- /dev/null +++ b/data/monsters.xml @@ -0,0 +1,63 @@ + + + + + monster1 + 1 + 2 + m + + + monster2 + 2 + 3 + m + + + monster3 + 3 + 4 + m + + + + + monster4 + 4 + 5 + m + + + monster5 + 5 + 6 + m + + + monster5 + 6 + 7 + m + + + + + monster6 + 8 + 9 + m + + + monster7 + 9 + 10 + m + + + Boss + 10 + 12 + m + + + diff --git a/inc/Monster.inc b/inc/Monster.inc new file mode 100644 index 0000000..fbb0fe9 --- /dev/null +++ b/inc/Monster.inc @@ -0,0 +1,19 @@ +name = $name; + $this->level = $level; + $this->hp = $hp; + $this->icon = $icon; + + } +} + +?> diff --git a/inc/dungeon.inc b/inc/dungeon.inc new file mode 100644 index 0000000..b2277f0 --- /dev/null +++ b/inc/dungeon.inc @@ -0,0 +1,39 @@ +(string)$monsters["cost"],"monsters"=>array()); + foreach($monsters as $f){ + $floor = (string)$f["name"]; + $dungeon["monsters"][$floor] = array(); + foreach($f as $monster){ + $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, + intval($monster->level), + intval($monster->hp), + (string)$monster->icon); + } + } + return $dungeon; +} + +function initDungeon() { + $_SESSION["dungeon"] = true; +} + +function buildDungeon() { + $dungeon=generateMonster(); + if(!empty($_SESSION["dungeon"])) { + sendError("dungeon_already_available"); + } + elseif(debitAccount($dungeon["cost"])) { + initDungeon(); + $_SESSION["mine"]["gold"] -= $dungeon["cost"]; + echo json_encode($dungeon); + } +} + +?> diff --git a/inc/messages.inc b/inc/messages.inc index d6ea87e..c24bd18 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -5,7 +5,8 @@ $messages = array( "gold_insufficient" => "You don't have enough gold.", "shop_missing_item" => "This item does not exist.", "guild_not_yet_created" => "You need to create a guild first.", - "guild_already_built" => "You have aready built a guild." + "guild_already_built" => "You have aready built a guild.", + "dungeon_already_available" => "You can already access the dungeon" ); function sendError($msg) { diff --git a/index.xhtml b/index.xhtml index aa29615..2745c8a 100644 --- a/index.xhtml +++ b/index.xhtml @@ -15,6 +15,8 @@ + +
    @@ -69,6 +71,7 @@
    • +
    diff --git a/js/dungeon.js b/js/dungeon.js new file mode 100644 index 0000000..1760afa --- /dev/null +++ b/js/dungeon.js @@ -0,0 +1,18 @@ +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 = "
    "; + tmphtml += ""; + //tmphtml += ""; + document.getElementById("tab4").innerHTML = tmphtml; +} + +function launchDungeon(){ + console.log("Battle!"); +} -- cgit v1.2.3-54-g00ecf From 64b1663e55544e1ed0e072c4f624688625691c9f Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 1 May 2016 13:55:08 +0200 Subject: Add dungeon without fight system You can buy a "ticket" to access the dungeon If you exit you have to buy another ticket Problem when we update the page, the default sentence is displayed while it said that you can access the dungeon --- craftmine.php | 2 ++ data/items.xml | 4 ++-- inc/dungeon.inc | 11 +++++++++++ js/craftmine.js | 5 ++++- js/dungeon.js | 30 +++++++++++++++++++++++++++--- 5 files changed, 46 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/craftmine.php b/craftmine.php index 4cd6b00..72817cc 100644 --- a/craftmine.php +++ b/craftmine.php @@ -43,6 +43,8 @@ switch($op) { case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; case "buildDungeon" : buildDungeon(); break; + case "launchDungeon" : launchDungeon(); break; + case "exitDungeon" : exitDungeon(); break; default: reportBadRequest(); } diff --git a/data/items.xml b/data/items.xml index 6c19b84..8888796 100644 --- a/data/items.xml +++ b/data/items.xml @@ -25,7 +25,7 @@ Life Bottle 5 - 🍶 + 💧 A bottle which can heal you by regaining hp @@ -34,7 +34,7 @@ 20 - 🍶 + 💧 If used, you have 20% more chance to hit your enemy during the battle diff --git a/inc/dungeon.inc b/inc/dungeon.inc index b2277f0..8c26c92 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -36,4 +36,15 @@ function buildDungeon() { } } +function launchDungeon(){ + $dungeon=generateMonster(); + $opponent = $dungeon["monsters"]["floor1"]; + echo json_encode($opponent); +} + +function exitDungeon(){ + $_SESSION["dungeon"] = false; + echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. +} + ?> diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..c40106c 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) { diff --git a/js/dungeon.js b/js/dungeon.js index 1760afa..d20a3cf 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -8,11 +8,35 @@ function buildDungeon(){ function displayDungeon(){ var tmphtml = "
    "; - tmphtml += ""; - //tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } function launchDungeon(){ - console.log("Battle!"); + sendRequest("craftmine.php", "op=launchDungeon", function(ret) { + document.getElementById("launch").style.display = "none"; + displayBattle(ret); + }); +} + +function displayBattle(ret){ + var tmphtml = "
    "; + tmphtml += "

    Battle

    "; + tmphtml += "
      "; + tmphtml += "
    • "; + tmphtml += ""; + tmphtml += ""; + tmphtml += "
    • "; + tmphtml += "
    "; + tmphtml += "
    "; + tmphtml += "

    "; + tmphtml += ""; + document.getElementById("tab4").innerHTML = tmphtml; +} + +function exitDungeon(){ + sendRequest("craftmine.php", "op=exitDungeon", function() { + document.getElementById("tab4").innerHTML = "

    Look at how poor you are! You can't access the dungeon, it is only for the elite.

    "; + showInfo("You have left the dungeon"); + }); } -- cgit v1.2.3-54-g00ecf From 556adda68fe99e3a88f59803aa9bd8892e4d34cf Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 2 May 2016 14:51:37 +0200 Subject: fix shop item count --- inc/Inventory.inc | 8 ++++---- js/shop.js | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 3396eb9..20c63bf 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -20,13 +20,13 @@ class Inventory { } private function _addItem($item) { - $counter = 0; - foreach($this->items as $object){ + foreach($this->items as $k => $object){ if($object[0] == $item){ - $counter++; + $this->items[$k][1]++; + return $this->items[$k]; } } - $tab = array($item,$counter+1); + $tab = array($item,1); $this->items[] = $tab; return $tab; } diff --git a/js/shop.js b/js/shop.js index 00f13af..bda3885 100644 --- a/js/shop.js +++ b/js/shop.js @@ -34,13 +34,14 @@ function buildShop() { function addItem(ret) { var itemhtml = ""; - if(ret[1]==1){ //si c'est la première itération de l'objet + var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]"); + if(!itemtag){ //si c'est la première itération de l'objet itemhtml += "
  • "; - itemhtml += ""; + itemhtml += ""; itemhtml += "
  • "; } - else if(ret[1]>1){ // si c'est une n-ième itération - document.getElementById("nbObjet").innerHTML=ret[1]; + else{ // si c'est une n-ième itération + itemtag.innerHTML=ret[1]; } var invcontent = document.getElementById("tab3"); -- cgit v1.2.3-54-g00ecf From b60d56327a1b8531d15348034889e67f8b49444d Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:44:28 +0200 Subject: Allow empty data from server --- js/craftmine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 8af8296..608efb7 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -11,7 +11,8 @@ function sendRequest(url, params, callback) { 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) { -- cgit v1.2.3-54-g00ecf From 6bff76321ab05d6193bc1d35327cb44128f9ed66 Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:45:44 +0200 Subject: Force reset mine on game reload --- js/craftmine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 608efb7..d649305 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -50,10 +50,11 @@ 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); data.miners = parseInt(ret.miners); - updateData("gold","miners"); + updateData("gold", "mine", "miners"); }) } -- cgit v1.2.3-54-g00ecf From f53549e4c2668ca268c8e31ef4c7cf3718fe08b5 Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:50:14 +0200 Subject: Move saveGame()/downGame() to its own JS file --- index.xhtml | 1 + js/craftmine.js | 8 -------- js/savegame.js | 7 +++++++ 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 js/savegame.js (limited to 'js') diff --git a/index.xhtml b/index.xhtml index d12585f..e879cf1 100644 --- a/index.xhtml +++ b/index.xhtml @@ -15,6 +15,7 @@ +
    diff --git a/js/craftmine.js b/js/craftmine.js index 13dd0a2..92fa45a 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -60,14 +60,6 @@ function updateMine() { updateData("mine"); } -function saveGame() { - sendRequest("craftmine.php", "op=saveGame"); -} - -function downGame() { - window.open("craftmine.php?op=downGame", "_blank"); -} - function init() { initCraftMine(); changeTab(); diff --git a/js/savegame.js b/js/savegame.js new file mode 100644 index 0000000..2a83f77 --- /dev/null +++ b/js/savegame.js @@ -0,0 +1,7 @@ +function saveGame() { + sendRequest("craftmine.php", "op=saveGame"); +} + +function downGame() { + window.open("craftmine.php?op=downSave", "_blank"); +} -- cgit v1.2.3-54-g00ecf From 8c0851a7d4db8be1bac99e034c745a45c64cc3ba Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:51:08 +0200 Subject: Add various JS functions to work with game save --- js/savegame.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'js') diff --git a/js/savegame.js b/js/savegame.js index 2a83f77..438be0a 100644 --- a/js/savegame.js +++ b/js/savegame.js @@ -1,3 +1,35 @@ +function listSaves() { + sendRequest("craftmine.php", "op=listSaves", function(ret) { + var tmphtml="" + for(var i=0; i" + ret[i] + "\n"; + } + console.log(tmphtml); + document.getElementById("listsaves").innerHTML = tmphtml; + }); +} + +function getCheckedSave() { + var radios = document.getElementsByName('saveRadio'); + for (var i = 0, length = radios.length; i < length; i++) { + if (radios[i].checked) return radios[i].parentNode.textContent; + } + return -1; +} + +function loadSave() { + sendRequest("craftmine.php", "op=loadSave&filename="+getCheckedSave(), function(ret) { + initCraftMine(); + }); +} + +function downloadSave() { + window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank"); +} + +function deleteSave() { +} + function saveGame() { sendRequest("craftmine.php", "op=saveGame"); } -- cgit v1.2.3-54-g00ecf From 0b72114561a685b247922a93c576edabd4d3b09e Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:59:16 +0200 Subject: Add ability to delete a save Doesn't work because idk which method to use and I don't have the PHP doc right now --- craftmine.php | 1 + inc/messages.inc | 2 ++ inc/savegame.inc | 7 +++++++ js/savegame.js | 3 +++ 4 files changed, 13 insertions(+) (limited to 'js') diff --git a/craftmine.php b/craftmine.php index 28bb49d..9a5d3d7 100644 --- a/craftmine.php +++ b/craftmine.php @@ -51,6 +51,7 @@ switch($op) { case "downSave": downSave(); break; case "listSaves": listSaves(); break; case "loadSave": loadSave(); break; + case "deleteSave": deleteSave(); break; default: reportBadRequest(); } diff --git a/inc/messages.inc b/inc/messages.inc index 955c0a0..5574bcf 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -10,6 +10,8 @@ $messages = array( "gamesave_ok" => "Game saved.", "gamesave_error" => "An error occured when trying to save the game.", "gamesave_not_found" => "Couldn't find the specified save file.", + "gamesave_delete_error" => "Couldn't delete the specified save file.", + "gamesave_delete_success" => "Game save successfully removed from server", ); function sendMessage($type, $msg) { diff --git a/inc/savegame.inc b/inc/savegame.inc index 79b1dae..eb4134f 100644 --- a/inc/savegame.inc +++ b/inc/savegame.inc @@ -71,6 +71,13 @@ function parseSave($xml, &$table) { // Passing $table by reference } } +function deleteSave() { + if(empty($_POST["filename"])) return; + $filename = $_POST["filename"]; + if(rm_file(SAVEDIR + "/" + $filename)) sendError("gamesave_delete_failed"); // TODO: find the correct method for removing a file… + else sendInfo("gamesave_delete_success"); +} + function loadSave() { if(empty($_POST["filename"])) return; $xml = simplexml_load_file(SAVEDIR . "/" . $_POST["filename"]); diff --git a/js/savegame.js b/js/savegame.js index 438be0a..4a08f91 100644 --- a/js/savegame.js +++ b/js/savegame.js @@ -28,6 +28,9 @@ function downloadSave() { } function deleteSave() { + sendRequest("craftmine.php", "op=deleteSave&filename="+getCheckedSave(), function(ret) { + listSaves(); + }); } function saveGame() { -- cgit v1.2.3-54-g00ecf From cbfbedcaceccda890a7f15cb806561ede72e8044 Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 20:14:17 +0200 Subject: Allow multiple classes on tabs --- js/gui.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/gui.js b/js/gui.js index bdf1710..89fa0fa 100644 --- a/js/gui.js +++ b/js/gui.js @@ -6,10 +6,8 @@ function changeTab() { var id = window.location.hash.substr(4); var tabs = document.querySelectorAll("#tabs-panel > ul > li"); for(var i=0; i < tabs.length; i++) { - if(i == id-1) - tabs[i].className = "active"; - else - tabs[i].className = ""; + if(i == id-1) tabs[i].classList.add("active"); // Doesn't work with IE < 10 (and Opera Mini), but who cares? + else tabs[i].classList.remove("active"); } } -- cgit v1.2.3-54-g00ecf From add9d3248a5adc02b071a301005c6f11195f7f7b Mon Sep 17 00:00:00 2001 From: alexichi Date: Tue, 3 May 2016 10:33:27 +0200 Subject: add dungeon client side to display it when reload --- inc/craftmine.inc | 4 +++- inc/dungeon.inc | 6 ++++++ js/craftmine.js | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/inc/craftmine.inc b/inc/craftmine.inc index 33a28d7..0d6a445 100644 --- a/inc/craftmine.inc +++ b/inc/craftmine.inc @@ -2,12 +2,14 @@ require_once("mine.inc"); require_once("shop.inc"); +require_once("dungeon.inc"); function sendCraftMine() { $data = array("gold" => sendMine(), "shop" => sendShop(), "inventory" => Inventory::sendContent(), - "miners" => sendMiners() + "miners" => sendMiners(), + "dungeon" => sendDungeon(), ); echo json_encode($data); } diff --git a/inc/dungeon.inc b/inc/dungeon.inc index 8c26c92..81e2ba7 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -24,6 +24,12 @@ function initDungeon() { $_SESSION["dungeon"] = true; } +function sendDungeon() { + if(!empty($_SESSION["dungeon"])) + return generateMonster(); + else return false; +} + function buildDungeon() { $dungeon=generateMonster(); if(!empty($_SESSION["dungeon"])) { diff --git a/js/craftmine.js b/js/craftmine.js index c40106c..7c37e59 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -52,6 +52,7 @@ function initCraftMine() { data.gold = parseInt(ret.gold); // Server's response is a string if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); + if(ret.dungeon) displayDungeon(); data.miners = parseInt(ret.miners); updateData("gold","miners"); }) -- cgit v1.2.3-54-g00ecf From 80f61cc5216fe020f82fc303317e4098acb5d21d Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 4 May 2016 14:27:59 +0200 Subject: AJAX upload file --- js/savegame.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/savegame.js b/js/savegame.js index 4a08f91..d5a9ba1 100644 --- a/js/savegame.js +++ b/js/savegame.js @@ -24,7 +24,9 @@ function loadSave() { } function downloadSave() { - window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank"); + var filename = getCheckedSave(); + if(filename == -1) downGame(); + else window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank"); } function deleteSave() { @@ -40,3 +42,18 @@ function saveGame() { function downGame() { window.open("craftmine.php?op=downSave", "_blank"); } + +function uploadSave() { + var selectedFile = document.getElementById("selectedFile"); + if(selectedFile.files[0].size > 2000000) { + showError("File is too big."); + return; + } + + var form = new FormData(); // Doesn't work with IE < 10 (and Opera Mini), but, as always, who cares? + form.append("savefile", selectedFile.files[0]); + + sendRequest("upload.php", form, function(ret) { + console.log(ret); + }, true); +} -- cgit v1.2.3-54-g00ecf From ec7771705d62d09fcd142c87f4941604f31c1d76 Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 4 May 2016 14:32:49 +0200 Subject: Don't send content-type when uploading file + update saves list when loading page --- js/craftmine.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..4e6490f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,10 +5,10 @@ data = { level: 1 } -function sendRequest(url, params, callback) { +function sendRequest(url, params, callback, isFile) { var xhr = new XMLHttpRequest(); xhr.open("POST", url); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + 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); @@ -63,5 +63,6 @@ function updateMine() { function init() { initCraftMine(); changeTab(); + listSaves(); window.setInterval(updateMine, 1000); } -- cgit v1.2.3-54-g00ecf From 35ec65de0869c77fc66bf3f2702c561efd98f4af Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 4 May 2016 14:52:35 +0200 Subject: Move onhashchange event hook from XHTML to JavaScript Add some comments --- index.xhtml | 2 +- js/craftmine.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/index.xhtml b/index.xhtml index bd2cdf3..f242f76 100644 --- a/index.xhtml +++ b/index.xhtml @@ -18,7 +18,7 @@ - +

    CraftMine

    diff --git a/js/craftmine.js b/js/craftmine.js index 61abbf7..0e95aa3 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -70,7 +70,8 @@ function updateMine() { function init() { initCraftMine(); - changeTab(); - listSaves(); - window.setInterval(updateMine, 1000); + changeTab(); // Switch to tab specified in URL + listSaves(); // Update save list on page load + window.setInterval(updateMine, 1000); // Increase mine amount every 1 second + window.onhashchange = changeTab; // Hook changeTab from js/gui.js to hashchange event } -- cgit v1.2.3-54-g00ecf From 1efc4a15c8ab913bf8bdb1aef9f3b5720b3b7762 Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 20:28:26 +0200 Subject: add dungeon server side and improve some details like the difference between floors --- craftmine.php | 1 + data/items.xml | 4 +-- data/monsters.xml | 2 +- inc/dungeon.inc | 16 ++++++++--- inc/messages.inc | 3 +- js/craftmine.js | 7 +++-- js/dungeon.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 90 insertions(+), 25 deletions(-) (limited to 'js') diff --git a/craftmine.php b/craftmine.php index 242e1fd..43fdc66 100644 --- a/craftmine.php +++ b/craftmine.php @@ -51,6 +51,7 @@ switch($op) { case "buildDungeon" : buildDungeon(); break; case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; + case "sendDungeonProgress" : sendDungeonProgress(); break; case "saveGame": saveGame(); break; case "downSave": downSave(); break; case "listSaves": listSaves(); break; diff --git a/data/items.xml b/data/items.xml index 8888796..6c19b84 100644 --- a/data/items.xml +++ b/data/items.xml @@ -25,7 +25,7 @@ Life Bottle 5 - 💧 + 🍶 A bottle which can heal you by regaining hp @@ -34,7 +34,7 @@ 20 - 💧 + 🍶 If used, you have 20% more chance to hit your enemy during the battle diff --git a/data/monsters.xml b/data/monsters.xml index 86cf422..630e83a 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -4,7 +4,7 @@ monster1 1 - 2 + 3 m diff --git a/inc/dungeon.inc b/inc/dungeon.inc index 81e2ba7..ebe74b7 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -21,12 +21,12 @@ function generateMonster(){ } function initDungeon() { - $_SESSION["dungeon"] = true; + $_SESSION["dungeon"]["access"] = true; } function sendDungeon() { if(!empty($_SESSION["dungeon"])) - return generateMonster(); + return $_SESSION["dungeon"]; else return false; } @@ -43,14 +43,22 @@ function buildDungeon() { } function launchDungeon(){ + $f= $_POST["floor"]; $dungeon=generateMonster(); - $opponent = $dungeon["monsters"]["floor1"]; + $opponent = $dungeon["monsters"]["floor".$f]; echo json_encode($opponent); } +function sendDungeonProgress(){ + $f= $_POST["floor"]; + $nb=$_POST["mob"]; + $_SESSION["dungeon"]["flat"] = $f; + $_SESSION["dungeon"]["mob"] = $nb; +} + + function exitDungeon(){ $_SESSION["dungeon"] = false; - echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. } ?> diff --git a/inc/messages.inc b/inc/messages.inc index c51adba..1f25ed3 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -6,8 +6,7 @@ $messages = array( "shop_missing_item" => "This item does not exist.", "guild_not_yet_created" => "You need to create a guild first.", "guild_already_built" => "You have aready built a guild.", - "dungeon_already_available" => "You can already access the dungeon" - + "dungeon_already_available" => "You can already access the dungeon", "gamesave_ok" => "Game saved.", "gamesave_error" => "An error occured when trying to save the game.", "gamesave_not_found" => "Couldn't find the specified save file.", diff --git a/js/craftmine.js b/js/craftmine.js index ffc9b5e..9af9b9f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -3,8 +3,8 @@ data = { gold: 0, mine: 0, miners: 0, - level: 1, - hp: 1, + level: 4, + hp: 5, icon : "H" } @@ -56,7 +56,8 @@ function initCraftMine() { data.mine = 0; // Reset mine if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(ret.dungeon) displayDungeon(); + if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) 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 = "
    "; - tmphtml += ""; + tmphtml += ""; 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 = "
    "; - tmphtml += "

    Battle

    "; + tmphtml += "

    Battle floor "+ f +"

    "; tmphtml += "
      "; tmphtml += "
    • "; - tmphtml += ""; - tmphtml += ""; + tmphtml += ""; + tmphtml += ""; tmphtml += "
    • "; tmphtml += "
    "; tmphtml += "
    "; - tmphtml += "

    "; - tmphtml += ""; 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 += "" + document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); +} + +function displayExit(){ + var tmphtml = "

    "; + tmphtml += ""; + document.getElementById("tab4").innerHTML += tmphtml; } function exitDungeon(){ sendRequest("craftmine.php", "op=exitDungeon", function() { + window.clearTimeout(timeout); document.getElementById("tab4").innerHTML = "

    Look at how poor you are! You can't access the dungeon, it is only for the elite.

    "; showInfo("You have left the dungeon"); }); -- cgit v1.2.3-54-g00ecf From f171811a44364f605712aff1ca0808bfe570ef6e Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 23:06:29 +0200 Subject: add xp system and perso server side --- craftmine.php | 3 +++ data/monsters.xml | 9 +++++++++ inc/Monster.inc | 4 +++- inc/craftmine.inc | 2 ++ inc/dungeon.inc | 5 +++-- inc/perso.inc | 17 +++++++++++++++++ index.xhtml | 4 ++++ js/craftmine.js | 13 +++++++++++-- js/dungeon.js | 38 ++++++++++++++++++++++++++------------ js/perso.js | 5 +++++ 10 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 inc/perso.inc create mode 100644 js/perso.js (limited to 'js') diff --git a/craftmine.php b/craftmine.php index 43fdc66..d47989c 100644 --- a/craftmine.php +++ b/craftmine.php @@ -6,6 +6,7 @@ require_once("inc/shop.inc"); require_once("inc/craftmine.inc"); require_once("inc/dungeon.inc"); require_once("inc/savegame.inc"); +require_once("inc/perso.inc"); session_start(); // Must be placed *BEFORE* $_SESSION is actually used and *AFTER* all classes are imported @@ -52,6 +53,8 @@ switch($op) { case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; case "sendDungeonProgress" : sendDungeonProgress(); break; + case "updatePerso" : updatePerso(); break; + case "sendPerso" : sendPerso(); break; case "saveGame": saveGame(); break; case "downSave": downSave(); break; case "listSaves": listSaves(); break; diff --git a/data/monsters.xml b/data/monsters.xml index 630e83a..ab29364 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -5,18 +5,21 @@ monster1 1 3 + 1 m
    monster2 2 3 + 2 m monster3 3 4 + 3 m @@ -25,18 +28,21 @@ monster4 4 5 + 4 m monster5 5 6 + 5 m monster5 6 7 + 6 m @@ -45,18 +51,21 @@ monster6 8 9 + 8 m monster7 9 10 + 9 m Boss 10 12 + 10 m diff --git a/inc/Monster.inc b/inc/Monster.inc index fbb0fe9..c7063ec 100644 --- a/inc/Monster.inc +++ b/inc/Monster.inc @@ -5,12 +5,14 @@ class Monster { public $icon = ""; public $desc = ""; public $hp = 1; + public $xp = 0; public $level = 1; - function __construct($name, $level, $hp, $icon) { + function __construct($name, $level, $hp, $xp, $icon) { $this->name = $name; $this->level = $level; $this->hp = $hp; + $this->xp = $xp; $this->icon = $icon; } diff --git a/inc/craftmine.inc b/inc/craftmine.inc index 0d6a445..f5dbbb1 100644 --- a/inc/craftmine.inc +++ b/inc/craftmine.inc @@ -3,6 +3,7 @@ require_once("mine.inc"); require_once("shop.inc"); require_once("dungeon.inc"); +require_once("perso.inc"); function sendCraftMine() { $data = array("gold" => sendMine(), @@ -10,6 +11,7 @@ function sendCraftMine() { "inventory" => Inventory::sendContent(), "miners" => sendMiners(), "dungeon" => sendDungeon(), + "perso" => sendPerso(), ); echo json_encode($data); } diff --git a/inc/dungeon.inc b/inc/dungeon.inc index ebe74b7..c023cf8 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -12,8 +12,9 @@ function generateMonster(){ $dungeon["monsters"][$floor] = array(); foreach($f as $monster){ $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, - intval($monster->level), - intval($monster->hp), + intval($monster->level), + intval($monster->hp), + intval($monster->xp), (string)$monster->icon); } } diff --git a/inc/perso.inc b/inc/perso.inc new file mode 100644 index 0000000..075f8ae --- /dev/null +++ b/inc/perso.inc @@ -0,0 +1,17 @@ + diff --git a/index.xhtml b/index.xhtml index ed3e7a6..7921cab 100644 --- a/index.xhtml +++ b/index.xhtml @@ -17,12 +17,16 @@ +

    CraftMine

    +
    + HP : 5/ LV : 1/ exp : 0 +
    diff --git a/js/craftmine.js b/js/craftmine.js index 9af9b9f..c7a396f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,6 +5,7 @@ data = { miners: 0, level: 4, hp: 5, + xp: 0, icon : "H" } @@ -52,12 +53,20 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { + console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine + if(ret.perso){ + data.hp = ret.perso.hp; + data.xp = ret.perso.xp; + data.level = ret.perso.lv; + displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv); + } if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); - else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); + if(ret.dungeon == false){}//if we have left the donjon + else if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); //if we have reload just after buying the ticket + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);//if we have reload in the middle of the dungeon data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) diff --git a/js/dungeon.js b/js/dungeon.js index c6ce014..65d1081 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -50,11 +50,12 @@ function strike(ret,nb, f){ var mobLife = document.getElementById("lifeMob").innerHTML; var persoLife = document.getElementById("lifePerso").innerHTML; if(mobLife == 0){ - endBattle("perso",nb,f); + data.hp = persoLife; + endBattle("perso",nb,f,ret); return; } else if(persoLife == 0){ - endBattle("mob",nb); + endBattle("mob",nb,f,ret); return; } if(hitRate<50+10*lvDiff){ @@ -68,19 +69,32 @@ function strike(ret,nb, f){ battle(ret,nb,f); } -function endBattle(v,nb, f){ +function endBattle(v,nb, f, ret){ 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 + //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 += 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); + }); + } + 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 += "" + document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } - var tmphtml = "Le " + v + " a gagné."; - tmphtml += "" - document.getElementById("tab4").innerHTML = tmphtml; - displayExit(); - sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } function displayExit(){ diff --git a/js/perso.js b/js/perso.js new file mode 100644 index 0000000..365cf54 --- /dev/null +++ b/js/perso.js @@ -0,0 +1,5 @@ +function displayPerso(hp,xp,lv){ + document.getElementById("hp").innerHTML = hp; + document.getElementById("lv").innerHTML = lv; + document.getElementById("xp").innerHTML = xp; +} -- cgit v1.2.3-54-g00ecf From ee02581b7fabd087fc4056bda739c88656fbca14 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 7 May 2016 10:13:20 +0200 Subject: add the display of the perso characteristics below the title --- inc/perso.inc | 12 +++++++++--- js/craftmine.js | 2 +- js/dungeon.js | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) (limited to 'js') diff --git a/inc/perso.inc b/inc/perso.inc index 075f8ae..4fb05ef 100644 --- a/inc/perso.inc +++ b/inc/perso.inc @@ -1,8 +1,8 @@ diff --git a/js/craftmine.js b/js/craftmine.js index c7a396f..a8619df 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -3,7 +3,7 @@ data = { gold: 0, mine: 0, miners: 0, - level: 4, + level: 3, hp: 5, xp: 0, icon : "H" diff --git a/js/dungeon.js b/js/dungeon.js index 65d1081..30808ff 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -71,11 +71,11 @@ function strike(ret,nb, f){ function endBattle(v,nb, f, ret){ window.clearTimeout(timeout); - if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon + if(v=="mob")exitDungeon(false);//if you die in the dungeon, you are immediately sent out of the dungeon //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 += ret[nb].xp; + data.xp += parseInt(ret[nb].xp); if(data.xp>=data.level){ data.xp-=data.level; data.level++; @@ -88,6 +88,10 @@ function endBattle(v,nb, f, ret){ if(nb>=3){//floor changing nb=0;//reset the number of the mob f++;//increment the number of the floor + if(f>=4){ + exitDungeon(true);//true means that you have completed the dungeon and not just die or exit by yourself + return; + } } var tmphtml = "Le " + v + " a gagné."; tmphtml += "" @@ -95,18 +99,22 @@ 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,data.xp,data.level); + }); } function displayExit(){ var tmphtml = "

    "; - tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML += tmphtml; } -function exitDungeon(){ +function exitDungeon(boss){ sendRequest("craftmine.php", "op=exitDungeon", function() { window.clearTimeout(timeout); - document.getElementById("tab4").innerHTML = "

    Look at how poor you are! You can't access the dungeon, it is only for the elite.

    "; + 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!"); showInfo("You have left the dungeon"); }); } -- cgit v1.2.3-54-g00ecf From 79cfbb29042fd60dfbc76a6810f75cce21d3ffe0 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 7 May 2016 12:08:36 +0200 Subject: add the use of the life bottle --- craftmine.php | 1 + inc/Inventory.inc | 17 +++++++++++++++++ inc/perso.inc | 2 +- inc/shop.inc | 6 ++++++ js/craftmine.js | 2 +- js/dungeon.js | 3 ++- js/shop.js | 18 +++++++++++++++++- 7 files changed, 45 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/craftmine.php b/craftmine.php index d47989c..9a8806b 100644 --- a/craftmine.php +++ b/craftmine.php @@ -49,6 +49,7 @@ switch($op) { case "getCraftMine": sendCraftMine(); break; case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; + case "useItem": useItem(); break; case "buildDungeon" : buildDungeon(); break; case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 024a4fe..747c4db 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -46,6 +46,23 @@ class Inventory { $inv->_removeItem($item); } + private function _useItem($item) { + foreach($this->items as $k => $object){ + if($object[0] == $item){ + if($this->items[$k][1]>0)$this->items[$k][1]--; + //if($this->items[$k][1] == 0) _removeItem($item); + return $this->items[$k]; + } + } + return false; + } + + public static function useItem($item) { + $inv = self::get(); + $it = $inv->_useItem($item); + return $it; + } + public function addToXML($root) { foreach($this->items as $item) $item->addToXML($root); diff --git a/inc/perso.inc b/inc/perso.inc index 4fb05ef..0362d8c 100644 --- a/inc/perso.inc +++ b/inc/perso.inc @@ -10,7 +10,7 @@ function updatePerso(){ $xp = $_POST["xp"]; $lv = $_POST["lv"]; $_SESSION["perso"]["hp"] = $hp; - $_SESSION["perso"]["xp"] = $xp; + $_SESSION["perso"]["xp"] = intval($xp); $_SESSION["perso"]["lv"] = $lv; } diff --git a/inc/shop.inc b/inc/shop.inc index 49ee20b..32ecea2 100644 --- a/inc/shop.inc +++ b/inc/shop.inc @@ -60,5 +60,11 @@ function buyItem() { } } +function useItem(){ + $item = getItem($_POST["item"]); + $it = Inventory::useItem($item); + echo json_encode($it); +} + ?> diff --git a/js/craftmine.js b/js/craftmine.js index a8619df..70becec 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -63,7 +63,7 @@ function initCraftMine() { displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv); } if(ret.shop) displayShop(ret.shop); - displayInventory(ret.inventory); + if(ret.inventory) displayInventory(ret.inventory); if(ret.dungeon == false){}//if we have left the donjon else if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); //if we have reload just after buying the ticket else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);//if we have reload in the middle of the dungeon diff --git a/js/dungeon.js b/js/dungeon.js index 30808ff..982dcf6 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -55,6 +55,7 @@ function strike(ret,nb, f){ return; } else if(persoLife == 0){ + data.hp = 1; endBattle("mob",nb,f,ret); return; } @@ -100,7 +101,7 @@ function endBattle(v,nb, f, ret){ 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,data.xp,data.level); + displayPerso(data.hp,parseInt(data.xp),data.level); }); } diff --git a/js/shop.js b/js/shop.js index bda3885..efb347a 100644 --- a/js/shop.js +++ b/js/shop.js @@ -37,7 +37,7 @@ function addItem(ret) { var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]"); if(!itemtag){ //si c'est la première itération de l'objet itemhtml += "
  • "; - itemhtml += ""; + itemhtml += ""; itemhtml += "
  • "; } else{ // si c'est une n-ième itération @@ -68,6 +68,22 @@ function buyItem(name) { function useItem(name) { sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) { + if(parseInt(ret[1])>=0){ + var nb = parseInt(document.getElementById("nbItem").innerHTML); + if(nb>0){ + nb--; + switch(ret[0].name){ + case "Life Bottle": data.hp = parseInt(data.hp) + 3; break; + case "Strength Bottle" : break; // to do + case "Wooden Sword" : break; //to do + case "Metal Sword" : break; //to do + } + } + document.getElementById("nbItem").innerHTML = nb; + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ + displayPerso(data.hp,data.xp,data.level); + }); + } }); } -- cgit v1.2.3-54-g00ecf From acfc0e766e266e60302a1cf1f4b18da759eb0243 Mon Sep 17 00:00:00 2001 From: piernov Date: Sat, 7 May 2016 13:30:20 +0200 Subject: Change save buttons layout --- js/savegame.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/savegame.js b/js/savegame.js index d5a9ba1..c069b5c 100644 --- a/js/savegame.js +++ b/js/savegame.js @@ -2,7 +2,13 @@ function listSaves() { sendRequest("craftmine.php", "op=listSaves", function(ret) { var tmphtml="" for(var i=0; i" + ret[i] + "\n"; + tmphtml += "
    "; + tmphtml += ""; + tmphtml += ""; + tmphtml += ""; + tmphtml += ""; + + tmphtml += "
    " } console.log(tmphtml); document.getElementById("listsaves").innerHTML = tmphtml; -- cgit v1.2.3-54-g00ecf From 25556ed4765a897996fba7fb4b0776f043d47cb9 Mon Sep 17 00:00:00 2001 From: piernov Date: Sat, 7 May 2016 13:31:15 +0200 Subject: btn-primary → btn-success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/dungeon.js | 8 ++++---- js/shop.js | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'js') diff --git a/js/dungeon.js b/js/dungeon.js index d20a3cf..4fb226d 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -8,7 +8,7 @@ function buildDungeon(){ function displayDungeon(){ var tmphtml = "
    "; - tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } @@ -24,13 +24,13 @@ function displayBattle(ret){ tmphtml += "

    Battle

    "; tmphtml += "
      "; tmphtml += "
    • "; - tmphtml += ""; - tmphtml += ""; + tmphtml += ""; + tmphtml += ""; tmphtml += "
    • "; tmphtml += "
    "; tmphtml += "
    "; tmphtml += "

    "; - tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } diff --git a/js/shop.js b/js/shop.js index bda3885..a2f14ad 100644 --- a/js/shop.js +++ b/js/shop.js @@ -3,16 +3,14 @@ function displayShop(ret) { for(var key in ret.items){ if(ret.items.hasOwnProperty(key)){ var category = ret.items[key]; - tmphtml += "
    "; tmphtml += "

    "+key+"

    "; tmphtml += "
      "; for(var i=0; i < category.length; i++) { tmphtml += "
    • "; - tmphtml += ""; + tmphtml += ""; tmphtml += "
    • "; } tmphtml += "
    "; - tmphtml += "
    "; } } document.getElementById("tab2").innerHTML = tmphtml; @@ -37,7 +35,7 @@ function addItem(ret) { var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]"); if(!itemtag){ //si c'est la première itération de l'objet itemhtml += "
  • "; - itemhtml += ""; + itemhtml += ""; itemhtml += "
  • "; } else{ // si c'est une n-ième itération @@ -48,7 +46,7 @@ function addItem(ret) { if(invcontent.children.length <= 1) { - var tmphtml = "

    Your bag contains the following items:

    "; + var tmphtml = "

    Your bag contains the following items:

    "; tmphtml += "
      "; tmphtml += itemhtml; tmphtml += "
    " -- cgit v1.2.3-54-g00ecf From 8621eae6aa5fcdba0a60f0a5f1136412c61999ec Mon Sep 17 00:00:00 2001 From: piernov Date: Sat, 7 May 2016 13:31:49 +0200 Subject: UI improvements --- css/craftmine.css | 54 +++++++++++++++++++++++++++-- index.xhtml | 100 +++++++++++++++++++++++++++++------------------------- js/gui.js | 4 +-- 3 files changed, 107 insertions(+), 51 deletions(-) (limited to 'js') diff --git a/css/craftmine.css b/css/craftmine.css index c459baa..fa42bd9 100644 --- a/css/craftmine.css +++ b/css/craftmine.css @@ -15,7 +15,57 @@ } .item-icon { display:inline-block; - width: 1em; - font-size: 3em; + font-size: 4em; font-family: "Symbola"; } +.list-group-item > .label { + float:right; +} +#tab2 > ul > li > button { + width: 9em; + height: 9em; +} +.label { + font-size: 1.2em; +} +.list-group > button { + border-radius: 0; +} +a { + color: #5cb85c; +} +/* color: hotpink; +} +.label-success { + background-color: hotpink; +} + +.btn-success { + background-color: hotpink; + border-color: deeppink; +} +.btn-success:hover { + background-color: pink; + border-color: hotpink; +} +.btn-success.active.focus, .btn-success.active:focus, +.btn-success.active:hover, .btn-success.focus:active, +.btn-success:active:focus, .btn-success:active:hover, +.btn-success.focus, .btn-success:focus { + background-color: deeppink; + border-color: magenta; +} +.panel-success { + border-color: lightpink; +} +.panel-success > .panel-heading { + background-color: pink; + color: deeppink; + border-color: lightpink; +} +.alert-success { + color: deeppink; + border-color: lightpink; + background-color: pink; +} +*/ diff --git a/index.xhtml b/index.xhtml index 0760aeb..dcfdc69 100644 --- a/index.xhtml +++ b/index.xhtml @@ -18,44 +18,46 @@
    -

    CraftMine

    -
    -
    -
    + +
    -
    - 0 - 0 -

    Miners : 0

    - -
      -
    • -
    • -
    +
    +
    +
    +

    Stats

    +
    +
    +
      +
    • Mine14
    • +
    • Gold14
    • +
    • Miners14
    • +
    + +
    + + +
    +
    +
    -