aboutsummaryrefslogtreecommitdiffstats
path: root/inc/dungeon.inc
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-05-01 11:32:08 +0200
committeralexichi <alexbankai96@gmail.com>2016-05-01 11:32:08 +0200
commit31866085151518f468794dc71b541543e6b2f691 (patch)
treed73fe26a86db53707dd9c36f73b08ae3875c93e4 /inc/dungeon.inc
parent48ca3e8ee63787d567fd0fe1bcfea7158a6f9596 (diff)
downloadcandybox-31866085151518f468794dc71b541543e6b2f691.tar.gz
candybox-31866085151518f468794dc71b541543e6b2f691.tar.bz2
candybox-31866085151518f468794dc71b541543e6b2f691.tar.xz
candybox-31866085151518f468794dc71b541543e6b2f691.zip
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
Diffstat (limited to 'inc/dungeon.inc')
-rw-r--r--inc/dungeon.inc39
1 files changed, 39 insertions, 0 deletions
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 @@
+<?php
+require_once("messages.inc");
+require_once("account.inc");
+require_once("Monster.inc");
+
+
+function generateMonster(){
+ $monsters = simplexml_load_file('data/monsters.xml');
+ $dungeon = array("cost"=>(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);
+ }
+}
+
+?>