diff options
author | piernov <piernov@piernov.org> | 2016-05-07 13:48:28 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-07 13:48:28 +0200 |
commit | b91588134f3067c2771011c10af77cda5f9031e8 (patch) | |
tree | a8e5f1bde0bfe9539bb5dd29e249ee8c6b1f36d6 /inc | |
parent | 8621eae6aa5fcdba0a60f0a5f1136412c61999ec (diff) | |
parent | 80f5826d1ac8f6d42866d5133c6f463943b96bab (diff) | |
download | candybox-b91588134f3067c2771011c10af77cda5f9031e8.tar.gz candybox-b91588134f3067c2771011c10af77cda5f9031e8.tar.bz2 candybox-b91588134f3067c2771011c10af77cda5f9031e8.tar.xz candybox-b91588134f3067c2771011c10af77cda5f9031e8.zip |
Merge branch 'alexichi' into feat/gui
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Inventory.inc | 17 | ||||
-rw-r--r-- | inc/Monster.inc | 4 | ||||
-rw-r--r-- | inc/craftmine.inc | 2 | ||||
-rw-r--r-- | inc/dungeon.inc | 21 | ||||
-rw-r--r-- | inc/perso.inc | 23 | ||||
-rw-r--r-- | inc/shop.inc | 6 |
6 files changed, 66 insertions, 7 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 024a4fe..747c4db 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -46,6 +46,23 @@ class Inventory { $inv->_removeItem($item); } + private function _useItem($item) { + foreach($this->items as $k => $object){ + if($object[0] == $item){ + if($this->items[$k][1]>0)$this->items[$k][1]--; + //if($this->items[$k][1] == 0) _removeItem($item); + return $this->items[$k]; + } + } + return false; + } + + public static function useItem($item) { + $inv = self::get(); + $it = $inv->_useItem($item); + return $it; + } + public function addToXML($root) { foreach($this->items as $item) $item->addToXML($root); diff --git a/inc/Monster.inc b/inc/Monster.inc index fbb0fe9..c7063ec 100644 --- a/inc/Monster.inc +++ b/inc/Monster.inc @@ -5,12 +5,14 @@ class Monster { public $icon = ""; public $desc = ""; public $hp = 1; + public $xp = 0; public $level = 1; - function __construct($name, $level, $hp, $icon) { + function __construct($name, $level, $hp, $xp, $icon) { $this->name = $name; $this->level = $level; $this->hp = $hp; + $this->xp = $xp; $this->icon = $icon; } diff --git a/inc/craftmine.inc b/inc/craftmine.inc index 0d6a445..f5dbbb1 100644 --- a/inc/craftmine.inc +++ b/inc/craftmine.inc @@ -3,6 +3,7 @@ require_once("mine.inc"); require_once("shop.inc"); require_once("dungeon.inc"); +require_once("perso.inc"); function sendCraftMine() { $data = array("gold" => sendMine(), @@ -10,6 +11,7 @@ function sendCraftMine() { "inventory" => Inventory::sendContent(), "miners" => sendMiners(), "dungeon" => sendDungeon(), + "perso" => sendPerso(), ); echo json_encode($data); } diff --git a/inc/dungeon.inc b/inc/dungeon.inc index 81e2ba7..c023cf8 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -12,8 +12,9 @@ function generateMonster(){ $dungeon["monsters"][$floor] = array(); foreach($f as $monster){ $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, - intval($monster->level), - intval($monster->hp), + intval($monster->level), + intval($monster->hp), + intval($monster->xp), (string)$monster->icon); } } @@ -21,12 +22,12 @@ function generateMonster(){ } function initDungeon() { - $_SESSION["dungeon"] = true; + $_SESSION["dungeon"]["access"] = true; } function sendDungeon() { if(!empty($_SESSION["dungeon"])) - return generateMonster(); + return $_SESSION["dungeon"]; else return false; } @@ -43,14 +44,22 @@ function buildDungeon() { } function launchDungeon(){ + $f= $_POST["floor"]; $dungeon=generateMonster(); - $opponent = $dungeon["monsters"]["floor1"]; + $opponent = $dungeon["monsters"]["floor".$f]; echo json_encode($opponent); } +function sendDungeonProgress(){ + $f= $_POST["floor"]; + $nb=$_POST["mob"]; + $_SESSION["dungeon"]["flat"] = $f; + $_SESSION["dungeon"]["mob"] = $nb; +} + + function exitDungeon(){ $_SESSION["dungeon"] = false; - echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. } ?> diff --git a/inc/perso.inc b/inc/perso.inc new file mode 100644 index 0000000..0362d8c --- /dev/null +++ b/inc/perso.inc @@ -0,0 +1,23 @@ +<?php +function sendPerso() { + if(empty($_SESSION["perso"])) + initPerso(); + return $_SESSION["perso"]; +} + +function updatePerso(){ + $hp = $_POST["hp"]; + $xp = $_POST["xp"]; + $lv = $_POST["lv"]; + $_SESSION["perso"]["hp"] = $hp; + $_SESSION["perso"]["xp"] = intval($xp); + $_SESSION["perso"]["lv"] = $lv; +} + +function initPerso(){ + $_SESSION["perso"]["hp"] = 5; + $_SESSION["perso"]["xp"] = 0; + $_SESSION["perso"]["lv"] = 3; +} + +?> diff --git a/inc/shop.inc b/inc/shop.inc index 49ee20b..32ecea2 100644 --- a/inc/shop.inc +++ b/inc/shop.inc @@ -60,5 +60,11 @@ function buyItem() { } } +function useItem(){ + $item = getItem($_POST["item"]); + $it = Inventory::useItem($item); + echo json_encode($it); +} + ?> |