home · contact · privacy
Refactor key movement initialization.
[plomrogue2-experiments] / new2 / plomrogue / tasks.py
1 from plomrogue.errors import PlayError
2 from plomrogue.mapping import YX
3
4
5
6 class Task:
7     argtypes = ''
8     todo = 3
9
10     def __init__(self, thing, args=()):
11         self.thing = thing
12         self.args = args
13
14     def check(self):
15         pass
16
17
18
19 class Task_WAIT(Task):
20     todo = 1
21
22     def do(self):
23         return 'success'
24
25
26
27 class Task_MOVE(Task):
28     todo = 1
29     argtypes = 'string:direction'
30
31     def get_move_target(self):
32         return self.thing.game.map_geometry.move(self.thing.position,
33                                                  self.args[0])
34
35     def check(self):
36         test_pos = self.get_move_target()
37         if test_pos is None:
38             raise PlayError('would move out of map')
39         elif self.thing.game.map[test_pos] != '.':
40             raise PlayError('would move into illegal territory')
41
42     def do(self):
43         self.thing.position = self.get_move_target()
44
45
46
47 class Task_WRITE(Task):
48     todo = 1
49     argtypes = 'string:char'
50
51     def check(self):
52         pass
53
54     def do(self):
55         self.thing.game.map[self.thing.position] = self.args[0]
56
57
58
59 class Task_FLATTEN_SURROUNDINGS(Task):
60     todo = 10
61
62     def check(self):
63         pass
64
65     def do(self):
66         self.thing.game.map[self.thing.position] = '.'
67         for yx in self.thing.game.map_geometry.get_neighbors(self.thing.position).values():
68             if yx is not None:
69                 self.thing.game.map[yx] = '.'