예제 #1
0
    def test_successful_multiple_attack_actions(self):
        game_state = GameState(AvatarMap(self.other_avatar),
                               self.avatar_manager)
        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        self.assertEqual(self.other_avatar.events,
                         [event.ReceivedAttackEvent(self.avatar, 1)])

        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        self.assertEqual(
            self.other_avatar.events,
            [
                event.ReceivedAttackEvent(self.avatar, 1),
                event.ReceivedAttackEvent(self.avatar, 1),
            ],
        )

        self.assertEqual(self.avatar.location, ORIGIN)
        self.assertEqual(self.other_avatar.location, EAST_OF_ORIGIN)
        self.assertEqual(self.other_avatar.times_died, 0)
        self.assertEqual(self.other_avatar.health, 3)
예제 #2
0
    def test_successful_multiple_attack_actions(self):
        game_state = GameState(AvatarMap(self.other_avatar),
                               self.avatar_manager)
        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        assert self.other_avatar.events == [
            event.ReceivedAttackEvent(self.avatar, 1)
        ]

        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        assert self.other_avatar.events == [
            event.ReceivedAttackEvent(self.avatar, 1),
            event.ReceivedAttackEvent(self.avatar, 1),
        ]

        assert self.avatar.location == ORIGIN
        assert self.other_avatar.location == EAST_OF_ORIGIN
        assert self.other_avatar.times_died == 0
        assert self.other_avatar.health == 3
예제 #3
0
    def test_successful_attack_action(self):
        game_state = GameState(AvatarMap(self.other_avatar),
                               self.avatar_manager)
        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        target_location = NORTH_OF_ORIGIN
        damage_dealt = 1

        self.assertEqual(self.avatar.location, ORIGIN)
        self.assertEqual(self.other_avatar.location, EAST_OF_ORIGIN)
        self.assertEqual(self.other_avatar.times_died, 0)
        self.assertEqual(self.other_avatar.health, 4)

        self.assertEqual(
            self.avatar.events,
            [
                event.PerformedAttackEvent(self.other_avatar, target_location,
                                           damage_dealt)
            ],
        )
        self.assertEqual(
            self.other_avatar.events,
            [event.ReceivedAttackEvent(self.avatar, damage_dealt)],
        )
예제 #4
0
    def test_failed_attack_action(self):
        game_state = GameState(InfiniteMap(), self.avatar_manager)
        action.AttackAction(self.avatar, {'x': 0, 'y': 1}).process(game_state.world_map)

        target_location = NORTH_OF_ORIGIN

        self.assertEqual(self.avatar.location, ORIGIN)
        self.assertEqual(self.other_avatar.location, EAST_OF_ORIGIN)
        self.assertEqual(self.avatar.events, [event.FailedAttackEvent(target_location)])
        self.assertEqual(self.other_avatar.events, [])
예제 #5
0
    def test_failed_attack_action(self):
        game_state = GameState(InfiniteMap(), self.avatar_manager)
        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        target_location = NORTH_OF_ORIGIN

        assert self.avatar.location == ORIGIN
        assert self.other_avatar.location == EAST_OF_ORIGIN
        assert self.avatar.events == [event.FailedAttackEvent(target_location)]
        assert self.other_avatar.events == []
예제 #6
0
    def test_avatar_dies(self):
        self.other_avatar.health = 1
        game_state = GameState(AvatarMap(self.other_avatar), self.avatar_manager)
        action.AttackAction(self.avatar, {'x': 0, 'y': 1}).process(game_state.world_map)

        target_location = NORTH_OF_ORIGIN
        damage_dealt = 1
        self.assertEqual(self.avatar.events,
                         [event.PerformedAttackEvent(
                             self.other_avatar,
                             target_location,
                             damage_dealt)])
        self.assertEqual(self.other_avatar.events,
                         [event.ReceivedAttackEvent(self.avatar, damage_dealt)])

        self.assertEqual(self.avatar.location, ORIGIN)
        self.assertEqual(self.other_avatar.health, 0)
        self.assertEqual(self.other_avatar.times_died, 1)
        self.assertEqual(self.other_avatar.location, Location(10, 10))
예제 #7
0
    def test_avatar_dies(self):
        self.other_avatar.health = 1
        game_state = GameState(AvatarMap(self.other_avatar),
                               self.avatar_manager)
        action.AttackAction(self.avatar, {
            "x": 0,
            "y": 1
        }).process(game_state.world_map)

        target_location = NORTH_OF_ORIGIN
        damage_dealt = 1
        assert self.avatar.events == [
            event.PerformedAttackEvent(self.other_avatar, target_location,
                                       damage_dealt)
        ]
        assert self.other_avatar.events == [
            event.ReceivedAttackEvent(self.avatar, damage_dealt)
        ]

        assert self.avatar.location == ORIGIN
        assert self.other_avatar.health == 0
        assert self.other_avatar.times_died == 1
        assert self.other_avatar.location == Location(10, 10)