+ def update_terrain(self, terrain_map):
+ """Update self.terrain_map. Ensure size matching self.map_size."""
+ lines = terrain_map.split('\n')
+ if len(lines) != self.map_size[0]:
+ raise ArgumentError('wrong map height')
+ for line in lines:
+ if len(line) != self.map_size[1]:
+ raise ArgumentError('wrong map width')
+ self.terrain_map = terrain_map
+ self.draw_map()
+
+ def update_things(self, thing_description):
+ """Append thing of thing_description to self.things."""
+ thing_types = {'human': '@', 'monster': 'M'}
+ tokens = thing_description.split()
+ if len(tokens) != 2:
+ raise ArgumentError('Wrong number of tokens.')
+ yx = self.get_yx(tokens[1])
+ if yx[0] >= self.map_size[0] or yx[1] >= self.map_size[1]:
+ raise ArgumentError('Position outside of map size bounds.')
+ type_token = tokens[0]
+ prefix = 'TYPE:'
+ type_ = '?'
+ if len(type_token) <= len(prefix) or \
+ type_token[:len(prefix)] != prefix:
+ raise ArgumentError('Invalid type token.')
+ type_ = type_token[len(prefix):]
+ if type_ not in thing_types:
+ raise ArgumentError('Unknown thing type.')
+ self.things += [self.Thing(yx, thing_types[type_])]
+ self.draw_map()
+
+ def clear_things(self, _):
+ self.things = []
+