def test_drawer_blit_pack(pygame): drawer = Drawer(Game()) image = object() drawer.IMAGES = {'IMAGE': {Direction.DOWN: image}} monster = NPC(1, 2) monster.set_direction(Direction.DOWN) drawer._blit('IMAGE', monster) drawer.screen.blit.assert_called_once_with( image, (drawer.OFFSET + 1, drawer.OFFSET + 2))
def test_render_npcs(pygame): game = Game() game.npcs = [ NPC(32, 32), NPC(64, 32), ] drawer = Drawer(game) drawer._blit = Mock(spec=drawer._blit) drawer._render_npcs() assert drawer._blit.call_args_list == [ call('IMG_NPC_1', game.npcs[0]), call('IMG_NPC_1', game.npcs[1]), ]
def test_drawer_blit_simple(pygame): drawer = Drawer(Game()) image = object() drawer.IMAGES = {'IMAGE': image} drawer._blit('IMAGE', NPC(1, 2)) drawer.screen.blit.assert_called_once_with( image, (drawer.OFFSET + 1, drawer.OFFSET + 2))
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 }), ])
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_text(pygame): game = Game() game.npcs = [NPC(0, 0), NPC(1, 1)] game.players = [Player(0, 32, 32), Player(1, 64, 32)] game.players[0].set_nick('1234') game.players[0].score = 100 game.time_left = 125 game.npcs_left = 3 drawer = Drawer(game) drawer._render_label = Mock(spec=drawer._render_label) drawer._render_text() assert drawer._render_label.call_args_list == [ call('title', 'BATTLE CITY AI', (0, 00)), call('npc_left', 'NPCs left: 003', (0, 40)), call('npc', 'NPCs in area: 002', (0, 80)), call('time', 'Time left: 125', (0, 120)), call('not-ready', 'NOT READY', (0, 180)), call('p-1', '1234 000100', (0, 240), drawer.PLAYER_COLORS[0]), call('p-info-1', 'WAIT', (0, 260), drawer.PLAYER_COLORS[0]), call('p-2', 'P1 000000', (0, 280), drawer.PLAYER_COLORS[1]), call('p-info-2', 'WAIT', (0, 300), drawer.PLAYER_COLORS[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}