示例#1
0
    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 get(self, gamePassCode, playerId):
     try:
         gameFound = get_game_by_gamepasscode(gamePassCode)
         if gameFound is None:
             raise ResourceNotFoundException(message="Game Not Found")
         playerCards = get_game_cards_on_hand(gameFound.gameId, playerId)
         result = GameCardSchema(many=True).dump(playerCards)
         return jsonify(result)
     except ValidationError as e:
         raise ResourceValidationException(e)
 def get(self, gamePassCode):
     try:
         game = get_game_by_gamepasscode(gamePassCode)
         if game is None:
             raise ResourceNotFoundException(message="Game Not Found")
         gameCards = get_game_cards_in_play(game.gameId)
         result = GameCardSchema(many=True).dump(gameCards)
         return jsonify(result)
     except ValidationError as e:
         raise ResourceValidationException(e)
示例#4
0
    def get(self,gamePassCode,playerId):
        try:
            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")   

            result = GamePlayerMovesSchema().dump(current_player_move)
            return jsonify(result)
        except ValidationError as e:
            raise ResourceValidationException(e)
示例#5
0
    def get(self, gamePassCode, playerId):
        try:
            game = get_game_by_gamepasscode(gamePassCode)
            if game is None:
                raise ResourceNotFoundException(message="Game Not Found")

            game_action_trackers = get_game_action_trackers(game.gameId)

            result = GameActionTrackerSchema(
                many=True).dump(game_action_trackers)
            return jsonify(result)

        except ValidationError as e:
            raise ResourceValidationException(e)
示例#6
0
    def post(self, gamePassCode, playerId):
        try:
            gameFound = get_game_by_gamepasscode(gamePassCode)
            if gameFound is None:
                raise ResourceNotFoundException(message="Game Not Found")

            player_cards_on_hand = get_game_cards_on_hand(
                gameFound.gameId, playerId)
            game_play_actions = get_game_play_actions()
            game_cards_in_play = get_game_cards_in_play(gameFound.gameId)

            pre_move_check_list = get_pre_move_check_list(
                player_cards_on_hand, game_cards_in_play, game_play_actions)
            result = PreMoveCheckSchema(many=True).dump(pre_move_check_list)

            return jsonify(result)
        except ValidationError as e:
            raise ResourceValidationException(e)
示例#7
0
    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)
示例#8
0
    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 post(self, gamePassCode):
        try:
            game = get_game_by_gamepasscode(gamePassCode)
            if game is None:
                raise ResourceNotFoundException(message="Game Not Found")
            player = login_player_schema().load(request.get_json())
            playerFound = get_player_by_player_name(game.gameId,
                                                    player.playerName)
            if playerFound is None:
                raise ResourceNotFoundException(message="Player Not Found")

            if check_password_hash(playerFound.playerPassCode,
                                   player.playerPassCode):
                player_result = PlayerSchema().dump(playerFound)
                result = create_tokens(player_result)
                session["gameId"] = game.gameId
                session["playerId"] = player_result["playerId"]
                return result, 200
            else:
                raise ResourceNotFoundException(message="Player Not Found")

        except ValidationError as e:
            raise ResourceValidationException(e)