diff options
| author | Jeff Armstrong <jeff@approximatrix.com> | 2013-07-27 14:27:20 -0400 |
|---|---|---|
| committer | Jeff Armstrong <jeff@approximatrix.com> | 2013-07-27 14:27:20 -0400 |
| commit | 032a02cb47fe933e423a06c4f79eeddecb5b8e68 (patch) | |
| tree | 6ddadad22a255410ea9d520a3830a3fab19fd9f3 /src/game.py | |
| parent | ca7982703591629ff73a8617e72c9496e9e92ab5 (diff) | |
| download | pyohio2013-032a02cb47fe933e423a06c4f79eeddecb5b8e68.tar.gz pyohio2013-032a02cb47fe933e423a06c4f79eeddecb5b8e68.zip | |
everywhere
Diffstat (limited to 'src/game.py')
| -rw-r--r-- | src/game.py | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/game.py b/src/game.py index bcaf29c..0a587e4 100644 --- a/src/game.py +++ b/src/game.py @@ -1,8 +1,58 @@ +import cmd +from room import get_room +import textwrap -class Game(): +class Game(cmd.Cmd): def __init__(self): - pass + cmd.Cmd.__init__(self) + + self.loc = get_room(1) + self.look() + + def move(self, dir): + newroom = self.loc._neighbor(dir) + if newroom is None: + print("you can't go that way") + else: + self.loc = get_room(newroom) + self.look() + + def look(self): + print(self.loc.name) + print("") + for line in textwrap.wrap(self.loc.description, 72): + print(line) + + def do_up(self, args): + """Go up""" + self.move('up') + + def do_down(self, args): + """Go down""" + self.move('down') + + + def do_n(self, args): + """Go north""" + self.move('n') + + def do_s(self, args): + """Go south""" + self.move('s') + + def do_e(self, args): + """Go east""" + self.move('e') + + def do_w(self, args): + """Go west""" + self.move('w') + + def do_quit(self, args): + """Leaves the game""" + print("Thank you for playing") + return True if __name__ == "__main__": g = Game() - + g.cmdloop() |
