home · contact · privacy
De-hardcode map size test.
[plomrogue2-experiments] / new2 / plomrogue / mapping.py
index aa5af2c6778c33444e51de1f74236e61a8442838..585000a1d0f471dfd8b4b5d2c0a3f6ecccb39445 100644 (file)
@@ -17,6 +17,9 @@ class YX(collections.namedtuple('YX', ('y', 'x'))):
 
 class MapGeometry():
 
+    def __init__(self, size):
+        self.size = size
+
     def get_directions(self):
         directions = []
         for name in dir(self):
@@ -26,7 +29,11 @@ class MapGeometry():
 
     def move(self, start_pos, direction):
         mover = getattr(self, 'move_' + direction)
-        return mover(start_pos)
+        target = mover(start_pos)
+        if target.y < 0 or target.x < 0 or \
+                target.y >= self.size.y or target.x >= self.size.x:
+            return None
+        return target