X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=new2%2Fplomrogue%2Fmapping.py;h=e0a59d8e225f56af79b0b516bb7f6e366de164a4;hb=1fcb132eabcaa1a95bf2b527dc18c92c15016d2a;hp=2edbea84809acbfc759aed7993e603ffdb9c74e6;hpb=a213ed788c8f305ea9c2192eabfb0d3562c8b2fa;p=plomrogue2-experiments diff --git a/new2/plomrogue/mapping.py b/new2/plomrogue/mapping.py index 2edbea8..e0a59d8 100644 --- a/new2/plomrogue/mapping.py +++ b/new2/plomrogue/mapping.py @@ -1,4 +1,5 @@ import collections +from plomrogue.errors import ArgError @@ -63,6 +64,38 @@ class MapGeometrySquare(MapGeometryWithLeftRightMoves): +class MapGeometryHex(MapGeometryWithLeftRightMoves): + + def move_UPLEFT(self, start_pos): + start_indented = start_pos.y % 2 + if start_indented: + return YX(start_pos.y - 1, start_pos.x) + else: + return YX(start_pos.y - 1, start_pos.x - 1) + + def move_UPRIGHT(self, start_pos): + start_indented = start_pos.y % 2 + if start_indented: + return YX(start_pos.y - 1, start_pos.x + 1) + else: + return YX(start_pos.y - 1, start_pos.x) + + def move_DOWNLEFT(self, start_pos): + start_indented = start_pos.y % 2 + if start_indented: + return YX(start_pos.y + 1, start_pos.x) + else: + return YX(start_pos.y + 1, start_pos.x - 1) + + def move_DOWNRIGHT(self, start_pos): + start_indented = start_pos.y % 2 + if start_indented: + return YX(start_pos.y + 1, start_pos.x + 1) + else: + return YX(start_pos.y + 1, start_pos.x) + + + class Map(): def __init__(self, map_size): @@ -89,8 +122,8 @@ class Map(): if y >= height_map: raise ArgError('too large row number %s' % y) width_line = len(line) - if width_line > width_map: - raise ArgError('too large map line width %s' % width_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:]