From faefddcb8b3d3ac491331b702f8a8ac6fe58a894 Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 20:14:40 +0200 Subject: First PHPDoc push, Inventory not complete --- inc/Item.inc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'inc/Item.inc') diff --git a/inc/Item.inc b/inc/Item.inc index 8eebbf8..4ec984f 100644 --- a/inc/Item.inc +++ b/inc/Item.inc @@ -2,13 +2,49 @@ require_once("perso.inc"); +/** + * Represent an Item in the shop or in the Inventory. + * + * @author Alexandre Renoux + * @author Pierre-Emmanuel Novac + */ class Item { + + /** + * Name of the item. + */ public $name = ""; + + /** + * Item's cost. + */ public $cost = 0; + + /** + * Item's icon. + */ public $icon = ""; + + /** + * Item's description. + */ public $desc = ""; + + /** + * Item's features as an associative array + */ public $feat = array(); + /** + * Item's constructor + * + * @param string $name Item's name + * @param int $cost Item's cost + * @param string $icon Item's icon + * @param string $desc Item's description + * @param array $feat associative array of strings describing the Item's features + * @return void + */ function __construct($name, $cost, $icon, $desc, $feat) { $this->name = $name; $this->cost = $cost; @@ -17,15 +53,27 @@ class Item { $this->feat = $feat; } + /** + * Applies Item's features on the player. + * + * @return void + */ function consume() { foreach($this->feat as $k => $v) { switch($k) { case "hp": increasePerso("hp", +$v); break; - case "power": break; + case "power": break; // TODO: do something with power } } } + /** + * Generates an XML tree describing the Item + * + * @param SimpleXMLElement $xml root XML element to add the Item's property to + * @param int $count numbers of Items + * @return void + */ function addToXML($root, $count) { $item = $root->addChild("item"); $item->addChild("name", $this->name); @@ -38,12 +86,18 @@ class Item { $item->addChild("count", $count); } + /** + * Generates an Item object from an XML tree + * + * @param SimpleXMLElement $xml root XML element representing the Item + * @return void + */ public static function fromXML($xml) { $feats = array(); foreach($xml->feat[0] as $k => $v) $feats[(string)$k] = (string)$v; - return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc, $feats); + return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc, $feats); // Call constructor } } -- cgit v1.2.3-54-g00ecf