diff options
-rw-r--r-- | craftmine.php | 3 | ||||
-rw-r--r-- | inc/guild.inc | 29 | ||||
-rw-r--r-- | index.xhtml | 9 | ||||
-rw-r--r-- | js/guild.js | 18 |
4 files changed, 57 insertions, 2 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/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/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); + }) +} + |