def player_interact_roll(game_id: str, player_id: str): """ Given player tried to roll the dice """ try: game = Game(**games.get(where('uuid') == game_id)) game.roll(player_id) except Exception as err: return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def delete_player(game_id, player_id): """ Delete a player from a game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": str(err)}, 404 game.remove_player(player_id) games.update(game.dict(), where('uuid') == game_id) return {}
def player_interact_end_turn(game_id: str, player_id: str): """ Given player ends their turn """ try: game = Game(**games.get(where('uuid') == game_id)) game.advance_turn() except Exception as err: print(err) return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def player_interact_make_choice(game_id: str, player_id: str, choice_idx: int): """ Given player makes a choice from given list """ try: game = Game(**games.get(where('uuid') == game_id)) game.make_choice(player_id, choice_idx) except Exception as err: print(err) return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def start_game(game_id): """ Start game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": err}, 404 status, error = game.start() if status is False: return {"error": error}, 400 games.update(game.dict(), where('uuid') == game_id) return {}
def new_player(game_id, name: str): """ Make a new player in a game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": err}, 404 if len(game.players) >= MAX_PLAYER_COUNT: return {"error": "The game is full"}, 404 player = game.new_player(name) games.update(game.dict(), where('uuid') == game_id) return player.dict()