async def test_unfreeze_players(): game = Game() game.alive_players = [Player(0, 128, 128), Player(1, 128, 128)] logic = TickLogicPart(game) await logic.unfreeze_players() assert not game.alive_players[0].is_freeze assert not game.alive_players[1].is_freeze
def test_messages_get_world_data(): game = Game() player = Player(x=1, y=1, player_id=0) game.alive_players = [player] game.npcs = [NPC(2, 2)] game.bullets = [Bullet(3, 3)] game.walls = [TinyWall(x=4, y=4), Water(x=5, y=5)] game.coins = [Coin(x=4, y=4), Coin(x=5, y=5)] assert messages.get_world_data(player, game) == dict( id=player.id.hex, cords=[ dict(type='player', id=player.id.hex, position={ 'x': 1, 'y': 1 }), dict(type='npc', id=game.npcs[0].id.hex, position={ 'x': 2, 'y': 2 }), dict(type='bullet', id=game.bullets[0].id.hex, position={ 'x': 3, 'y': 3 }), dict(type='tinywall', id=game.walls[0].id.hex, position={ 'x': 4, 'y': 4 }), dict(type='water', id=game.walls[1].id.hex, position={ 'x': 5, 'y': 5 }), dict(type='coin', id=game.coins[0].id.hex, position={ 'x': 4, 'y': 4 }), dict(type='coin', id=game.coins[1].id.hex, position={ 'x': 5, 'y': 5 }), ])
def test_messages_get_over_game_data(): player_a = Player(x=1, y=2, player_id=0) player_b = Player(x=1, y=2, player_id=1) player_a.score = 20 player_b.score = 40 game = Game() game.alive_players = [player_a, player_b] assert messages.get_over_game_data(game) == dict( status='game', action='over', winner=player_b.id.hex, )
async def test_set_old_position(): game = Game() game.bullets = [Bullet(128, 128)] game.alive_players = [Player(x=128, y=128, player_id=0)] game.npcs = [NPC(128, 128)] for monster in game.get_monsters_chain(): monster.set_position(42, 24) await SetOldPositionLogicPart(game).do_it() for monster in game.bullets + game.alive_players + game.npcs: assert monster.old_position.x == 42 assert monster.old_position.y == 24
def test_render_players_with_freeze(pygame): game = Game() game.alive_players = [ Player(0, 32, 32), ] game.alive_players[0].set_freeze() drawer = Drawer(game) drawer._blit = Mock(spec=drawer._blit) drawer._render_players() assert drawer._blit.call_args_list == [ call('IMG_PLAYER_1_1', game.alive_players[0]), call('FREEZE', game.alive_players[0]), ]
def test_render_players(pygame): game = Game() game.alive_players = [ Player(0, 32, 32), Player(1, 64, 32), ] drawer = Drawer(game) drawer._blit = Mock(spec=drawer._blit) drawer._render_players() assert drawer._blit.call_args_list == [ call('IMG_PLAYER_1_1', game.alive_players[0]), call('IMG_PLAYER_2_1', game.alive_players[1]), ]
async def test_move(): game = Game() # default direction is UP game.bullets = [Bullet(128, 128)] game.alive_players = [Player(x=128, y=128, player_id=0)] # but default direction of NPC is DOWN game.npcs = [NPC(128, 128)] game.alive_players[0].set_speed(2) game.npcs[0].set_speed(2) await MoveLogicPart(game).do_it() assert game.alive_players[0].get_position() == {'x': 128, 'y': 128 - 2} assert game.npcs[0].get_position() == {'x': 128, 'y': 128 + 2} assert game.bullets[0].get_position() == {'x': 128, 'y': 128 - 8}
def make_game(*players): game = Game() game.alive_players = players return game