コード例 #1
0
 def test_open(self):
     game_state = GameState()
     game_state.window_size = Vector(0, 500)
     dialog = Dialog(True)
     dialog.open(game_state)
     self.assertTrue(dialog.visible)
     self.assertEqual(300, dialog.position.y)
コード例 #2
0
    def test_update(self):
        was_called = []

        def shoot(*_):
            was_called.append(0)

        game_state = GameState()
        game_state.window_size = Vector(100, 100)
        game_state.building_manager.shoot = shoot

        # no enemy to shoot at
        building = Laser(Vector(), Vector(10, 10))
        building.cool_down = 0
        building.update(game_state)
        self.assertEqual(0, len(was_called))

        # on cool down
        building = Laser(Vector(), Vector(10, 10))
        building.cool_down = 100
        building.update(game_state)
        self.assertEqual(0, len(was_called))

        # shooting
        game_state.entity_manager.entities = [
            Entity(Vector(150, 0), Vector(10, 10), EntityType.LARGE_BOULDER)
        ]
        building = Laser(Vector(), Vector(10, 10))
        building.cool_down = 0
        building.update(game_state)
        self.assertEqual(1, len(was_called))
コード例 #3
0
    def test_render_highlight(self):
        game_state = GameState()
        game_state.window_size = Vector(100, 100)
        was_called = []

        def dummy(*args):
            was_called.append(0)

        batch = pyglet.graphics.Batch()
        batch.add = dummy

        position = Vector()
        size = Vector(10, 10)
        tile_type = TileType.BUILDING_GROUND
        tile = Tile(position, size, tile_type)
        tile.render_highlight(game_state, batch)
        self.assertEqual(4, len(was_called))

        def dummy(*args):
            was_called.append(0)

        batch = pyglet.graphics.Batch()
        batch.add = dummy

        game_state = GameState()
        was_called.clear()
        position = Vector()
        size = Vector(10, 10)
        tile_type = TileType.BUILDING_GROUND
        tile = Tile(position, size, tile_type)
        tile.render_highlight(game_state, batch)
        self.assertEqual(0, len(was_called))
コード例 #4
0
    def test_update_reset_animation_speed(self):
        game_state = GameState()
        game_state.window_size = Vector(100, 100)

        building = Drill(Vector(), Vector(10, 10))
        building.animation_speed = 5
        building.update(game_state)
        self.assertEqual(0, building.animation_speed)
コード例 #5
0
    def test_update_key_event_bottom_right(self):
        game_state = GameState()
        game_state.key_presses.down = True
        game_state.key_presses.right = True
        game_state.window_size = Vector(1280, 720)
        game_state.update()

        actual = game_state.world_offset
        self.assertEqual(Vector(95, 105), actual)
コード例 #6
0
    def test_update_key_event_top_left(self):
        game_state = GameState()
        game_state.key_presses.up = True
        game_state.key_presses.left = True
        game_state.window_size = Vector(1280, 720)
        game_state.update()

        actual = game_state.world_offset
        self.assertEqual(Vector(105, 95), actual)
コード例 #7
0
    def test_check_for_entities(self):
        game_state = GameState()
        game_state.window_size = Vector(100, 100)

        building = Drill(Vector(), Vector(10, 10))
        result = building.check_for_entities(game_state)
        self.assertEqual(False, result)

        game_state = GameState()
        game_state.window_size = Vector(100, 100)
        game_state.entity_manager.entities = [
            Entity(Vector(), Vector(10, 10), EntityType.LARGE_BOULDER)
        ]

        building = Drill(Vector(), Vector(10, 10))
        result = building.check_for_entities(game_state)
        self.assertEqual(True, result)
        self.assertEqual(5, building.animation_speed)
        self.assertEqual(99, game_state.entity_manager.entities[0].health)
コード例 #8
0
    def test_render_no_label(self):
        game_state = GameState()
        game_state.window_size = Vector(100, 100)

        position = Vector(1, 1)
        size = Vector(10, 10)
        tile_type = TileType.BUILDING_GROUND
        tile = Tile(position, size, tile_type)

        batch = pyglet.graphics.Batch()
        tile.render_label(game_state, batch)
        self.assertEqual(0, len(batch.top_groups))
コード例 #9
0
    def test_render(self):
        game_state = GameState()
        game_state.init("./tower_defense/res")
        game_state.window_size = Vector(100, 100)

        building = Hammer(Vector(), Vector(10, 10))
        batch = pyglet.graphics.Batch()
        building.render(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        building = Hammer(Vector(20, 20), Vector(10, 10))
        batch = pyglet.graphics.Batch()
        building.render(game_state, batch)
        self.assertEqual(0, len(batch.top_groups))
コード例 #10
0
    def test_render(self):
        game_state = GameState()
        game_state.init("./tower_defense/res")
        game_state.window_size = Vector(100, 100)

        entity = Entity(Vector(1, 1), Vector(10, 10), EntityType.LARGE_BOULDER)
        batch = pyglet.graphics.Batch()
        entity.render(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        entity = Entity(Vector(10, 10), Vector(10, 10),
                        EntityType.LARGE_BOULDER)
        batch = pyglet.graphics.Batch()
        entity.render(game_state, batch)
        self.assertEqual(0, len(batch.top_groups))
コード例 #11
0
    def test_world_to_window_space(self):
        game_state = GameState()
        game_state.window_size = Vector(100, 100)

        position = Vector(1, 1)
        size = Vector(10, 10)
        self.assertEqual(None,
                         game_state.world_to_window_space(position, size))

        position = Vector()
        size = Vector(10, 10)
        self.assertEqual(Vector(100, 100),
                         game_state.world_to_window_space(position, size))

        game_state.world_offset = Vector(-100, 0)
        position = Vector()
        size = Vector(10, 10)
        self.assertEqual(None,
                         game_state.world_to_window_space(position, size))
コード例 #12
0
    def test_render(self):
        game_state = GameState()
        game_state.init("./tower_defense/res")
        game_state.window_size = Vector(100, 100)

        position = Vector()
        size = Vector(10, 10)
        tile_type = TileType.BUILDING_GROUND
        tile = Tile(position, size, tile_type)

        batch = pyglet.graphics.Batch()
        tile.render(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        batch = pyglet.graphics.Batch()
        tile.tile_type = TileType.START
        tile.render(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(MovementGroup, type(batch.top_groups[0]))
コード例 #13
0
    def test_render_arrow(self):
        game_state = GameState()
        game_state.init("./tower_defense/res")
        game_state.window_size = Vector(100, 100)

        position = Vector()
        size = Vector(10, 10)
        tile_type = TileType.BUILDING_GROUND
        tile = Tile(position, size, tile_type)
        tile.direction_index = 1
        tile.timer = 50

        tile.directions = [(1, 0)]
        batch = pyglet.graphics.Batch()
        tile.render_arrow(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        tile.directions = [(-1, 0)]
        batch = pyglet.graphics.Batch()
        tile.render_arrow(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        tile.directions = [(0, 1)]
        batch = pyglet.graphics.Batch()
        tile.render_arrow(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))

        tile.directions = [(0, -1)]
        batch = pyglet.graphics.Batch()
        tile.render_arrow(game_state, batch)
        self.assertEqual(1, len(batch.top_groups))
        self.assertEqual(pyglet.graphics.TextureGroup,
                         type(batch.top_groups[0]))
コード例 #14
0
 def test_update_no_key_event(self):
     game_state = GameState()
     world_offset_before = game_state.world_offset
     game_state.window_size = Vector(1280, 720)
     game_state.update()
     self.assertEqual(world_offset_before, game_state.world_offset)