diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Inventory.inc | 14 | ||||
-rw-r--r-- | inc/shop.inc | 4 |
2 files changed, 14 insertions, 4 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc index efe54f2..3396eb9 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -20,12 +20,21 @@ class Inventory { } private function _addItem($item) { - $this->items[] = $item; + $counter = 0; + foreach($this->items as $object){ + if($object[0] == $item){ + $counter++; + } + } + $tab = array($item,$counter+1); + $this->items[] = $tab; + return $tab; } public static function addItem($item) { $inv = self::get(); - $inv->_addItem($item); + $tab = $inv->_addItem($item); + return $tab; } private function _removeItem($item) { @@ -36,6 +45,7 @@ class Inventory { $inv = self::get(); $inv->_removeItem($item); } + } ?> diff --git a/inc/shop.inc b/inc/shop.inc index 6e30923..83b08b0 100644 --- a/inc/shop.inc +++ b/inc/shop.inc @@ -56,8 +56,8 @@ function buildShop() { function buyItem() { $item = getItem($_POST["item"]); if($item && debitAccount($item->cost)) { - Inventory::addItem($item); - echo json_encode($item); + $tab = Inventory::addItem($item); + echo json_encode($tab); //renvoyer un tableau avec comme première entrée $item et comme deuxième entrée le nombre } } |