aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/Monster.inc19
-rw-r--r--inc/dungeon.inc39
-rw-r--r--inc/messages.inc3
3 files changed, 60 insertions, 1 deletions
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 @@
+<?php
+
+class Monster {
+ public $name = "";
+ public $icon = "";
+ public $desc = "";
+ public $hp = 1;
+ public $level = 1;
+
+ function __construct($name, $level, $hp, $icon) {
+ $this->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 @@
+<?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);
+ }
+}
+
+?>
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) {