From 725c3529c3c2f63998578cfbcb070bdfa3a9ce19 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 23 Apr 2016 20:40:52 +0200 Subject: add file for the guild ,client side (not finish) --- js/guild.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 js/guild.js (limited to 'js/guild.js') 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); + }) +} + -- cgit v1.2.3-54-g00ecf From 8984aa2ecca7feacec93db35aee1570e40fa5123 Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 25 Apr 2016 10:18:41 +0200 Subject: Add the guild add buttons to hireMiner and purchase the guild on xhtml javascript send request to the server php -> update $_SESSION for miner --- inc/guild.inc | 19 ++++++++++--------- index.xhtml | 26 +++++++++++++++++++++++--- js/guild.js | 24 ++++++++++++++++-------- 3 files changed, 49 insertions(+), 20 deletions(-) (limited to 'js/guild.js') 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 @@ = 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 "

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 @@

- - -
+ + + + + + +
+

Items Shop

+
wooden sword + +
+
golden sword + +
+
life bottle + +
+
strength bottle + +
+
+ + 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"); + } }) } -- cgit v1.2.3-54-g00ecf From 29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8 Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 25 Apr 2016 13:37:08 +0200 Subject: Mise en commun du shop et de la guilde --- inc/account.inc | 2 +- inc/craftmine.inc | 1 + inc/guild.inc | 29 +++++++++++++++-------------- inc/messages.inc | 2 ++ js/craftmine.js | 3 ++- js/guild.js | 27 +++++++++------------------ 6 files changed, 30 insertions(+), 34 deletions(-) (limited to 'js/guild.js') diff --git a/inc/account.inc b/inc/account.inc index 19f311d..6f398bb 100644 --- a/inc/account.inc +++ b/inc/account.inc @@ -2,7 +2,7 @@ require_once("messages.inc"); function debitAccount($amount) { - if($_SESSION["mine"]["gold"] <= $amount) { + if($_SESSION["mine"]["gold"] < $amount) { sendError("gold_insufficient"); return false; } diff --git a/inc/craftmine.inc b/inc/craftmine.inc index a30538c..33a28d7 100644 --- a/inc/craftmine.inc +++ b/inc/craftmine.inc @@ -7,6 +7,7 @@ function sendCraftMine() { $data = array("gold" => sendMine(), "shop" => sendShop(), "inventory" => Inventory::sendContent(), + "miners" => sendMiners() ); echo json_encode($data); } diff --git a/inc/guild.inc b/inc/guild.inc index 4ca0262..c0e8264 100644 --- a/inc/guild.inc +++ b/inc/guild.inc @@ -1,30 +1,31 @@ = 50 && !isset($_SESSION["guild"])){ - $_SESSION["guild"]= array("miners" => 1); - $_SESSION["mine"]["gold"] -= 50; - echo "Guild has been successfully created"; + if(!empty($_SESSION["guild"])) { + sendError("guild_already_built"); } - else{ - echo "g"; + elseif(debitAccount(GUILD_COST)) { + $_SESSION["guild"] = true; + echo json_encode(array("cost" => GUILD_COST)); } } function hireMiner(){ if(!isset($_SESSION["guild"])){ - echo "you need to create a guild first"; + sendError("guild_not_yet_created"); } - 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"]; + elseif(debitAccount(MINER_COST)){ + $_SESSION["mine"]["miners"]++; + echo json_encode(array("cost" => MINER_COST , "miners" => $_SESSION["mine"]["miners"])); } } -//function buy($obj,$prix){} +function sendMiners(){ + return $_SESSION["mine"]["miners"]; +} ?> diff --git a/inc/messages.inc b/inc/messages.inc index f1ca8b3..d6ea87e 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -4,6 +4,8 @@ $messages = array( "shop_already_built" => "You have already built a shop.", "gold_insufficient" => "You don't have enough gold.", "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." ); function sendError($msg) { diff --git a/js/craftmine.js b/js/craftmine.js index 000a8f2..92fa45a 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -49,7 +49,8 @@ function initCraftMine() { data.gold = parseInt(ret.gold); // Server's response is a string if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - updateData("gold"); + data.miners = parseInt(ret.miners); + updateData("gold","miners"); }) } diff --git a/js/guild.js b/js/guild.js index cb9e783..8d4d91b 100644 --- a/js/guild.js +++ b/js/guild.js @@ -1,26 +1,17 @@ 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"); + sendRequest("craftmine.php", "op=hireMiner", function(ret) { + debitAccount(parseInt(ret.cost)); + data.miners = parseInt(ret.miners); + updateData("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"); + sendRequest("craftmine.php", "op=createGuild", function(ret) { + showInfo("Your guild has been successfully created"); + debitAccount(parseInt(ret.cost)); } - }) + ) } -- cgit v1.2.3-54-g00ecf