-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
61 lines (49 loc) · 1.53 KB
/
command.py
File metadata and controls
61 lines (49 loc) · 1.53 KB
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
from enum import Enum, auto
import libtcodpy as tcod
class Command:
def __init__(self, action, item=None):
self.action = action
self.item = item # item to do it with, if any
class ActionType(Enum):
MoveUp = auto()
MoveDown = auto()
MoveLeft = auto()
MoveRight = auto()
MoveUpLeft = auto()
MoveUpRight = auto()
MoveDownLeft = auto()
MoveDownRight = auto()
Rest = auto()
Pickup = auto()
Describe = auto()
Apply = auto()
Exit = auto()
command_keys = {
tcod.KEY_UP: ActionType.MoveUp,
tcod.KEY_DOWN: ActionType.MoveDown,
tcod.KEY_LEFT: ActionType.MoveLeft,
tcod.KEY_RIGHT: ActionType.MoveRight,
'k': ActionType.MoveUp,
'j': ActionType.MoveDown,
'h': ActionType.MoveLeft,
'l': ActionType.MoveRight,
'y': ActionType.MoveUpLeft,
'u': ActionType.MoveUpRight,
'b': ActionType.MoveDownLeft,
'n': ActionType.MoveDownRight,
's': ActionType.Rest,
',': ActionType.Pickup,
'i': ActionType.Describe,
'a': ActionType.Apply,
tcod.KEY_ESCAPE: ActionType.Exit,
}
MOVES = {ActionType.MoveUp: (0, -1),
ActionType.MoveDown: (0, 1),
ActionType.MoveRight: (1, 0),
ActionType.MoveLeft: (-1, 0),
ActionType.MoveUpLeft: (-1, -1),
ActionType.MoveUpRight: (1, -1),
ActionType.MoveDownLeft: (-1, 1),
ActionType.MoveDownRight: (1, 1)}
def handle_key(key):
return command_keys.get(key.vk) or command_keys.get(chr(key.c))