def test_scoreUp(): model = GameModel() assert model._base.score == 0 model.scoreUp() assert model._base.score == 1
def test_spawnEnemy(arcadeFactory): model = GameModel() assert model is not None model._factory = arcadeFactory model.spawnEnemy() assert arcadeFactory.createEnemy.call_count == 1
def test_init(arcadeFactory): model = GameModel() assert model is not None model._factory = arcadeFactory model.initGame() assert model._cannon is not None assert arcadeFactory.createEnemy.call_count == 1
def __init__(self): self.app = QApplication(sys.argv) self.state = State() self.gameModel = GameModel() self.controller = Controller(self.gameModel) self.view = GameView(self.controller, self.gameModel) self.gameModel.registerObserver(self.view) self.gameModel.setFactory() self.gameModel.initGame() sys.exit(self.app.exec_())
def put(self): claims = get_jwt_claims() if claims["admin"]: data = game_parser.parse_args() newgame = GameModel(title=data["title"], description=data["description"], riddles=int(data["riddles"])) newgame.save_to_db() return GameModel.serialize([newgame]) else: return { "message": "Admin privileges are required to perform this action" }
def start_game_db(Session): session = Session() players = list() players.append( PlayerModel(nickname='nwhite', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite2', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite3', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite4', email='*****@*****.**', role=4)) numberOfTeams = 2 minRequiredPlayers = 2 maxPlayersPerTeam = 2 game = GameModel(name='game1', initiator=players[0], numberOfTeams=numberOfTeams, minRequiredPlayers=minRequiredPlayers, maxPlayersPerTeam=maxPlayersPerTeam) for index in range(50): print("Putting card.") forbidden = "{'word1', 'word2', 'word3', 'word4'}" card = CardModel("word_" + str(index + 1), forbidden, "Book", "345") session.add(card) session.add(game) session.commit() for i in range(numberOfTeams): teamName = 'team' + str(i) team = TeamModel(teamName) if (i == 0): team.addPlayer(players[0]) team.addPlayer(players[1]) else: team.addPlayer(players[2]) team.addPlayer(players[3]) game.addTeam(team) game.gameState = GAME_READY session.commit() session.close()
def gamesUpdate(): if request.method == 'GET': return render_template('games_update.html') if request.method == 'POST': gametitle = request.form['title'] game = GameModel.query.filter_by(title=gametitle).first() if game: return render_template('games_search.html', game=game) if request.method == 'POST': if request.form['title']: title = request.form['title'] if request.form['platform']: platform = request.form['platform'] if request.form['score']: score = request.form['score'] if request.form['genre']: genre = request.form['genre'] if request.form['editors_choice']: editors_choice = request.form['editors_choice'] new_game = GameModel(title=title, platform=platform, score=score, genre=genre, editors_choice=editors_choice) db.session.add(new_game) db.session.commit() return redirect('/games') return f"Game with title ={gametitle} Doesn't exist"
def test5AddUsedCard(self): game = GameModel.getGameById(1, self.session) card = CardModel.findCardById(self.session, 2) game.addUsedCard(card) self.session.flush() self.session.commit() self.assertTrue(card in game.usedCards) unusedCards = game.getUnusedCards() self.assertEqual(len(unusedCards), 49)
def test9LoadCard(self): game = GameModel.getGameById(1, self.session) round = game.getCurrentRound() self.session.commit() turn = round.getCurrentTurn() cardData = turn.loadCard() print("buzzword: " + cardData['card']['buzzword']) self.session.commit() self.session.close()
def create_game(): data = request.get_json() new_game_model = GameModel(id=random_eight_character_id(), home_team=data['home_team'], away_team=data['away_team'], game_status='pending') db.session.add(new_game_model) db.session.commit() # return game_sim(data['home_team'], data['away_team'])' result = q.enqueue(game_sim, new_game_model.id) print(result) return { 'game_id': new_game_model.id }
def test8AddGameChanger(self): game = GameModel.getGameById(1, self.session) round = game.getCurrentRound() self.session.commit() turn = round.getCurrentTurn() turn.setGameChanger() print("Changer Number is {}".format(turn.gameChangerNumber)) turn.updatePlayerRoles( ) # roles have to be updated if the all-guessers game changer is selected self.session.commit() self.session.close()
def start_game2_db(Session): session = Session() players = list() players.append( PlayerModel(nickname='nwhite', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite2', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite3', email='*****@*****.**', role=4)) players.append( PlayerModel(nickname='nwhite4', email='*****@*****.**', role=4)) numberOfTeams = 2 minRequiredPlayers = 2 maxPlayersPerTeam = 2 game = GameModel(name='game1', initiator=players[0], numberOfTeams=numberOfTeams, minRequiredPlayers=minRequiredPlayers, maxPlayersPerTeam=maxPlayersPerTeam) session.add(game) session.commit() for i in range(numberOfTeams): teamName = 'team' + str(i) team = TeamModel(teamName) if (i == 0): team.addPlayer(players[0]) team.addPlayer(players[1]) else: team.addPlayer(players[2]) team.addPlayer(players[3]) game.addTeam(team) game.gameState = GAME_READY session.commit() session.close()
def test_call_collision(arcadeFactory, missile, basicEnemy): model = GameModel() model._factory = arcadeFactory model._birds = [missile] model._enemies = [basicEnemy] model.tickUpdate() assert basicEnemy.colision.call_count == 1
def post(self, game_id): import datetime as dt current_user = get_jwt_identity() current_progress = ScoreboardEntryModel.filter_by_user_and_game( current_user, game_id) current_game = GameModel.find_by_id(game_id) if current_progress.current_riddle + 1 > current_game.riddles: current_progress.finished = True current_progress.time_end = dt.datetime.now() else: current_progress.current_riddle = ScoreboardEntryModel.current_riddle + 1 db.session.commit() return ScoreboardEntryModel.serialize([current_progress])
def test7CreateTurn(self): game = GameModel.getGameById(1, self.session) turn = game.createTurn() self.session.commit() obervers = turn.getObservers() guessers = turn.getGuessers() moderator = turn.getModerator() teller = turn.getTeller() teamOnDeck = turn.team print("On deck: " + teamOnDeck.name) print("Moderator: " + moderator.nickname) print("Teller: " + teller.nickname) self.session.close()
def test_command(command): model = GameModel() model.acceptCommand(command) assert len(model._commands) == 1 model.tickUpdate() assert command.execute.call_count == 1
def test3JoinTeam(self): player1 = PlayerModel.findPlayerById(self.session, 2) team1 = TeamModel.getTeamById(self.session, 1) cGame = GameModel.getGameById(1, self.session) player1.team = team1 for i in range(1, 8): team = TeamModel.getTeamById(self.session, i) player2 = PlayerModel.findPlayerById(self.session, 2 * i) player3 = PlayerModel.findPlayerById(self.session, 2 * i + 1) player2.team = team player3.team = team i = i + 1 self.session.flush() self.session.commit() self.assertTrue(player1 in team1.players) self.assertTrue(player1.team == team1)
def gamesAdd(): if request.method == 'GET': return render_template('games_add.html') if request.method == 'POST': title = request.form['title'] platform = request.form['platform'] score = request.form['score'] genre = request.form['genre'] editors_choice = request.form['editors_choice'] new_game = GameModel(title=title, platform=platform, score=score, genre=genre, editors_choice=editors_choice) db.session.add(new_game) db.session.commit() return redirect('/games')
def get(self): import datetime as dt out_entries = [] scoreboard = ScoreboardEntryModel.get_all_entries() for sbentry in scoreboard: user = UserModel.find_by_id(sbentry.user_id) game = GameModel.find_by_id(sbentry.game_id) elapsed_seconds = (sbentry.time_end - sbentry.time_begin).total_seconds() \ if sbentry.time_end else (dt.datetime.now() - sbentry.time_begin).total_seconds() entry = { "username": user.username, "game": game.title, "current_riddle": sbentry.current_riddle, "finished": sbentry.finished, "time_begin": int(sbentry.time_begin.timestamp() * 1000), "elapsed_seconds": elapsed_seconds } out_entries.append(entry) return {"entries": out_entries}
def get(self): return GameModel.return_all()
def test_game(): a = GameModel.find_by_game_id(57509) assert a.game_id == 57509
def get(self, game_id): return GameModel.serialize([GameModel.find_by_id(game_id)])
def test2GameCreate(self): print( "\n\n*************Test add new valid game with 7 teams**************\n\n" ) initiator = PlayerModel.findPlayerById(self.session, 1) #print ("Email: " + initiator.email) game = GameModel(initiator, "CS699", 60) team1 = TeamModel("Team 1") team2 = TeamModel("Team 2") team3 = TeamModel("Team 3") teams = [team1, team2, team3] initiator.team = team1 self.session.flush() game.teams = teams self.session.add(game) self.session.commit() self.assertEqual(GameModel.numberOfRows(self.session), 1) self.assertEqual(GameModel.getGameById(1, self.session), game) cGame = GameModel.getGameById(1, self.session) self.assertEqual(cGame.teams, teams) self.assertEqual(team1.gameId, 1) print( "\n\n*************Test add invalid gamename **************************\n\n" ) gameData = { "maxPlayersPerTeam": 2, "turnDuration": 30, "pointsToWin": 30, "numberOfTeams": 2, "skipPenaltyAfter": 3, "gameChangers": True, "name": "", "initiatorTeam": { "name": "team1" }, "teamData": [{ "name": "team1" }, { "name": "team2" }] } feedback = GameModel.isValidGame(self.session, gameData) self.assertFalse(feedback["valid"]) self.assertEqual(feedback["message"], 'game name must be between 2 and 255 characters') print( "\n\n*************Test add invalid turnDuration **************************\n\n" ) gameData = { "maxPlayersPerTeam": 2, "turnDuration": 0, "pointsToWin": 30, "numberOfTeams": 2, "skipPenaltyAfter": 3, "gameChangers": True, "name": "game123", "initiatorTeam": { "name": "team1" }, "teamData": [{ "name": "team1" }, { "name": "team2" }] } feedback = GameModel.isValidGame(self.session, gameData) self.assertFalse(feedback["valid"]) self.assertEqual(feedback["message"], "turn duration must be between 30 and 120 inclusive") print( "\n\n*************Test add invalid teams *****************************\n\n" ) gameData = { "maxPlayersPerTeam": 2, "turnDuration": 30, "pointsToWin": 30, "numberOfTeams": 0, "skipPenaltyAfter": 3, "gameChangers": True, "name": "game123", "initiatorTeam": { "name": "team1" }, "teamData": [] } feedback = GameModel.isValidGame(self.session, gameData) self.assertFalse(feedback["valid"]) self.assertEqual(feedback["message"], "number of teams must be between 2 and 5 inclusive") print( "\n\n*************Test add invalid players in one team *****************************\n\n" ) gameData = { "maxPlayersPerTeam": 10, "turnDuration": 30, "pointsToWin": 30, "numberOfTeams": 2, "skipPenaltyAfter": 3, "gameChangers": True, "name": "game123", "initiatorTeam": { "name": "team1" }, "teamData": [{ "name": "team1" }, { "name": "team2" }] } feedback = GameModel.isValidGame(self.session, gameData) self.assertFalse(feedback["valid"]) self.assertEqual( feedback["message"], "number of players in a team must be between 2 and 5 inclusive") print( "\n\n*************Test add invalid points to win *****************************\n\n" ) gameData = { "maxPlayersPerTeam": 2, "turnDuration": 30, "pointsToWin": 1, "numberOfTeams": 2, "skipPenaltyAfter": 3, "gameChangers": True, "name": "game123", "initiatorTeam": { "name": "team1" }, "teamData": [{ "name": "team1" }, { "name": "team2" }] } feedback = GameModel.isValidGame(self.session, gameData) self.assertFalse(feedback["valid"]) self.assertEqual(feedback["message"], "points to win must be between 10 and 60 inclusive")
def post(self): new_game = GameModel() uid = self._repository.insert(new_game) return {'uid': uid, 'game': new_game.to_dict()}, HTTPStatus.CREATED
def calculate_score_from_post(request): game1 = GameModel() game2 = GameModel() game3 = GameModel() if "game1" in request.POST.keys(): winners = [request.POST['game1'], request.POST['game2'], request.POST['game3']] if winners[0] == "player1": game1.player1 = 5 game1.player2 = 0 else: game1.player2 = 5 game1.player1 = 0 if winners[1] == "player1": game2.player1 = 5 game2.player2 = 0 else: game2.player2 = 5 game2.player1 = 0 if winners[2] == "player1": game3.player1 = 5 game3.player2 = 0 else: game3.player2 = 5 game3.player1 = 0 else: game1.player1 = int(request.POST['p1g1']) game1.player2 = int(request.POST['p2g1']) game2.player1 = int(request.POST['p1g2']) game2.player2 = int(request.POST['p2g2']) game3.player1 = int(request.POST['p1g3']) game3.player2 = int(request.POST['p2g3']) return [game1, game2, game3]