Esempio n. 1
0
async def test_game_sim_ends_when_no_more_connections(game: Game, players):
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    join_conn = add_connected_player(game, players.joining)
    game.host = players.hosting

    await game.launch()

    await game.remove_game_connection(host_conn)
    await game.remove_game_connection(join_conn)
    assert game.ended
Esempio n. 2
0
async def test_game_sim_ends_when_no_more_connections(game: Game, players):
    await game.clear_data()
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    join_conn = add_connected_player(game, players.joining)
    game.host = players.hosting

    await game.launch()

    await game.remove_game_connection(host_conn)
    await game.remove_game_connection(join_conn)
    assert game.ended
Esempio n. 3
0
async def test_game_sim_ends_when_connections_ended_sim(game: Game, players):
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    join_conn = add_connected_player(game, players.joining)
    game.host = players.hosting

    await game.launch()

    host_conn.finished_sim = True
    join_conn.finished_sim = True
    await game.check_sim_end()
    assert game.ended
Esempio n. 4
0
async def test_game_sim_ends_when_connections_ended_sim(game: Game, players):
    await game.clear_data()
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    join_conn = add_connected_player(game, players.joining)
    game.host = players.hosting

    await game.launch()

    host_conn.finished_sim = True
    join_conn.finished_sim = True
    await game.check_sim_end()
    assert game.ended
Esempio n. 5
0
async def test_game_launch_freezes_players(game: Game, players):
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    game.host = players.hosting
    add_connected_player(game, players.joining)

    await game.launch()

    assert game.state is GameState.LIVE
    assert game.players == {players.hosting, players.joining}

    await game.remove_game_connection(host_conn)
    assert game.players == {players.hosting, players.joining}
Esempio n. 6
0
async def test_game_launch_freezes_players(game: Game, players):
    await game.clear_data()
    game.state = GameState.LOBBY
    host_conn = add_connected_player(game, players.hosting)
    game.host = players.hosting
    add_connected_player(game, players.joining)

    await game.launch()

    assert game.state == GameState.LIVE
    assert game.players == {players.hosting, players.joining}

    await game.remove_game_connection(host_conn)
    assert game.players == {players.hosting, players.joining}
Esempio n. 7
0
async def test_add_game_connection_twice(game: Game, players,
                                         mock_game_connection):
    """
    When a player disconnects and reconnects to the same game, they should not
    be considered as 'in-lobby' until the new PlayerOptions are received.
    """
    game.state = GameState.LOBBY
    mock_game_connection.player = players.hosting
    mock_game_connection.state = GameConnectionState.CONNECTED_TO_HOST
    # Connect the host
    game.add_game_connection(mock_game_connection)
    game.set_player_option(players.hosting.id, "Team", 1)
    assert game.players == {players.hosting}
    # Join a new player
    join_conn = add_connected_player(game, players.joining)
    assert game.players == {players.hosting, players.joining}
    # Player leaves
    await game.remove_game_connection(join_conn)
    assert game.players == {players.hosting}
    # Player joins again
    game.add_game_connection(join_conn)
    assert game.to_dict()["num_players"] == 1
    assert game.players == {players.hosting}
    game.set_player_option(players.joining.id, "Team", 1)
    assert game.players == {players.hosting, players.joining}
    assert game.to_dict()["num_players"] == 2
Esempio n. 8
0
async def test_game_visible_to_players(game: Game, players):
    game.host = players.hosting
    game.visibility = None  # Ensure that visibility is not checked
    game.state = GameState.LOBBY
    add_connected_player(game, players.joining)
    assert game.is_visible_to_player(players.joining)