From ca7982703591629ff73a8617e72c9496e9e92ab5 Mon Sep 17 00:00:00 2001 From: Jeff Armstrong Date: Wed, 24 Jul 2013 15:26:57 -0400 Subject: Initial skeleton uploaded. --- src/game.py | 8 ++++++++ src/room.py | 25 +++++++++++++++++++++++++ src/todb.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/game.py create mode 100644 src/room.py create mode 100644 src/todb.py (limited to 'src') diff --git a/src/game.py b/src/game.py new file mode 100644 index 0000000..bcaf29c --- /dev/null +++ b/src/game.py @@ -0,0 +1,8 @@ + +class Game(): + def __init__(self): + pass + +if __name__ == "__main__": + g = Game() + diff --git a/src/room.py b/src/room.py new file mode 100644 index 0000000..9aba006 --- /dev/null +++ b/src/room.py @@ -0,0 +1,25 @@ + +class Room(): + def __init__(self, id=0, name="A Room", description="An empty room", neighbors={}): + self.id = id + self.name = name + self.description = description + self.neighbors = neighbors + + def _neighbor(self, direction): + if direction in self.neighbors: + return self.neighbors[direction] + else: + return None + + def north(self): + return self._neighbor('n') + + def south(self): + return self._neighbor('s') + + def east(self): + return self._neighbor('e') + + def west(self): + return self._neighbor('w') diff --git a/src/todb.py b/src/todb.py new file mode 100644 index 0000000..202422e --- /dev/null +++ b/src/todb.py @@ -0,0 +1,31 @@ +import sys +import sqlite3 +import os +import os.path + +def main(dbname): + con = sqlite3.connect(dbname) + + con.execute("CREATE TABLE IF NOT EXISTS rooms(id INTEGER PRIMARY KEY, json TEXT NOT NULL)") + con.commit() + + for filename in os.listdir(): + base, extension = os.path.splitext(filename) + if extension == '.json': + with open(filename, 'r') as f: + json = f.read() + + print("Inserting room {0}".format(int(base))) + + con.execute("INSERT OR REPLACE INTO rooms(id, json) VALUES(?, ?);", + (int(base), json)) + + con.commit() + + con.close() + +if __name__ == "__main__": + if len(sys.argv) != 2: + print('Usage: {0} '.format(sys.argv[0])) + else: + main(sys.argv[1]) \ No newline at end of file -- cgit v1.2.3