diff options
-rw-r--r-- | craftmine.php | 3 | ||||
-rw-r--r-- | inc/guild.inc | 29 | ||||
-rw-r--r-- | inc/mine.inc | 2 | ||||
-rw-r--r-- | index.xhtml | 9 | ||||
-rw-r--r-- | js/craftmine.js | 2 | ||||
-rw-r--r-- | js/guild.js | 18 |
6 files changed, 59 insertions, 4 deletions
diff --git a/craftmine.php b/craftmine.php index 5df926f..c6bebdb 100644 --- a/craftmine.php +++ b/craftmine.php @@ -2,6 +2,7 @@ session_start(); require_once("inc/mine.inc"); +require_once("inc/guild.inc"); /** * Indique au client une message requete. */ @@ -33,6 +34,8 @@ $op = $_POST["op"]; switch($op) { case "withdrawMine": withdrawMine(); break; case "getCraftMine": sendMine(); break; + case "createGuild": createGuild(); break; + case "hireMiner": hireMiner(); break; default: reportBadRequest(); } diff --git a/inc/guild.inc b/inc/guild.inc new file mode 100644 index 0000000..5ede1f6 --- /dev/null +++ b/inc/guild.inc @@ -0,0 +1,29 @@ +<?php + +function createGuild(){ + if($_SESSION["mine"]["gold"] >= 150){ + $_SESSION["guild"]= array("miners" => 1); + $_SESSION["mine"]["gold"] -= 150; + echo "Guild has been successfully created"; + } + else{ + echo "Not enough money"; + } +} + +function hireMiner(){ + if(!isset($_SESSION["guild"])){ + echo "<p>you need to create a guild first"; + } + if($_SESSION["mine"]["gold"] >= 40){ + $_SESSION["guild"]["miners"]++; + $_SESSION["mine"]["gold"] -= 40; + $_SESSION["mine"]["miners"] = $_SESSION["guild"]["miners"]; + $mine = $_SESSION["mine"]; + $guild = $_SESSION["guild"]; + echo $mine["gold"]; + echo $mine["miners"]; + } +} + +?> diff --git a/inc/mine.inc b/inc/mine.inc index aea04ad..a2ecd09 100644 --- a/inc/mine.inc +++ b/inc/mine.inc @@ -1,7 +1,7 @@ <?php function initCraftMine() { - $_SESSION["mine"] = array("mine" => 0, "gold" => 0, "miners" => 1); + $_SESSION["mine"] = array("mine" => 0, "gold" => 0, "miners" => 0); } function withdrawMine() { diff --git a/index.xhtml b/index.xhtml index 5b38b69..30352bf 100644 --- a/index.xhtml +++ b/index.xhtml @@ -11,13 +11,18 @@ <meta name="author" content="Alexandre Renoux,Pierre-Emmanuel Novac"/> <title>CraftMine</title> <script type="text/javascript" charset="utf-8" src="js/craftmine.js"></script> + <script type="text/javascript" charset="utf-8" src="js/guild.js"></script> </head> <body onload="init()"> <h1>CraftMine</h1> - <span id="gold">0</span> - <span id="mine">0</span> + <p>Gold : <span id="gold">0</span></p> + <p>Mine : <span id="mine">0</span></p> + <p>Miners : <span id="miners">0</span></p> + <span id="guild"></span> <form class="form-horizontal" method="post" action="craftmine.php"> <button type="button" name="withdraw" onclick="withdrawMine()">Withdraw</button> + <button type="button" name="createGuild" onclick="createGuild()">Create your guild</button> + <button type="button" name="hireMiner" onclick="hireMiner()">Hire one miner</button> </form> </body> </html> diff --git a/js/craftmine.js b/js/craftmine.js index bbb1074..9aaae5c 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,7 +1,7 @@ data = { gold: 0, mine: 0, - miners: 1, + miners: 0, level: 1 } diff --git a/js/guild.js b/js/guild.js new file mode 100644 index 0000000..28f58b8 --- /dev/null +++ b/js/guild.js @@ -0,0 +1,18 @@ +function hireMiner(){ + sendRequest("craftmine.php", "op=hireMiner", function() { + //datas.gold -= parseInt(datas.mine); + var ret = xhr.responseText; + console.log(ret); + //datas.gold = ret; + //updateDatas("gold"); + //updateDatas("miners"); + }) +} + +function createGuild(){ + sendRequest("craftmine.php", "op=createGuild", function() { + var ret = xhr.responseText; + console.log(ret); + }) +} + |