aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/guild.inc9
-rw-r--r--inc/messages.inc1
-rw-r--r--inc/mine.inc14
-rw-r--r--index.xhtml6
4 files changed, 24 insertions, 6 deletions
diff --git a/inc/guild.inc b/inc/guild.inc
index c0e8264..1666b15 100644
--- a/inc/guild.inc
+++ b/inc/guild.inc
@@ -3,6 +3,13 @@
define("GUILD_COST",10);
define("MINER_COST",5);
+function initMinersIfNeeded() {
+ if(empty($_SESSION["mine"]))
+ $_SESSION["mine"] = array("miners" => 0);
+ else if(!array_key_exists("miners", $_SESSION["mine"]))
+ $_SESSION["mine"]["miners"] = 0;
+}
+
function createGuild(){
if(!empty($_SESSION["guild"])) {
sendError("guild_already_built");
@@ -18,12 +25,14 @@ function hireMiner(){
sendError("guild_not_yet_created");
}
elseif(debitAccount(MINER_COST)){
+ initMinersIfNeeded();
$_SESSION["mine"]["miners"]++;
echo json_encode(array("cost" => MINER_COST , "miners" => $_SESSION["mine"]["miners"]));
}
}
function sendMiners(){
+ initMinersIfNeeded();
return $_SESSION["mine"]["miners"];
}
diff --git a/inc/messages.inc b/inc/messages.inc
index 3a7d9b1..97e1da2 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -6,6 +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.",
+ "cant_withdraw_in_dungeon" => "You cannot withdraw gold from the mine while you are in the dungeon.",
"dungeon_already_available" => "You can already access the dungeon",
"gamesave_ok" => "Game saved.",
diff --git a/inc/mine.inc b/inc/mine.inc
index 752fc69..76dfb50 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -1,18 +1,26 @@
<?php
-function initCraftMine() {
- $_SESSION["mine"] = array("gold" => 0, "miners" => 0);
+function initMineIfNeeded() {
+ if(empty($_SESSION["mine"]))
+ $_SESSION["mine"] = array("gold" => 0);
+ else if(!array_key_exists("gold", $_SESSION["mine"]))
+ $_SESSION["mine"]["gold"] = 0;
}
function withdrawMine() {
$amount = intval($_POST["amount"]);
+ if(!empty($_SESSION["dungeon"])) {
+ sendError("cant_withdraw_in_dungeon");
+ return;
+ }
if($amount == 0) return;
+ initMineIfNeeded();
$_SESSION["mine"]["gold"] += $amount;
echo json_encode($_SESSION["mine"]["gold"]);
}
function sendMine() {
- if(empty($_SESSION["mine"])) initCraftMine();
+ initMineIfNeeded();
$mine = $_SESSION["mine"];
return $mine["gold"];
}
diff --git a/index.xhtml b/index.xhtml
index eba0f43..8ee8c52 100644
--- a/index.xhtml
+++ b/index.xhtml
@@ -44,9 +44,9 @@
</ul>
<ul class="list-group">
- <li class="list-group-item">Mine<span id="mine" class="label label-success">14</span></li>
- <li class="list-group-item">Gold<span id="gold" class="label label-success">14</span></li>
- <li class="list-group-item">Miners<span id="miners" class="label label-success">14</span></li>
+ <li class="list-group-item">Mine<span id="mine" class="label label-success">0</span></li>
+ <li class="list-group-item">Gold<span id="gold" class="label label-success">0</span></li>
+ <li class="list-group-item">Miners<span id="miners" class="label label-success">0</span></li>
</ul>
<div class="list-group">