X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=new2%2Fplomrogue%2Fmapping.py;fp=new2%2Fplomrogue%2Fmapping.py;h=aa5af2c6778c33444e51de1f74236e61a8442838;hb=e1d03eb7d5f847813071e1711accbb4d9153fdcf;hp=1847f691a79f7cef829a3a6bc1b4323397e38488;hpb=8f4f45798471d5b0069d7ac2caaf7d6a389ce981;p=plomrogue2-experiments diff --git a/new2/plomrogue/mapping.py b/new2/plomrogue/mapping.py index 1847f69..aa5af2c 100644 --- a/new2/plomrogue/mapping.py +++ b/new2/plomrogue/mapping.py @@ -12,3 +12,38 @@ class YX(collections.namedtuple('YX', ('y', 'x'))): def __str__(self): return 'Y:%s,X:%s' % (self.y, self.x) + + + +class MapGeometry(): + + def get_directions(self): + directions = [] + for name in dir(self): + if name[:5] == 'move_': + directions += [name[5:]] + return directions + + def move(self, start_pos, direction): + mover = getattr(self, 'move_' + direction) + return mover(start_pos) + + + +class MapGeometryWithLeftRightMoves(MapGeometry): + + def move_LEFT(self, start_pos): + return YX(start_pos.y, start_pos.x - 1) + + def move_RIGHT(self, start_pos): + return YX(start_pos.y, start_pos.x + 1) + + + +class MapGeometrySquare(MapGeometryWithLeftRightMoves): + + def move_UP(self, start_pos): + return YX(start_pos.y - 1, start_pos.x) + + def move_DOWN(self, start_pos): + return YX(start_pos.y + 1, start_pos.x)