From d46a4d75594cebef5fc0c25104bde6242be0571e Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 23 Apr 2016 20:39:13 +0200 Subject: add file for server side --- inc/guild.inc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 inc/guild.inc (limited to 'inc') 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 @@ += 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 "

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"]; + } +} + +?> -- cgit v1.2.3-70-g09d2 From 743cbaa32e6b8564e069f98ff3ea69a0707bad19 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 24 Apr 2016 14:06:14 +0200 Subject: nothing special --- inc/mine.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/mine.inc b/inc/mine.inc index 76c0055..7a68237 100644 --- a/inc/mine.inc +++ b/inc/mine.inc @@ -1,7 +1,7 @@ 0, "gold" => 0, "miners" => 1); + $_SESSION["mine"] = array("mine" => 0, "gold" => 0, "miners" => 0); } function withdrawMine() { @@ -11,7 +11,7 @@ function withdrawMine() { } function sendMine() { - if(empty($_SESSION["mine"])) initMine(); + if(empty($_SESSION["mine"])) initCraftMine(); $mine = $_SESSION["mine"]; echo $mine["gold"]; } -- cgit v1.2.3-70-g09d2 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 'inc') 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-70-g09d2 From 3ece645cc83e36aaa36c0258afa0f1b36eb13ca2 Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 25 Apr 2016 10:25:46 +0200 Subject: remove useless files and add .gitignore to not see them again --- .gitignore | 1 + inc/mine.inc~ | 20 -------------------- js/craftmine.js~ | 51 --------------------------------------------------- 3 files changed, 1 insertion(+), 71 deletions(-) create mode 100644 .gitignore delete mode 100644 inc/mine.inc~ delete mode 100644 js/craftmine.js~ (limited to 'inc') diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ 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 @@ - 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/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); -} -- cgit v1.2.3-70-g09d2 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 'inc') 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-70-g09d2