本文整理汇总了Python中server.games.game.Game.state方法的典型用法代码示例。如果您正苦于以下问题:Python Game.state方法的具体用法?Python Game.state怎么用?Python Game.state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.games.game.Game
的用法示例。
在下文中一共展示了Game.state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_initialized_game_not_allowed_to_end
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_initialized_game_not_allowed_to_end(game: Game):
await game.clear_data()
game.state = GameState.INITIALIZING
game.on_game_end()
assert game.state is GameState.INITIALIZING
示例2: test_remove_game_connection
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_remove_game_connection(game: Game, players, mock_game_connection):
game.state = GameState.LOBBY
mock_game_connection.player = players.hosting
mock_game_connection.state = GameConnectionState.CONNECTED_TO_HOST
game.add_game_connection(mock_game_connection)
await game.remove_game_connection(mock_game_connection)
assert players.hosting not in game.players
示例3: test_add_game_connection_throws_if_not_lobby_state
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
def test_add_game_connection_throws_if_not_lobby_state(game: Game, players, mock_game_connection):
game.state = GameState.INITIALIZING
mock_game_connection.player = players.hosting
mock_game_connection.state = GameConnectionState.CONNECTED_TO_HOST
with pytest.raises(GameError):
game.add_game_connection(mock_game_connection)
assert players.hosting not in game.players
示例4: test_add_game_connection_throws_if_not_connected_to_host
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
def test_add_game_connection_throws_if_not_connected_to_host(game: Game, players, mock_game_connection):
game.state = GameState.LOBBY
mock_game_connection.player = players.hosting
mock_game_connection.state = GameConnectionState.INITIALIZED
with pytest.raises(GameError):
game.add_game_connection(mock_game_connection)
assert players.hosting not in game.players
示例5: test_game_end_when_no_more_connections
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_game_end_when_no_more_connections(game: Game, mock_game_connection):
game.state = GameState.LOBBY
game.on_game_end = CoroMock()
mock_game_connection.state = GameConnectionState.CONNECTED_TO_HOST
game.add_game_connection(mock_game_connection)
await game.remove_game_connection(mock_game_connection)
game.on_game_end.assert_any_call()
示例6: test_game_is_invalid_due_to_desyncs
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_game_is_invalid_due_to_desyncs(game: Game, players):
await game.clear_data()
game.state = GameState.LOBBY
add_connected_players(game, [players.hosting, players.joining])
game.host = players.hosting
await game.launch()
game.desyncs = 30
await game.on_game_end()
assert game.validity is ValidityState.TOO_MANY_DESYNCS
示例7: test_game_not_ends_in_unilatery_agreed_draw
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_game_not_ends_in_unilatery_agreed_draw(game: Game, players):
game.state = GameState.LOBBY
add_players(game, 2)
await game.launch()
game.launched_at = time.time()-60*60
await game.add_result(players.hosting, 0, 'mutual_draw', 0)
await game.add_result(players.joining, 1, 'victory', 10)
await game.on_game_end()
assert game.validity is not ValidityState.MUTUAL_DRAW
示例8: test_game_sim_ends_when_no_more_connections
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
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
示例9: test_game_ends_in_mutually_agreed_draw
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_game_ends_in_mutually_agreed_draw(game: Game):
game.state = GameState.LOBBY
players = add_players(game, 2)
await game.launch()
game.launched_at = time.time()-60*60
await game.add_result(players[0], 0, 'mutual_draw', 0)
await game.add_result(players[1], 1, 'mutual_draw', 0)
await game.on_game_end()
assert game.validity is ValidityState.MUTUAL_DRAW
示例10: test_game_sim_ends_when_connections_ended_sim
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
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
示例11: test_report_army_stats_sends_stats_for_defeated_player
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_report_army_stats_sends_stats_for_defeated_player(game: Game):
game.state = GameState.LOBBY
players = add_players(game, 2)
await game.launch()
await game.add_result(0, 1, 'defeat', -1)
with open("tests/data/game_stats_simple_win.json", "r") as stats_file:
stats = stats_file.read()
await game.report_army_stats(stats)
game._game_stats_service.process_game_stats.assert_called_once_with(players[1], game, stats)
示例12: test_game_launch_freezes_players
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
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}
示例13: test_clear_slot
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_clear_slot(game: Game, game_connection: GameConnection):
game.state = GameState.LOBBY
players = [
Player(id=1, login='Dostya', global_rating=(1500, 500)),
Player(id=2, login='Rhiza', global_rating=(1500, 500))
]
add_connected_players(game, players)
game.clear_slot(0)
assert game.get_player_option(1, 'StartSpot') == -1
assert game.get_player_option(1, 'Team') == -1
assert game.get_player_option(1, 'Army') == -1
assert game.get_player_option(2, 'StartSpot') == 1
示例14: test_compute_rating_computes_ladder_ratings
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_compute_rating_computes_ladder_ratings(game: Game, players):
await game.clear_data()
game.state = GameState.LOBBY
players.hosting.ladder_rating = Rating(1500, 250)
players.joining.ladder_rating = Rating(1500, 250)
add_connected_players(game, [players.hosting, players.joining])
await game.launch()
await game.add_result(players.hosting, 0, 'victory', 1)
await game.add_result(players.joining, 1, 'defeat', 0)
game.set_player_option(players.hosting.id, 'Team', 1)
game.set_player_option(players.joining.id, 'Team', 1)
groups = game.compute_rating(rating='ladder')
assert players.hosting in groups[0]
assert players.joining in groups[1]
示例15: test_players_exclude_observers
# 需要导入模块: from server.games.game import Game [as 别名]
# 或者: from server.games.game.Game import state [as 别名]
async def test_players_exclude_observers(game: Game):
game.state = GameState.LOBBY
players = add_players(game, 2)
obs = Player(id=3, login='Zoidberg', global_rating=(1500, 500))
game.game_service.player_service[obs.id] = obs
gc = mock_game_connection(state=GameConnectionState.CONNECTED_TO_HOST, player=obs)
game.set_player_option(obs.id, 'Army', -1)
game.set_player_option(obs.id, 'StartSpot', -1)
game.set_player_option(obs.id, 'Team', 0)
game.set_player_option(obs.id, 'Faction', 0)
game.set_player_option(obs.id, 'Color', 0)
game.add_game_connection(gc)
await game.launch()
assert game.players == frozenset(players)