• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python game.Game类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中server.games.game.Game的典型用法代码示例。如果您正苦于以下问题:Python Game类的具体用法?Python Game怎么用?Python Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Game类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_remove_game_connection

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
开发者ID:FAForever,项目名称:server,代码行数:7,代码来源:test_game.py


示例2: test_initialized_game_not_allowed_to_end

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
开发者ID:FAForever,项目名称:server,代码行数:7,代码来源:test_game.py


示例3: test_add_game_connection_throws_if_not_lobby_state

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
开发者ID:FAForever,项目名称:server,代码行数:8,代码来源:test_game.py


示例4: test_add_game_connection_throws_if_not_connected_to_host

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
开发者ID:FAForever,项目名称:server,代码行数:8,代码来源:test_game.py


示例5: test_game_end_when_no_more_connections

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()
开发者ID:FAForever,项目名称:server,代码行数:9,代码来源:test_game.py


示例6: test_game_is_invalid_due_to_desyncs

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
开发者ID:FAForever,项目名称:server,代码行数:11,代码来源:test_game.py


示例7: test_game_ends_in_mutually_agreed_draw

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
开发者ID:FAForever,项目名称:server,代码行数:12,代码来源:test_game.py


示例8: test_game_sim_ends_when_no_more_connections

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
开发者ID:FAForever,项目名称:server,代码行数:12,代码来源:test_game.py


示例9: test_game_not_ends_in_unilatery_agreed_draw

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
开发者ID:FAForever,项目名称:server,代码行数:12,代码来源:test_game.py


示例10: test_game_sim_ends_when_connections_ended_sim

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
开发者ID:FAForever,项目名称:server,代码行数:13,代码来源:test_game.py


示例11: test_game_launch_freezes_players

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}
开发者ID:FAForever,项目名称:server,代码行数:14,代码来源:test_game.py


示例12: test_compute_rating_computes_ladder_ratings

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]
开发者ID:FAForever,项目名称:server,代码行数:15,代码来源:test_game.py


示例13: add_connected_players

def add_connected_players(game: Game, players):
    """
    Utility to add players with army and StartSpot indexed by a list
    """
    for army, player in enumerate(players):
        add_connected_player(game, player)
        game.set_player_option(player.id, 'Army', army)
        game.set_player_option(player.id, 'StartSpot', army)
        game.set_player_option(player.id, 'Team', army)
        game.set_player_option(player.id, 'Faction', 0)
        game.set_player_option(player.id, 'Color', 0)
    game.host = players[0]
开发者ID:yorick-ne,项目名称:server,代码行数:12,代码来源:test_game.py


示例14: test_report_army_stats_sends_stats_for_defeated_player

async def test_report_army_stats_sends_stats_for_defeated_player(game: Game):
    game.id = 43
    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)

    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)
开发者ID:yorick-ne,项目名称:server,代码行数:18,代码来源:test_game.py


示例15: test_validate_game_settings

async def test_validate_game_settings(game: Game):
    settings = [
        ('Victory', Victory.SANDBOX, Victory.DEMORALIZATION, ValidityState.WRONG_VICTORY_CONDITION),
        ('FogOfWar', 'none', 'explored', ValidityState.NO_FOG_OF_WAR),
        ('CheatsEnabled', 'true', 'false', ValidityState.CHEATS_ENABLED),
        ('PrebuiltUnits', 'On', 'Off', ValidityState.PREBUILT_ENABLED),
        ('NoRushOption', 20, 'Off', ValidityState.NORUSH_ENABLED),
        ('RestrictedCategories', 1, 0, ValidityState.BAD_UNIT_RESTRICTIONS)
    ]

    for data in settings:
        key, value, default, expected = data
        game.gameOptions[key] = value
        await game.validate_game_settings()
        assert game.validity is expected
        game.gameOptions[key] = default

    game.validity = ValidityState.VALID
    await game.validate_game_settings()
    assert game.validity is ValidityState.VALID
开发者ID:FAForever,项目名称:server,代码行数:20,代码来源:test_game.py


示例16: test_report_army_stats_sends_stats_for_defeated_player

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)
开发者ID:FAForever,项目名称:server,代码行数:13,代码来源:test_game.py


示例17: test_clear_slot

async def test_clear_slot(game: Game, mock_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.set_ai_option('rush', 'StartSpot', 3)


    game.clear_slot(0)
    game.clear_slot(3)

    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
    assert 'rush' not in game.AIs
开发者ID:FAForever,项目名称:server,代码行数:18,代码来源:test_game.py


示例18: test_compute_rating_balanced_teamgame

async def test_compute_rating_balanced_teamgame(game: Game, create_player):
    await game.clear_data()

    game.state = GameState.LOBBY
    players = [
        (create_player(**info), result, team) for info, result, team in [
            (dict(login='Paula_Bean', id=1, global_rating=Rating(1500, 250.7)), 0, 1),
            (dict(login='Some_Guy', id=2, global_rating=Rating(1700, 120.1)), 0, 1),
            (dict(login='Some_Other_Guy', id=3, global_rating=Rating(1200, 72.02)), 0, 2),
            (dict(login='That_Person', id=4, global_rating=Rating(1200, 72.02)), 0, 2),
        ]
    ]
    add_connected_players(game, [player for player, _, _ in players])
    for player, _, team in players:
        game.set_player_option(player.id, 'Team', team)
        game.set_player_option(player.id, 'Army', player.id - 1)
    await game.launch()
    for player, result, _ in players:
        await game.add_result(player, player.id - 1, 'score', result)
    result = game.compute_rating()
    for team in result:
        for player, new_rating in team.items():
            assert player in game.players
            assert new_rating != Rating(*player.global_rating)
开发者ID:FAForever,项目名称:server,代码行数:24,代码来源:test_game.py


示例19: test_game_marked_dirty_when_timed_out

async def test_game_marked_dirty_when_timed_out(game: Game):
    game.state = GameState.INITIALIZING
    game.sleep = CoroMock()
    await game.timeout_game()
    assert game.state == GameState.ENDED
    assert game in game.game_service.dirty_games
开发者ID:FAForever,项目名称:server,代码行数:6,代码来源:test_game.py


示例20: add_connected_player

def add_connected_player(game: Game, player):
    game.game_service.player_service[player.id] = player
    gc = game_connection(state=GameConnectionState.CONNECTED_TO_HOST, player=player)
    game.set_player_option(player.id, 'Army', 0)
    game.set_player_option(player.id, 'StartSpot', 0)
    game.set_player_option(player.id, 'Team', 0)
    game.set_player_option(player.id, 'Faction', 0)
    game.set_player_option(player.id, 'Color', 0)
    game.add_game_connection(gc)
    return gc
开发者ID:yorick-ne,项目名称:server,代码行数:10,代码来源:test_game.py



注:本文中的server.games.game.Game类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python manager.get_current_customer_name函数代码示例发布时间:2022-05-27
下一篇:
Python filterpoll.FilterPoll类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap