forked from greyblue9/text-adventure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.class.inc
52 lines (42 loc) · 994 Bytes
/
Player.class.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once('Game.class.inc');
class Player
{
public $location;
public $inventoryByName;
public function __construct()
{
$this->location = Game::get()->metadata['start'];
$this->inventoryByName = array();
}
public static function get()
{
if (!isset($_SESSION['player']))
{
$_SESSION['player'] = new Player();
}
return $_SESSION['player'];
}
public function addToInventory($pObjName)
{
$this->inventoryByName[$pObjName] = true;
}
public function removeFromInventory($pObjName)
{
if (isset($this->inventoryByName[$pObjName]))
{
unset($this->inventoryByName[$pObjName]);
}
}
public function hasObject($pObjName)
{
return (isset($this->inventoryByName[$pObjName]));
}
/**
@return <array> List of object names in inventory
*/
public function getInventory()
{
return array_keys($this->inventoryByName);
}
}