diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | craftmine.php | 3 | ||||
-rw-r--r-- | inc/guild.inc | 30 | ||||
-rw-r--r-- | inc/mine.inc | 2 | ||||
-rw-r--r-- | inc/mine.inc~ | 20 | ||||
-rw-r--r-- | index.xhtml | 6 | ||||
-rw-r--r-- | js/craftmine.js | 2 | ||||
-rw-r--r-- | js/craftmine.js~ | 51 | ||||
-rw-r--r-- | js/guild.js | 26 |
9 files changed, 67 insertions, 74 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/craftmine.php b/craftmine.php index 4d08ffd..78c5e37 100644 --- a/craftmine.php +++ b/craftmine.php @@ -1,6 +1,7 @@ <?php require_once("inc/mine.inc"); +require_once("inc/guild.inc"); require_once("inc/shop.inc"); require_once("inc/craftmine.inc"); @@ -36,6 +37,8 @@ if (!isset($_POST["op"])) { $op = $_POST["op"]; switch($op) { case "withdrawMine": withdrawMine(); break; + case "createGuild": createGuild(); break; + case "hireMiner": hireMiner(); break; case "getCraftMine": sendCraftMine(); break; case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; diff --git a/inc/guild.inc b/inc/guild.inc new file mode 100644 index 0000000..4ca0262 --- /dev/null +++ b/inc/guild.inc @@ -0,0 +1,30 @@ +<?php + +function createGuild(){ + if($_SESSION["mine"]["gold"] >= 50 && !isset($_SESSION["guild"])){ + $_SESSION["guild"]= array("miners" => 1); + $_SESSION["mine"]["gold"] -= 50; + echo "Guild has been successfully created"; + } + else{ + echo "g"; + } +} + +function hireMiner(){ + if(!isset($_SESSION["guild"])){ + echo "you need to create a guild first"; + } + if($_SESSION["mine"]["gold"] >= 20 && isset($_SESSION["guild"])){ + $_SESSION["guild"]["miners"]++; + $_SESSION["mine"]["gold"] -= 20; + $_SESSION["mine"]["miners"] = $_SESSION["guild"]["miners"]; + $mine = $_SESSION["mine"]; + echo $mine["gold"] +","+ $mine["miners"]; + } +} + +//function buy($obj,$prix){} + + +?> diff --git a/inc/mine.inc b/inc/mine.inc index 6a04cc4..94a2c66 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/inc/mine.inc~ b/inc/mine.inc~ deleted file mode 100644 index a01d768..0000000 --- a/inc/mine.inc~ +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -function initCraftMine() { - $_SESSION["mine"] = array("mine" => 0, "or" => 0, "miners" => 1); -} - -function withdrawMine() { - $mine = $_SESSION["mine"]; - $_SESSION["mine"]["gold"] += $mine["mine"]; - $_SESSION["mine"]["mine"] = 0; -} - -function sendMine() { - if(empty($_SESSION["mine"])) initMine(); - $mine = $_SESSION["mine"]; - echo $mine["gold"]; -} - - -?> diff --git a/index.xhtml b/index.xhtml index 6ec45ef..1685eb9 100644 --- a/index.xhtml +++ b/index.xhtml @@ -12,6 +12,7 @@ <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> <script type="text/javascript" charset="utf-8" src="js/shop.js"></script> <script type="text/javascript" charset="utf-8" src="js/gui.js"></script> </head> @@ -26,8 +27,11 @@ <div class="col-md-10"> <span id="gold">0</span> <span id="mine">0</span> + <p>Miners : <span id="miners">0</span></p> + <span id="guild"></span> <form class="form-horizontal" method="post" action="craftmine.php"> <button class="btn btn-default" type="button" name="withdraw" onclick="withdrawMine()">Withdraw</button> + <button type="button" name="HireMiner" onclick="hireMiner()">Hire one miner</button> </form> </div> </div> @@ -63,7 +67,7 @@ <div class="tab-pane" id="tab1"> <h4>Select a building to build:</h4> <ul class="list-inline"> - <li><button class="btn btn-default" type="button" onclick="">Miner's guild</button></li> + <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> </ul> </div> diff --git a/js/craftmine.js b/js/craftmine.js index 66c35fc..000a8f2 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/craftmine.js~ b/js/craftmine.js~ deleted file mode 100644 index bc03d6c..0000000 --- a/js/craftmine.js~ +++ /dev/null @@ -1,51 +0,0 @@ -datas = { - gold: 0, - mine: 0, - miners: 1, - level: 1 -} - -function sendRequest(url, params, callback) { - var xhr = new XMLHttpRequest(); - xhr.open("POST", url); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhr.onreadystatechange = function() { - if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { - callback(xhr); - } - } - xhr.send(params); -} - - -function updateDatas(t) { - document.getElementById(t).innerHTML = datas[t]; -} - -function withdrawMine() { - sendRequest("craftmine.php", "op=withdrawMine", function() { - datas.gold += parseInt(datas.mine); - datas.mine = 0; - updateDatas("gold"); - updateDatas("mine"); - }) -} - -function initCraftMine() { - sendRequest("craftmine.php", "op=getCraftMine", function(xhr) { - var ret = xhr.responseText; - datas.gold = ret; - updateDatas("gold"); - }) -} - - -function updateMine() { - datas.mine += (datas.mineurs+1); - updateDatas("mine"); -} - -function init() { - initCraftMine(); - window.setInterval(updateMine, 1000); -} diff --git a/js/guild.js b/js/guild.js new file mode 100644 index 0000000..cb9e783 --- /dev/null +++ b/js/guild.js @@ -0,0 +1,26 @@ +function hireMiner(){ + sendRequest("craftmine.php", "op=hireMiner", function(xhr) { + //data.gold -= 40; + var ret = xhr.responseText; + if(ret != "you need to create a guild first" && ret!=""){ + console.log(ret); + var tmp = ret.split(","); + console.log(tmp); + data.gold = parseInt(tmp[0]); + data.miners = parseInt(tmp[1]); + updateData("gold","miners"); + } + }) +} + +function createGuild(){ + sendRequest("craftmine.php", "op=createGuild", function(xhr) { + var ret = xhr.responseText; + if(ret != "g"){ + document.getElementById("guild").innerHTML = ret; + data.gold -= 50; + updateData("gold"); + } + }) +} + |