home · contact · privacy
Introduce map geometry.
[plomrogue2-experiments] / new2 / plomrogue / mapping.py
index 1847f691a79f7cef829a3a6bc1b4323397e38488..aa5af2c6778c33444e51de1f74236e61a8442838 100644 (file)
@@ -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)