def _init_db_(self, session): Control._init_db_(self, session) game = model.Game(name="foo") game.set_properties({"width":100,"height":100}) fort = model.Feature(name="fort") fort.set_properties({'label':'bar'}) f1 = model.GameFeature(game=game, feature=fort) f1.set_properties({"label":'knox'}) session.add_all([game]) session.commit()
def setUp(self): self.control = Control() self.control.drop_all_and_create()
class Test(unittest.TestCase): def setUp(self): self.control = Control() self.control.drop_all_and_create() def tearDown(self): self.control._dispose_() def testMap(self): with self.control.db_session as session: admin = session.query(model.User).get(1) game = model.Game(name="NewWorld",owner=admin) game.set_properties({"width":100,"height":100}) game.players.append(admin) brt = model.Feature(name="brt", url="image:/assets/brt16x16.png") tree = model.Feature(name="tree", url="sprite:/assets/16x16_forest_2.gif:0:0") session.add_all([game,tree]) game.add_feature(tree,{"loc":(0,0)}) game.add_feature(tree,{"loc":(0,16)}) unit1 = game.add_feature(brt,{"loc":(50,50)},admin) session.commit() self.control.start_game(1) self.control.change_feature(1, unit1.id, "loc", (51,51)) print json.dumps(self.control.games[0],indent=4) self.control.end_turn(1) print json.dumps(self.control.games[0],indent=4) try: self.control.start_game(1) raise Exception("Should fail") except GameAlreadyRunning: pass self.control.end_game(1)
def __init__(self, *args, **kwargs): tornado.web.Application.__init__(self, *args, **kwargs) Control.__init__(self) self.clients = []
def end_game(self, gameId): game = Control.start_game(self, gameId) players = game.get("players") self.broadcast("game_ended", {"id": gameId}, players)