X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=new2%2Fplomrogue%2Fmapping.py;h=f056e105ca57a11d59b45d8451bada77211ef703;hb=804c0812954c9ab11bffaef5fee644ee4350b2a6;hp=cd0c23def676edd8eb146fca15da7c781201fb28;hpb=8db0e200f8c2d279c68ca01b9ae235ab63c8f642;p=plomrogue2-experiments diff --git a/new2/plomrogue/mapping.py b/new2/plomrogue/mapping.py index cd0c23d..f056e10 100644 --- a/new2/plomrogue/mapping.py +++ b/new2/plomrogue/mapping.py @@ -1,4 +1,5 @@ import collections +from plomrogue.errors import ArgError @@ -27,6 +28,12 @@ class MapGeometry(): directions += [name[5:]] return directions + def get_neighbors(self, pos): + neighbors = {} + for direction in self.get_directions(): + neighbors[direction] = self.move(pos, direction) + return neighbors + def move(self, start_pos, direction): mover = getattr(self, 'move_' + direction) target = mover(start_pos) @@ -77,5 +84,21 @@ class Map(): def size_i(self): return self.size.y * self.size.x + def set_line(self, y, line): + height_map = self.size.y + width_map = self.size.x + if y >= height_map: + raise ArgError('too large row number %s' % y) + width_line = len(line) + if width_line != width_map: + raise ArgError('map line width %s unequal map width %s' % (width_line, width_map)) + self.terrain = self.terrain[:y * width_map] + line +\ + self.terrain[(y + 1) * width_map:] + def get_position_index(self, yx): return yx.y * self.size.x + yx.x + + def lines(self): + width = self.size.x + for y in range(self.size.y): + yield (y, self.terrain[y * width:(y + 1) * width])