Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/game_map.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-02-06 00:53:00 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-02-06 00:53:00 (GMT)
commit952583926af90301cfee57c19cf72f4de9954598 (patch)
treead6c0203329b8ff64144e8a6e2bee52a4be42e26 /game_map.py
parentf38aa41dc7e7553b7cd3d5c2b0ce744dd1262e77 (diff)
Add a class to test basic navigation in the map
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'game_map.py')
-rw-r--r--game_map.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/game_map.py b/game_map.py
index e77e33c..f8d1035 100644
--- a/game_map.py
+++ b/game_map.py
@@ -184,25 +184,39 @@ class GameMap():
if direction == 'W':
return x, y + 1, direction
- def cross_door(self, x, y, direction, door):
+ def cross_door(self, x, y, direction):
""" Return next position if the user go to the left"""
# verify is the door is in the right position/direction
objects = self.get_wall_info(x, y, direction)
if objects is None:
return x, y, direction
else:
- for door_object in objects:
- if door_object == door:
- if direction == 'N':
- return x, y - 1, direction
- if direction == 'E':
- return x + 1, y, direction
- if direction == 'S':
- return x, y + 1, direction
- if direction == 'W':
- return x - 1, y, direction
- # do not found the door
- return x, y, direction
+ if self.have_door(objects):
+ new_x, new_y, new_dir = self.go_forward(x, y, direction)
+ if self.get_wall_info(new_x, new_y, new_dir) is None:
+ new_x, new_y, new_dir = self.go_forward(new_x, new_y,
+ new_dir)
+ return new_x, new_y, new_dir
+ else:
+ return x, y, direction
+
+ def go_forward(self, x, y, direction):
+ if direction == 'N':
+ return x, y - 1, direction
+ if direction == 'E':
+ return x + 1, y, direction
+ if direction == 'S':
+ return x, y + 1, direction
+ if direction == 'W':
+ return x - 1, y, direction
+
+ def have_door(self, wall_info):
+ _have_door = False
+ for wall_object in wall_info:
+ if wall_object.startswith('door'):
+ _have_door = True
+ break
+ return _have_door
# testing