aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--craftmine.php3
-rw-r--r--data/monsters.xml63
-rw-r--r--inc/Monster.inc19
-rw-r--r--inc/dungeon.inc39
-rw-r--r--inc/messages.inc3
-rw-r--r--index.xhtml3
-rw-r--r--js/dungeon.js18
7 files changed, 146 insertions, 2 deletions
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dungeon cost="10">
+ <floor name="floor1">
+ <monster>
+ <name>monster1</name>
+ <level>1</level>
+ <hp>2</hp>
+ <icon>m</icon>
+ </monster>
+ <monster >
+ <name>monster2</name>
+ <level>2</level>
+ <hp>3</hp>
+ <icon>m</icon>
+ </monster>
+ <monster>
+ <name>monster3</name>
+ <level>3</level>
+ <hp>4</hp>
+ <icon>m</icon>
+ </monster>
+ </floor>
+ <floor name="floor2">
+ <monster>
+ <name>monster4</name>
+ <level>4</level>
+ <hp>5</hp>
+ <icon>m</icon>
+ </monster>
+ <monster>
+ <name>monster5</name>
+ <level>5</level>
+ <hp>6</hp>
+ <icon>m</icon>
+ </monster>
+ <monster>
+ <name>monster5</name>
+ <level>6</level>
+ <hp>7</hp>
+ <icon>m</icon>
+ </monster>
+ </floor>
+ <floor name="floor3">
+ <monster>
+ <name>monster6</name>
+ <level>8</level>
+ <hp>9</hp>
+ <icon>m</icon>
+ </monster>
+ <monster>
+ <name>monster7</name>
+ <level>9</level>
+ <hp>10</hp>
+ <icon>m</icon>
+ </monster>
+ <monster>
+ <name>Boss</name>
+ <level>10</level>
+ <hp>12</hp>
+ <icon>m</icon>
+ </monster>
+ </floor>
+</dungeon>
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) {
diff --git a/index.xhtml b/index.xhtml
index aa29615..2745c8a 100644
--- a/index.xhtml
+++ b/index.xhtml
@@ -15,6 +15,8 @@
<script type="text/javascript" charset="utf-8" src="js/guild.js"></script>
<script type="text/javascript" charset="utf-8" src="js/shop.js"></script>
<script type="text/javascript" charset="utf-8" src="js/gui.js"></script>
+ <script type="text/javascript" charset="utf-8" src="js/dungeon.js"></script>
+
</head>
<body onload="init()" onhashchange="changeTab()">
<div class="container-fluid">
@@ -69,6 +71,7 @@
<ul class="list-inline">
<li><button class="btn btn-default" type="button" onclick="createGuild()">Miner's guild</button></li>
<li><button class="btn btn-default" type="button" onclick="buildShop()">Shop</button></li>
+ <li><button class="btn btn-default" type="button" onclick="buildDungeon()">Dungeon</button></li>
</ul>
</div>
<div class="tab-pane" id="tab2">
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 = "<br/>";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon()\">Launch</button>";
+ //tmphtml += "</li>";
+ document.getElementById("tab4").innerHTML = tmphtml;
+}
+
+function launchDungeon(){
+ console.log("Battle!");
+}