From 0e7c76d6daee9c182a5d01c0227b77dcc36a915c Mon Sep 17 00:00:00 2001 From: Jeff Armstrong Date: Sat, 27 Jul 2013 14:42:40 -0400 Subject: done --- src/game.py | 17 +++++++++++++++-- src/room.py | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/game.py b/src/game.py index 0a587e4..800d3ac 100644 --- a/src/game.py +++ b/src/game.py @@ -1,12 +1,17 @@ import cmd from room import get_room import textwrap +import shutil +import tempfile class Game(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) - self.loc = get_room(1) + self.dbfile = tempfile.mktemp() + shutil.copyfile("game.db", self.dbfile) + + self.loc = get_room(1, self.dbfile) self.look() def move(self, dir): @@ -14,8 +19,11 @@ class Game(cmd.Cmd): if newroom is None: print("you can't go that way") else: - self.loc = get_room(newroom) + self.loc = get_room(newroom, self.dbfile) self.look() + + if newroom==13: + exit() def look(self): print(self.loc.name) @@ -52,6 +60,11 @@ class Game(cmd.Cmd): """Leaves the game""" print("Thank you for playing") return True + + def do_save(self, args): + """Saves the game""" + shutil.copyfile(self.dbfile, args) + print("The game was saved to {0}".format(args)) if __name__ == "__main__": g = Game() diff --git a/src/room.py b/src/room.py index 1bc3747..ca5430a 100644 --- a/src/room.py +++ b/src/room.py @@ -1,10 +1,10 @@ import json import sqlite3 -def get_room(id): +def get_room(id, dbfile): ret = None - con = sqlite3.connect("game.db") + con = sqlite3.connect(dbfile) for row in con.execute("select json from rooms where id=?",(id,)): @@ -14,6 +14,8 @@ def get_room(id): ret = Room(**d) break + con.close() + return ret class Room(): -- cgit v1.2.3