home · contact · privacy
Add basic multiplayer roguelike chat example.
[plomrogue2-experiments] / new2 / plomrogue / tasks.py
1 from plomrogue.errors import GameError
2 #from plomrogue.misc import quote
3 from plomrogue.mapping import YX
4
5
6
7 class Task:
8     argtypes = ''
9     todo = 3
10
11     def __init__(self, thing, args=()):
12         self.thing = thing
13         self.args = args
14
15     def check(self):
16         pass
17
18
19
20 class Task_WAIT(Task):
21     todo = 1
22
23     def do(self):
24         return 'success'
25
26
27
28 class Task_MOVE(Task):
29     argtypes = 'string:direction'
30
31     def get_move_target(self):
32         moves = {
33             'UP': YX(-1, 0),
34             'DOWN': YX(1, 0),
35             'LEFT': YX(0, -1),
36             'RIGHT': YX(0, 1),
37         }
38         return self.thing.position + moves[self.args[0]]
39
40     def check(self):
41         test_pos = self.get_move_target()
42         if test_pos.y < 0 or test_pos.x < 0 or test_pos.y >= 24 or test_pos.x >= 40: 
43             raise GameError('would move out of map')
44
45     def do(self):
46         self.thing.position = self.get_move_target()