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 set_size(self, yx):
25 for y in range(self.size[0]):
26 self.terrain += '?' * self.size[1]
35 self.Thing = Thing # child classes may use an extended Thing class here
37 def get_thing(self, id_):
38 for thing in self.things:
41 t = self.Thing(self, id_)
48 def __init__(self, world, id_):
55 class CommonCommandsMixin:
57 def cmd_MAP_SIZE(self, yx):
58 """Set self.map_size to yx, redraw self.terrain_map as '?' cells."""
59 self.world.map_.set_size(yx)
60 cmd_MAP_SIZE.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'