-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGame.class.inc
65 lines (53 loc) · 1.21 KB
/
Game.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once('Area.class.inc');
require_once('Object.class.inc');
require_once('Exit.class.inc');
class Game
{
private $areasByName;
private $objectsByName;
public $metadata;
public function __construct($pGameFile)
{
require_once('Tokenizer.class.inc');
require_once('Parser.class.inc');
$tokenizer = new Tokenizer(file_get_contents($pGameFile));
$parser = new Parser($tokenizer);
if (!$parser->parse()) exit; // parse and quit on error
$this->areasByName = array();
foreach ($parser->areas as $area)
{
$this->areasByName[$area->name] = $area;
}
$this->objectsByName = array();
foreach ($parser->objects as $object)
{
$this->objectsByName[$object->name] = $object;
}
$this->metadata = $parser->metadata;
}
public static function get()
{
if (!isset($_SESSION['game']))
{
$_SESSION['game'] = new Game('main.game');
}
return $_SESSION['game'];
}
public function getArea($pName)
{
if (array_key_exists($pName, $this->areasByName))
{
return $this->areasByName[$pName];
}
return false;
}
public function getObject($pName)
{
if (array_key_exists($pName, $this->objectsByName))
{
return $this->objectsByName[$pName];
}
return false;
}
}