def post(self,gamePassCode): try: gameFound = get_game_by_gamepasscode(gamePassCode) if gameFound is None: raise ResourceNotFoundException(message="Game Not Found") game = update_game_schema().load(request.get_json()) if game.gamePassCode != gameFound.gamePassCode: raise FieldValidationException(message="GamePassCode in request body doesn't match url") elif game.gameStatus == Enum.GameStatus.WaitingToStart: raise FieldValidationException(message="Game cannot be reset to Waiting To Start.") elif gameFound.gameStatus == Enum.GameStatus.Completed: raise FieldValidationException(message="Game is complete.No longer can be updated.") if gameFound.gameStatus == Enum.GameStatus.WaitingToStart and game.gameStatus == Enum.GameStatus.InProgress: try: cards = get_cards() players = get_players_by_gameid(gameFound.gameId) if not is_game_allowed_to_start(gameFound): raise FieldValidationException(message="Not enough players to start the game") create_game_cards(gameFound,players,cards) create_game_player_moves(gameFound) except ValidationError as e: raise ResourceValidationException(e) gameFound = update_game(game) result = GameSchema().dump(gameFound) return jsonify(result) except ValidationError as e: raise ResourceValidationException(e)
def post(self, gamePassCode, playerId): try: game_action_tracker = create_game_action_tracker().load( request.get_json()) game = get_game_by_gamepasscode(gamePassCode) if game is None: raise ResourceNotFoundException(message="Game Not Found") current_player_move = get_game_player_moves(game.gameId) if current_player_move is None: raise ResourceNotFoundException( message="No Current Moves found") if current_player_move.playerId != playerId or game_action_tracker.playerId != playerId: raise FieldValidationException( message="Requested player is unable to start an action.") elif current_player_move.gameActionTrackerId is not None: raise FieldValidationException( message= "Unable to start a new action while an action is in progress." ) create_game_action_tracker(game_action_tracker) result = GameActionTrackerSchema().dump(game_action_tracker) current_player_move.gameActionTrackerId = result.gameActionTrackerId update_game_player_moves(current_player_move) return jsonify(result) except ValidationError as e: raise ResourceValidationException(e)
def post(self,gamePassCode,playerId): try: updated_player_move = update_player_moves().load(request.get_json()) game = get_game_by_gamepasscode(gamePassCode) if game is None: raise ResourceNotFoundException(message="Game Not Found") current_player_move = get_game_player_moves(game.gameId) if current_player_move is None: raise FieldValidationException(message="No Current Moves found") if not is_player_moves_status_valid(current_player_move,updated_player_move): raise FieldValidationException(message="Invalid Game Status") if not (is_player_valid(current_player_move,playerId) and is_player_valid(updated_player_move,playerId)): raise FieldValidationException(message="Player not allowed to update") if not is_game_action_tracker_valid(current_player_move): raise FieldValidationException(message="Cannot progress without performing an action.") updated_player_move.totalGameMoveCount = current_player_move.totalGameMoveCount updated_player_move.gameActionTrackerId = current_player_move.gameActionTrackerId updated_player_move.gameId = current_player_move.gameId if (updated_player_move.gameMoveStatus == GameMoveStatus.WaitingForPlayerToBeginMove and current_player_move.numberOfMovesPlayed == MAX_NUMBER_OF_MOVES) or updated_player_move.gameMoveStatus == GameMoveStatus.SkipYourTurn: currentPlayerGameOrder = get_player_game_order(game.players,current_player_move.currentPlayerId) updated_player_move.currentPlayerId = get_next_player_id(game.players,1) if len(game.players) == currentPlayerGameOrder else get_next_player_id(game.players,currentPlayerGameOrder+1) updated_player_move.numberOfRounds +=1 updated_player_move.numberOfMovesPlayed = 1 if current_player_move.numberOfMovesPlayed == MAX_NUMBER_OF_MOVES else (current_player_move.numberOfMovesPlayed + 1) gamePlayerMove = update_game_player_moves(updated_player_move) result = GamePlayerMovesSchema().dump(gamePlayerMove) return jsonify(result) except ValidationError as e: raise ResourceValidationException(e)
def post(self, gamePassCode): try: #Get game and all current players that are part of the game game = get_game_by_gamepasscode(gamePassCode) if game is None: raise ResourceNotFoundException(message="Game Not Found") if not is_player_allowed_to_join(game): raise FieldValidationException( message="No more players can join the game") #create the player player = register_player_schema().load(request.get_json()) player.gameId = game.gameId player.gamePassCode = game.gamePassCode player.playerPassCode = generate_password_hash( player.playerPassCode) #evaluate their order based on other players' order player.playerGameOrder = 1 if len( game.players) == 0 else max(p.playerGameOrder for p in game.players) + 1 #check if user name exists if len([ x for x in game.players if x.playerName.lower() == player.playerName.lower() ]) > 0: raise FieldValidationException( message="Player Name already exists") add_player(player) player_result = PlayerSchema().dump(player) session["gameId"] = game.gameId session["playerId"] = player_result["playerId"] result = create_tokens(player_result) return result, 200 except ValidationError as e: raise ResourceValidationException(e)
def get(self): gameId = session.get("gameId") playerId = session.get("playerId") if gameId is None or playerId is None: raise FieldValidationException(message="No Session exists.") session.clear() response = make_response("Logged Out!", 200) response.delete_cookie(app.config["SESSION_COOKIE_NAME"]) return response
def get(self): gameId = session.get("gameId") playerId = session.get("playerId") if gameId is None or playerId is None: raise FieldValidationException(message="No Session exists.") playerFound = get_player_by_player_id(gameId, playerId) if playerFound is None: raise ResourceNotFoundException(message="Player Not Found") player_result = PlayerSchema().dump(playerFound) result = create_tokens(player_result) return make_response(result, 200)
def post(self, gamePassCode, playerId, gameActionTrackerId): try: game_action_tracker = update_game_action_tracker().load( request.get_json()) game = get_game_by_gamepasscode(gamePassCode) if game is None: raise ResourceNotFoundException(message="Game Not Found") current_player_move = get_game_player_moves(game.gameId) if current_player_move is None: raise ResourceNotFoundException( message="No Current Moves found") if current_player_move.playerId != playerId: raise FieldValidationException( message="Requested player is unable to start an action.") except ValidationError as e: raise ResourceValidationException(e)
def is_pre_check_condition_valid(player_cards_on_hand, game_cards_in_play, possible_play_action): pre_check_conditions = { (Enum.CardTypes.Rent, None, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_rent_playable, (Enum.CardTypes.Action, Enum.ActionTypes.Hotel, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsPlayedOnPropertyPile): is_house_or_hotel_playable, (Enum.CardTypes.Action, Enum.ActionTypes.House, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsPlayedOnPropertyPile): is_house_or_hotel_playable, (Enum.CardTypes.Action, Enum.ActionTypes.DoubleTheRent, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_double_the_rent_playable, (Enum.CardTypes.Action, Enum.ActionTypes.ItsMyBirthday, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_its_my_birthday_playable, (Enum.CardTypes.Action, Enum.ActionTypes.DebtCollector, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_debt_collector_playable, (Enum.CardTypes.Action, Enum.ActionTypes.JustSayNo, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_just_say_no_playable, (Enum.CardTypes.Action, Enum.ActionTypes.SlyDeal, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_sly_deal_playable, (Enum.CardTypes.Action, Enum.ActionTypes.ForcedDeal, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_forced_deal_playable, (Enum.CardTypes.Action, Enum.ActionTypes.DealBreaker, Enum.GameCardLocationStatus.IsOnHand, Enum.GameCardLocationStatus.IsInPlay): is_deal_breaker_playable, (Enum.CardTypes.Properties, None, Enum.GameCardLocationStatus.IsPlayedOnPropertyPile, Enum.GameCardLocationStatus.IsPlayedOnPropertyPile): is_rotate_or_move_property_available, } try: return pre_check_conditions[( possible_play_action.cardType, possible_play_action.actionType, possible_play_action.currentGameCardLocation, possible_play_action.expectedGameCardLocation)]( player_cards_on_hand, game_cards_in_play, possible_play_action) except KeyError: raise FieldValidationException( message= "Pre Check Condition not met. One or more of the specified conditions are not configured correctly." )