aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-04-25 10:18:41 +0200
committeralexichi <alexbankai96@gmail.com>2016-04-25 10:18:41 +0200
commit8984aa2ecca7feacec93db35aee1570e40fa5123 (patch)
tree0b8595418d264cec9335c7e3f79143e9a91965fe
parentd013e0e873277dd1bf29f51a83bbd9e467cad23b (diff)
downloadcandybox-8984aa2ecca7feacec93db35aee1570e40fa5123.tar.gz
candybox-8984aa2ecca7feacec93db35aee1570e40fa5123.tar.bz2
candybox-8984aa2ecca7feacec93db35aee1570e40fa5123.tar.xz
candybox-8984aa2ecca7feacec93db35aee1570e40fa5123.zip
Add the guild
add buttons to hireMiner and purchase the guild on xhtml javascript send request to the server php -> update $_SESSION for miner
-rw-r--r--inc/guild.inc19
-rw-r--r--index.xhtml26
-rw-r--r--js/guild.js24
3 files changed, 49 insertions, 20 deletions
diff --git a/inc/guild.inc b/inc/guild.inc
index 5ede1f6..4ca0262 100644
--- a/inc/guild.inc
+++ b/inc/guild.inc
@@ -1,29 +1,30 @@
<?php
function createGuild(){
- if($_SESSION["mine"]["gold"] >= 150){
+ if($_SESSION["mine"]["gold"] >= 50 && !isset($_SESSION["guild"])){
$_SESSION["guild"]= array("miners" => 1);
- $_SESSION["mine"]["gold"] -= 150;
+ $_SESSION["mine"]["gold"] -= 50;
echo "Guild has been successfully created";
}
else{
- echo "Not enough money";
+ echo "g";
}
}
function hireMiner(){
if(!isset($_SESSION["guild"])){
- echo "<p>you need to create a guild first";
+ echo "you need to create a guild first";
}
- if($_SESSION["mine"]["gold"] >= 40){
+ if($_SESSION["mine"]["gold"] >= 20 && isset($_SESSION["guild"])){
$_SESSION["guild"]["miners"]++;
- $_SESSION["mine"]["gold"] -= 40;
+ $_SESSION["mine"]["gold"] -= 20;
$_SESSION["mine"]["miners"] = $_SESSION["guild"]["miners"];
$mine = $_SESSION["mine"];
- $guild = $_SESSION["guild"];
- echo $mine["gold"];
- echo $mine["miners"];
+ echo $mine["gold"] +","+ $mine["miners"];
}
}
+//function buy($obj,$prix){}
+
+
?>
diff --git a/index.xhtml b/index.xhtml
index 30352bf..495d6f4 100644
--- a/index.xhtml
+++ b/index.xhtml
@@ -21,8 +21,28 @@
<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>
+ <span id="guildCreated">
+ <button type="button" name="CreateGuild" onclick="createGuild()">Create your guild</button>
+ </span>
+ <span id="minerHired">
+ <button type="button" name="HireMiner" onclick="hireMiner()">Hire one miner</button>
+ </span>
+ <div>
+ <h3>Items Shop</h3>
+ <div>wooden sword
+ <button type="button" name="epeeCuivre" onclick="buyItems()">buy</button>
+ </div>
+ <div>golden sword
+ <button type="button" name="goldenSword" onclick="buyItems()">buy</button>
+ </div>
+ <div>life bottle
+ <button type="button" name="lifeBottle" onclick="buyItems()">buy</button>
+ </div>
+ <div>strength bottle
+ <button type="button" name="strengthBottle" onclick="buyItems()">buy</button>
+ </div>
+</div>
+</form>
+
</body>
</html>
diff --git a/js/guild.js b/js/guild.js
index 28f58b8..cb9e783 100644
--- a/js/guild.js
+++ b/js/guild.js
@@ -1,18 +1,26 @@
function hireMiner(){
- sendRequest("craftmine.php", "op=hireMiner", function() {
- //datas.gold -= parseInt(datas.mine);
+ sendRequest("craftmine.php", "op=hireMiner", function(xhr) {
+ //data.gold -= 40;
var ret = xhr.responseText;
- console.log(ret);
- //datas.gold = ret;
- //updateDatas("gold");
- //updateDatas("miners");
+ 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() {
+ sendRequest("craftmine.php", "op=createGuild", function(xhr) {
var ret = xhr.responseText;
- console.log(ret);
+ if(ret != "g"){
+ document.getElementById("guild").innerHTML = ret;
+ data.gold -= 50;
+ updateData("gold");
+ }
})
}