summaryrefslogtreecommitdiffstats
path: root/weatbag/__init__.py
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2013-01-07 20:50:07 +0000
committerThomas Kluyver <takowl@gmail.com>2013-01-07 20:50:07 +0000
commit3400844980917bb3d59da322a3e33f55f81afe12 (patch)
tree898ff62681401e2c0a4b4a66c11f626d7b784a25 /weatbag/__init__.py
parent87e6fd0a9d0ec7869dc9e6e404638cc1e090e3a7 (diff)
Add a simple way to test tiles
Diffstat (limited to 'weatbag/__init__.py')
-rw-r--r--weatbag/__init__.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/weatbag/__init__.py b/weatbag/__init__.py
index 7c39d21..72912c6 100644
--- a/weatbag/__init__.py
+++ b/weatbag/__init__.py
@@ -1,5 +1,6 @@
from collections import Counter
from importlib import import_module
+import re
from . import action
@@ -34,18 +35,7 @@ class World:
try:
return self.tiles[key]
except KeyError:
- e,n = key
- modname = 'weatbag.tiles.'
- if n > 0:
- modname += 'n'+str(n)
- elif n < 0:
- modname += 's'+str(abs(n))
-
- if e > 0:
- modname += 'e'+str(e)
- elif e < 0:
- modname += 'w'+str(abs(e))
-
+ modname = 'weatbag.tiles.' + coords_to_name(*key)
try:
mod = import_module(modname)
except ImportError:
@@ -55,11 +45,47 @@ class World:
self.tiles[key] = tile
return tile
+def coords_to_name(e, n):
+ modname = ''
+ if n > 0:
+ modname += 'n'+str(n)
+ elif n < 0:
+ modname += 's'+str(abs(n))
+
+ if e > 0:
+ modname += 'e'+str(e)
+ elif e < 0:
+ modname += 'w'+str(abs(e))
+
+ return modname
+
+_tile_name_re = re.compile(r'([ns]\d+)?([ew]\d+)?')
+def name_to_coords(tilename):
+ ns, es = _tile_name_re.match(tilename).groups()
+ if ns is None:
+ n = 0
+ elif ns[0] == 'n':
+ n = int(ns[1:])
+ else:
+ n = -int(ns[1:])
+
+ if es is None:
+ e = 0
+ elif es[0] == 'e':
+ e = int(es[1:])
+ else:
+ e = -int(es[1:])
+
+ return e, n
+
def main():
name = input("What is your name? ")
player = Player(name)
+ interact(player)
+
+def interact(player):
world = World()
- tile = world[0,0]
+ tile = world[player.position]
tile.describe()
while True:
do = action.get_action()