summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Armstrong <jeff@approximatrix.com>2013-07-27 14:42:40 -0400
committerJeff Armstrong <jeff@approximatrix.com>2013-07-27 14:42:40 -0400
commit0e7c76d6daee9c182a5d01c0227b77dcc36a915c (patch)
tree01ee42ad62090a92185cfe2213e5eab3c41de89e /src
parentf24f3866b5cc5ccf0eaf32489892e14f6d94f899 (diff)
downloadpyohio2013-0e7c76d6daee9c182a5d01c0227b77dcc36a915c.tar.gz
pyohio2013-0e7c76d6daee9c182a5d01c0227b77dcc36a915c.zip
done
Diffstat (limited to 'src')
-rw-r--r--src/game.py17
-rw-r--r--src/room.py6
2 files changed, 19 insertions, 4 deletions
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():