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 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