1 from parser import ArgError
6 def __init__(self, size=(0, 0), terrain=''):
10 def set_line(self, y, line):
11 height_map = self.size[0]
12 width_map = self.size[1]
14 raise ArgError('too large row number %s' % y)
15 width_line = len(line)
16 if width_line > width_map:
17 raise ArgError('too large map line width %s' % width_line)
18 self.terrain = self.terrain[:y * width_map] + line +\
19 self.terrain[(y + 1) * width_map:]
21 def get_position_index(self, yx):
22 return yx[0] * self.size[1] + yx[1]
28 self.Map = Map # child classes may use an extended Map class here
29 self.Thing = Thing # child classes may use an extended Thing class here
31 self.map_ = self.Map()
34 def get_thing(self, id_):
35 for thing in self.things:
38 t = self.Thing(self, id_)
42 def new_map(self, yx):
43 self.map_ = self.Map(yx, '?')
48 def __init__(self, world, id_):
55 class CommonCommandsMixin:
57 def cmd_MAP(self, yx):
58 """Create new map of size yx and only '?' cells."""
59 self.world.new_map(yx)
60 cmd_MAP.argtypes = 'yx_tuple:nonneg'
62 def cmd_THING_TYPE(self, i, type_):
63 t = self.world.get_thing(i)
65 cmd_THING_TYPE.argtypes = 'int:nonneg string'
67 def cmd_THING_POS(self, i, yx):
68 t = self.world.get_thing(i)
70 cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'