summaryrefslogtreecommitdiffstats
path: root/weatbag
diff options
context:
space:
mode:
Diffstat (limited to 'weatbag')
-rw-r--r--weatbag/__init__.py45
-rw-r--r--weatbag/action.py25
-rw-r--r--weatbag/tiles/centre.py5
3 files changed, 33 insertions, 42 deletions
diff --git a/weatbag/__init__.py b/weatbag/__init__.py
index 7212bfa..7c39d21 100644
--- a/weatbag/__init__.py
+++ b/weatbag/__init__.py
@@ -34,7 +34,7 @@ class World:
try:
return self.tiles[key]
except KeyError:
- n,e = key
+ e,n = key
modname = 'weatbag.tiles.'
if n > 0:
modname += 'n'+str(n)
@@ -42,9 +42,9 @@ class World:
modname += 's'+str(abs(n))
if e > 0:
- modname += 'e'+str(n)
- elif n < 0:
- modname += 'w'+str(abs(n))
+ modname += 'e'+str(e)
+ elif e < 0:
+ modname += 'w'+str(abs(e))
try:
mod = import_module(modname)
@@ -60,23 +60,26 @@ def main():
player = Player(name)
world = World()
tile = world[0,0]
+ tile.describe()
while True:
- tile.describe()
- while True:
- do = action.get_action()
- if action.is_move(do):
- # check if we can leave tile
- if not getattr(tile, 'leave', lambda p,d: True)(player, do[1]):
- continue
- # move
- n,e = player.position
- dn, de = action.process_move(do[1])
- new_posn = n+dn, e+de
- try:
- tile = world[new_posn]
- except KeyError:
- print("The undergrowth in that direction is impassable. "
- "You turn back.")
+ do = action.get_action()
+ if action.is_move(do):
+ direction = do[1][0].lower()
+ # check if we can leave tile
+ if not getattr(tile, 'leave', lambda p,d: True)(player, direction):
+ continue
+ # move
+ e,n = player.position
+ de, dn = action.move_coords[direction]
+ new_posn = e+de, n+dn
+ try:
+ tile = world[new_posn]
+ except KeyError:
+ print("The undergrowth in that direction is impassable. "
+ "You turn back.")
else:
- action.handle_action(tile, player, do)
+ player.position = new_posn
+ tile.describe()
+ else:
+ action.handle_action(tile, player, do)
diff --git a/weatbag/action.py b/weatbag/action.py
index 159e9a0..9ef0f47 100644
--- a/weatbag/action.py
+++ b/weatbag/action.py
@@ -12,13 +12,7 @@ def get_action():
action = input('> ').lower().split()
for prep in words.prepositions.intersection(action):
action.remove(prep)
-
-
- # Look around
- return look_around
-
- return (move, action[1][0])
return action
move_directions = {'n','e','s','w','north','east','south','west'}
@@ -36,7 +30,7 @@ def handle_action(tile, player, do):
elif len(do) == 2 and (do[0] in words.look) and (do[1] in words.inventory):
# Look at bag
- for item, n in inventory.most_common():
+ for item, n in player.inventory.most_common():
if n < 1:
break
print(item, '(%d)' % n)
@@ -44,14 +38,9 @@ def handle_action(tile, player, do):
else:
tile.action(player, do)
-def process_move(direction):
- direction = direction[0].lower()
- if direction == 'n':
- return (0, 1)
- if direction == 's':
- return (0, -1)
- if direction == 'w':
- return (-1, 0)
- if direction == 'e':
- return (1, 0)
- return (0, 0)
+move_coords = {
+ 'n': (0, 1),
+ 's': (0, -1),
+ 'w': (-1, 0),
+ 'e': (1, 0)
+}
diff --git a/weatbag/tiles/centre.py b/weatbag/tiles/centre.py
index 7ab4d54..4aa9a30 100644
--- a/weatbag/tiles/centre.py
+++ b/weatbag/tiles/centre.py
@@ -5,9 +5,8 @@ class Tile:
self.contents = {'rope': 1}
def describe(self):
- print("You are in a sizeable clearing in the forest. At your feet, you see "
- "a mysterious trap door, with three golden keyholes. Paths lead off "
- "in four directions, which your unerring sense of direction tells you "
+ print("You are in a sizeable clearing in the forest. Paths lead off in"
+ "four directions, which your unerring sense of direction tells you "
"correspond to the four compass points.")
if self.contents.get('rope'):
print("A short length of rope is lying on the floor.")