Esempio n. 1
0
    def test_player_moving_updates_whole_screen(self):
        """
        Test that moving player character reports whole screen updated
        """
        model = Model()
        surface = mock()

        player = (CharacterBuilder()
                        .with_model(model)
                        .as_player_character()
                        .with_action_factory(ActionFactoryBuilder()
                                                .with_model(model)
                                                .with_move_factory())
                        .with_name('player')
                        .with_location((11, 11))
                        .build())

        monster = (CharacterBuilder()
                        .with_model(model)
                        .with_action_factory(ActionFactoryBuilder()
                                                .with_model(model)
                                                .with_move_factory())
                        .with_name('rat')
                        .with_location((5, 5))
                        .build())

        level = (LevelBuilder()
                    .with_character(player)
                    .with_character(monster)
                    .build())

        application = Application()
        application.world = model

        game_gui = GameArea(application = application,
                            surface_manager = mock(),
                            decorate = False,
                            width = 800,
                            height = 600)

        game_gui.old_location = player.location

        model.register_event_listener(game_gui)

        player.move(7)
        rects = game_gui.update(surface)

        assert_that(rects, has_items(Rect(0, 0, 800, 600)))
Esempio n. 2
0
    def test_updating_screen_while_monster_moves(self):
        """
        Test that only needed spots are reported as updated as a monster moves
        """
        model = Model()
        surface = mock()

        player = (CharacterBuilder()
                        .with_model(model)
                        .as_player_character()
                        .with_name('player')
                        .with_location((11, 11))
                        .build())

        monster = (CharacterBuilder()
                        .with_model(model)
                        .with_action_factory(ActionFactoryBuilder()
                                                .with_model(model)
                                                .with_move_factory())
                        .with_name('rat')
                        .with_location((5, 5))
                        .build())

        level = (LevelBuilder()
                    .with_character(player)
                    .with_character(monster)
                    .build())

        application = Application()
        application.world = model

        game_gui = GameArea(application = application,
                            surface_manager = mock(),
                            decorate = False,
                            width = 800,
                            height = 600)

        game_gui.old_location = player.location

        model.register_event_listener(game_gui)

        game_gui.paint(surface)
        monster.move(7)
        rects = game_gui.update(surface)

        assert_that(rects, has_items(Rect(160, 88, 192, 120),
                                     Rect(192, 88, 224, 120)))
Esempio n. 3
0
    def test_recording_dirty_tiles(self):
        """
        Test that GameArea records dirty tiles for updating based on events
        """
        level = LevelBuilder().build()

        game_gui = GameArea(application = Application(),
                            surface_manager = mock(),
                            decorate = False)

        tiles = [(10, 10),
                 (11, 11)]

        mover = mock()
        mover.location = (10, 10)
        mover.level = mock()

        game_gui.receive_event(MoveEvent(mover = mover,
                                         affected_tiles = tiles))

        assert_that(game_gui.dirty_tiles, has_items((10, 10), (11, 11)))