From 10a159da62d269ad7bd03025f08eac620c69cf1a Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 23 Apr 2016 20:32:58 +0200 Subject: add require_once and some cases of the switch --- craftmine.php | 3 +++ 1 file changed, 3 insertions(+) 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(); } -- cgit v1.2.3-54-g00ecf From 56145311017bb5ede4b65f531e50d92a1edc1544 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sat, 23 Apr 2016 20:35:05 +0200 Subject: add 2 buttons for createGuild and hireMiner --- index.xhtml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.xhtml b/index.xhtml index 5b38b69..30352bf 100644 --- a/index.xhtml +++ b/index.xhtml @@ -11,13 +11,18 @@ CraftMine +

CraftMine

- 0 - 0 +

Gold : 0

+

Mine : 0

+

Miners : 0

+
+ +
-- cgit v1.2.3-54-g00ecf 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 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-54-g00ecf 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 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 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(-) 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-54-g00ecf From a6768cc97e3b418e0df08bcc2b09d8ffb1c9daa2 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 24 Apr 2016 14:08:31 +0200 Subject: nothing special --- js/craftmine.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/craftmine.js b/js/craftmine.js index 50d3a47..4ccdf2f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,7 +1,7 @@ datas = { gold: 0, mine: 0, - miners: 1, + miners: 0, level: 1 } @@ -34,7 +34,7 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(xhr) { var ret = xhr.responseText; - datas.gold = ret; + datas.gold = parseInt(ret); updateDatas("gold"); }) } -- 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(-) 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 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~ 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-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(-) 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 From 8140617aeb2f32f7095a443ca743c6d6915739c6 Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 25 Apr 2016 13:45:05 +0200 Subject: change class of Hire a Miner, and change type submit to button for items --- index.xhtml | 2 +- js/shop.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.xhtml b/index.xhtml index 1685eb9..aa29615 100644 --- a/index.xhtml +++ b/index.xhtml @@ -31,7 +31,7 @@
- +
diff --git a/js/shop.js b/js/shop.js index 00636e1..22ca85f 100644 --- a/js/shop.js +++ b/js/shop.js @@ -25,7 +25,7 @@ function buildShop() { function addItem(ret) { var itemhtml = "
  • "; - itemhtml += ""; + itemhtml += ""; itemhtml += "
  • "; var invcontent = document.getElementById("tab3"); -- cgit v1.2.3-54-g00ecf