forked from greyblue9/text-adventure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.php
137 lines (109 loc) · 2.63 KB
/
command.php
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
function debug($pVar)
{
if (isset($_GET['debug']))
{
print("\n <pre> {debug_output} \n");
if (gettype($pVar) == 'object' || gettype($pVar) == 'array')
print_r($pVar);
else
var_dump($pVar);
print("\n {debug_end} </pre> \n");
}
}
require_once('Game.class.inc');
require_once('Player.class.inc');
require_once('Executive.class.inc');
$cmd = (isset($_POST['command']))? strtolower(trim($_POST['command'])): '';
if ($cmd == '')
{
print('I beg your pardon?');
exit;
}
session_start();
// _______________________
//___/ Command processing \______________________________________
/** @var Executive */
$executive = Executive::get();
$words = explode(' ', $cmd);
// Process first word (verb)
$verb = array_shift($words);
if ($verb == 'walk' || $verb == 'go')
{
$verb = array_shift($words);
}
debug('Verb: '.$verb);
$response = 'What?';
switch ($verb)
{
case 'look':
$response = $executive->look();
break;
case 'north':
case 'n':
$response = $executive->go(Executive::NORTH);
break;
case 'south':
case 's':
$response = $executive->go(Executive::SOUTH);
break;
case 'west':
case 'w':
$response = $executive->go(Executive::WEST);
break;
case 'east':
case 'e':
$response = $executive->go(Executive::EAST);
break;
case 'down':
case 'd':
$response = $executive->go(Executive::DOWN);
break;
case 'up':
case 'u':
$response = $executive->go(Executive::UP);
break;
case 'left':
case 'l':
$response = $executive->go(Executive::LEFT);
break;
case 'right':
case 'r':
$response = $executive->go(Executive::RIGHT);
break;
case 'in':
case 'through':
case 'out':
$response = $executive->go(Executive::DOOR);
break;
case 'die':
$response = 'You are dead to me.';
break;
case 'take':
case 'get':
case 'carry':
case 'pick':
// $objWords: ['knife'], ['blue', 'ball'], ['red', 'brick'], etc.
$objWords = $words;
if (count($objWords))
{
$response = $executive->pickUp($objWords);
}
break;
case 'drop':
// $objWords: ['knife'], ['blue', 'ball'], ['red', 'brick'], etc.
$objWords = $words;
if (count($objWords))
{
$response = $executive->drop($objWords);
}
break;
case 'inventory':
case 'inv':
case 'i':
$response = $executive->showInventory();
break;
default:
break;
}
print(nl2br($response));