def test_if_not_last_player_alive(): player1 = Player() player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) assert player_queue.is_last_player_alive(player2) is False
def test_when_last_player_is_alive(): player1 = Player() player1.is_alive = False player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) assert player_queue.is_last_player_alive(player2) is True
def test_get_dead_player(): player1 = Player() player1.is_alive = False player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) assert player_queue.get_dead_players() == [player1]
def test_get_current_player_when_player_order_set(): player1 = Player() player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) player_queue.set_player_order() player_queue.get_current_player() assert player_queue.current_player == player1
def test_generate_player_status_summary(): player1 = Player() player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) player_queue.set_player_order() actual_summary: [] = generate_player_status_summary(player_queue) expected_p1_dictionary = player1.generate_player_status_as_dictionary() expected_p2_dictionary = player2.generate_player_status_as_dictionary() expected_summary: [] = [expected_p1_dictionary, expected_p2_dictionary] assert actual_summary == expected_summary
def test_player_status_summary_to_JSON(): player1 = Player() player2 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) player_queue.set_player_order() actual_summary_json = player_status_summary_to_JSON(player_queue) expected_p1_dictionary = player1.generate_player_status_as_dictionary() expected_p2_dictionary = player2.generate_player_status_as_dictionary() expected_summary_json: [] = json.dumps( [expected_p1_dictionary, expected_p2_dictionary]) assert actual_summary_json == expected_summary_json
def test_generate_player_status_with_cards_summary(): player1 = Player() player1.add_card(EnergyHoarder()) player1.add_card(SolarPowered()) player2 = Player() player2.add_card(EvenBigger()) player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) player_queue.set_player_order() actual_summary: [] = generate_player_status_summary(player_queue) expected_p1_dictionary = player1.generate_player_status_as_dictionary() expected_p2_dictionary = player2.generate_player_status_as_dictionary() expected_summary: [] = [expected_p1_dictionary, expected_p2_dictionary] assert actual_summary == expected_summary
def test_get_all_alive_players_minus_current_player(): player1 = Player() player1.is_alive = False player2 = Player() player3 = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player1) player_queue.add_player_to_game(player2) player_queue.add_player_to_game(player3) player_queue.set_player_order() player_queue.get_current_player() assert player_queue.get_all_alive_players_minus_current_player() == [ player3 ]
def test_adding_player_to_queue(): player = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player) assert player_queue.players == [player]
def test_get_current_player_when_player_order_not_set(): player = Player() player_queue = GamePlayers() player_queue.add_player_to_game(player) assert player_queue.get_next_player() is None
def test_get_current_player_when_no_one_is_alive(): player_queue = GamePlayers() with pytest.raises(Exception) as excinfo: player_queue.get_next_player() assert 'There are no alive players left' == str(excinfo.value)
def test_adding_non_player_to_queue_raise_exception(): player_queue = GamePlayers() with pytest.raises(TypeError): player_queue.add_player_to_game("NON_PLAYER")
def __init__(self): self.players = GamePlayers() self.status = Status.SETUP self.winner = None self.deck_handler = DeckHandler() self.dice_handler = DiceHandler()
class BoardGame: def __init__(self): self.players = GamePlayers() self.status = Status.SETUP self.winner = None self.deck_handler = DeckHandler() self.dice_handler = DiceHandler() def add_player(self, player): self.players.add_player_to_game(player) def start_game(self): self.players.set_player_order() self.players.get_current_player() self.status = Status.ACTIVE def check_if_winner(self, potential_winner): if (potential_winner.victory_points >= constants.VICTORY_POINTS_TO_WIN or self.players.is_last_player_alive(potential_winner)): self.winner = potential_winner self.end_game() return True return False def is_game_active(self): return self.status == Status.ACTIVE def end_game(self): self.status = Status.COMPLETED def start_turn_actions(self, active_player): player_dice_count = constants.DEFAULT_DICE_TO_ROLL player_re_roll_count = constants.DEFAULT_RE_ROLL_COUNT if active_player != self.players.get_current_player(): raise Exception("It is not %s's turn" % (id(active_player))) # TODO, refactor to other method if active_player.has_instance_of_card(Urbavore()): Urbavore.special_effect( active_player, self.players.get_all_alive_players_minus_current_player()) self.dice_handler.roll_initial(player_dice_count, player_re_roll_count) def re_roll(self, indexes_to_re_roll): self.dice_handler.re_roll_dice(indexes_to_re_roll) def post_roll_actions(self, active_player): # TODO, refactor to other method if active_player.has_instance_of_card(EnergyHoarder()): EnergyHoarder().special_effect( active_player, self.players.get_all_alive_players_minus_current_player()) if active_player.has_instance_of_card(SolarPowered()): SolarPowered().special_effect( active_player, self.players.get_all_alive_players_minus_current_player()) if active_player.has_instance_of_card(RootingForTheUnderdog()): RootingForTheUnderdog().special_effect( active_player, self.players.get_all_alive_players_minus_current_player()) self.check_if_winner(active_player) def get_next_player_turn(self): if self.is_game_active(): self.players.get_next_player() return self.players.current_player def yield_tokyo_to_current_player(self, yielding_player): yield_tokyo(yielding_player, self.players.current_player)