|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Adventure\Utils; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Provides information about available actions in the game, including their names, targets, and descriptions. |
|
7
|
|
|
*/ |
|
8
|
|
|
class AvailableActionsProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Retrieves the available actions with their corresponding descriptions. |
|
12
|
|
|
* |
|
13
|
|
|
* @return array<int, array<string, string>> An array of available actions, each containing 'name', 'target', and 'description'. |
|
14
|
|
|
*/ |
|
15
|
10 |
|
public static function getAvailableActions(): array |
|
16
|
|
|
{ |
|
17
|
10 |
|
$availableActions = [ |
|
18
|
10 |
|
[ |
|
19
|
10 |
|
'name' => 'help', |
|
20
|
10 |
|
'target' => '<action>', |
|
21
|
10 |
|
'description' => 'Get help on available actions', |
|
22
|
10 |
|
], |
|
23
|
10 |
|
[ |
|
24
|
10 |
|
'name' => 'where', |
|
25
|
10 |
|
'target' => '', |
|
26
|
10 |
|
'description' => 'Recall where you are and view all exits and interactions in your current location', |
|
27
|
10 |
|
], |
|
28
|
10 |
|
[ |
|
29
|
10 |
|
'name' => 'inventory', |
|
30
|
10 |
|
'target' => '', |
|
31
|
10 |
|
'description' => 'View the items currently in your inventory' |
|
32
|
10 |
|
], |
|
33
|
10 |
|
[ |
|
34
|
10 |
|
'name' => 'examine', |
|
35
|
10 |
|
'target' => '<item>', |
|
36
|
10 |
|
'description' => 'Examine an item in your inventory or in the current location for more information', |
|
37
|
10 |
|
], |
|
38
|
10 |
|
[ |
|
39
|
10 |
|
'name' => 'take', |
|
40
|
10 |
|
'target' => '<item>', |
|
41
|
10 |
|
'description' => 'Take an item from the current location and add it to your inventory' |
|
42
|
10 |
|
], |
|
43
|
10 |
|
[ |
|
44
|
10 |
|
'name' => 'use', |
|
45
|
10 |
|
'target' => '<item>', |
|
46
|
10 |
|
'description' => 'Use an item from your inventory' |
|
47
|
10 |
|
], |
|
48
|
10 |
|
[ |
|
49
|
10 |
|
'name' => 'go', |
|
50
|
10 |
|
'target' => '<direction>', |
|
51
|
10 |
|
'description' => 'Move to a different location in the specified direction (e.g., north, south, east, west)', |
|
52
|
10 |
|
], |
|
53
|
10 |
|
]; |
|
54
|
|
|
|
|
55
|
10 |
|
return $availableActions; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Checks if a given action is valid. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $action The action to validate. |
|
62
|
|
|
* @return bool True if the action is valid, false otherwise. |
|
63
|
|
|
*/ |
|
64
|
32 |
|
public static function isValidAction(string $action): bool |
|
65
|
|
|
{ |
|
66
|
32 |
|
$validActions = ['help', 'where', 'inventory', 'use', 'take', 'go', 'examine']; |
|
67
|
|
|
|
|
68
|
32 |
|
return in_array($action, $validActions); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|