aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Item.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Item.inc')
-rw-r--r--inc/Item.inc57
1 files changed, 56 insertions, 1 deletions
diff --git a/inc/Item.inc b/inc/Item.inc
index a8ee302..435ca1c 100644
--- a/inc/Item.inc
+++ b/inc/Item.inc
@@ -2,13 +2,50 @@
require_once("perso.inc");
+/**
+ * Represent an Item in the shop or in the Inventory.
+ *
+ * @package inc\Item.inc
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
class Item {
+
+ /**
+ * @var string Name of the item.
+ */
public $name = "";
+
+ /**
+ * @var int Item's cost.
+ */
public $cost = 0;
+
+ /**
+ * @var string Item's icon.
+ */
public $icon = "";
+
+ /**
+ * @var string Item's description.
+ */
public $desc = "";
+
+ /**
+ * @var array 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,6 +54,11 @@ class Item {
$this->feat = $feat;
}
+ /**
+ * Applies Item's features on the player.
+ *
+ * @return void
+ */
function consume() {
foreach($this->feat as $k => $v) {
switch($k) {
@@ -26,6 +68,13 @@ class Item {
}
}
+ /**
+ * 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 +87,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
}
}