home · contact · privacy
Refactor and extend new library.
[plomrogue2-experiments] / new / plomrogue / tasks.py
1 from plomrogue.errors import GameError
2 from plomrogue.misc import quote
3
4
5
6 class Task:
7     argtypes = ''
8
9     def __init__(self, thing, args=()):
10         self.thing = thing
11         self.args = args
12         self.todo = 3
13
14     @property
15     def name(self):
16         prefix = 'Task_'
17         class_name = self.__class__.__name__
18         return class_name[len(prefix):]
19
20     def check(self):
21         pass
22
23     def get_args_string(self):
24         stringed_args = []
25         for arg in self.args:
26             if type(arg) == str:
27                 stringed_args += [quote(arg)]
28             else:
29                 raise GameError('stringifying arg type not implemented')
30         return ' '.join(stringed_args)
31
32
33
34 class Task_WAIT(Task):
35
36     def do(self):
37         return 'success'
38
39
40
41 class Task_MOVE(Task):
42     argtypes = 'string:direction'
43
44     def check(self):
45         test_pos = self.thing.world.map_.move(self.thing.position, self.args[0])
46         if self.thing.world.map_[test_pos] != '.':
47             raise GameError('%s would move into illegal terrain' % self.thing.id_)
48         for t in self.thing.world.things:
49             if t.position == test_pos:
50                 raise GameError('%s would move into other thing' % self.thing.id_)
51
52     def do(self):
53         self.thing.position = self.thing.world.map_.move(self.thing.position,
54                                                          self.args[0])