def setUp(self): self.database = 'test.sqlite' if os.path.exists(self.database): os.unlink(self.database) self.service = CardstoriesService({'db': self.database}) self.service.startService() self.db = sqlite3.connect(self.database) self.game = CardstoriesGame(self.service)
def load(self, c): c.execute( "SELECT id, sentence FROM games WHERE state != 'complete' AND state != 'canceled'" ) for (id, sentence) in c.fetchall(): game = CardstoriesGame(self, id) game.load(c) # Notify listeners of the game, but use the 'load' notification to signal # that the game is being loaded, not created # Note that the db is not accessible during that stage self.game_init(game, sentence, init_type='load')
def create(self, args): self.required(args, 'create', 'owner_id') owner_id = int(args['owner_id'][0]) # Keep track of consecutive games if 'previous_game_id' in args: previous_game_id = args['previous_game_id'][0] else: previous_game_id = None game = CardstoriesGame(self) game_id = yield game.create(owner_id) yield self.game_init(game, '', previous_game_id=previous_game_id) defer.returnValue({'game_id': game_id})
def game(self, args): self.required(args, 'game') game_id = self.required_game_id(args) if args.has_key('player_id'): player_id = int(args['player_id'][0]) else: player_id = None if self.games.has_key(game_id): return self.games[game_id].game(player_id) else: game = CardstoriesGame(self, game_id) d = game.game(player_id) def destroy(game_info): game.destroy() return game_info d.addCallback(destroy) return d