Exemplo n.º 1
0
class TestRepeatedTimer(TestCase):
    def setUp(self):
        self.timer = RepeatedTimer()
        self.time_fun = lambda x:hello(x)

    def test_start_input_args(self):

        time_fun = lambda x:print(x)
        self.timer = RepeatedTimer(1,time_fun,5,6)
        constructor_intearface =  self.timer.start_input_args
        self.timer.start_input_args = 5,6
        seting_input  = self.timer.start_input_args
        self.assertEqual(constructor_intearface,seting_input)


    def test_set_attr(self):

        self.timer.set_attr(timer_function=self.time_fun, interval= 1, start_input_args = ['test_set_attr'],limit=10)

        self.timer.start()

    def test_start(self):

        self.timer.set_attr( timer_function = self.time_fun, interval=1 )
        self.timer.start_input_args = ['test_start']
        self.timer.start()

    def test_stop(self):

        self.timer.set_attr(timer_function=self.time_fun, stop_function=self.time_fun, interval= 0.01, limit=0.05)
        self.timer.start_input_args = ['test_stop']
        self.timer.stop_input_args = ['stop']
        self.timer.start()
Exemplo n.º 2
0
class Goblin(Human):
    def __init__(self, environment, **attr):
        super().__init__(environment, **attr)
        self.images_path = full_file(['Resources', 'images', 'Enemy'])

        # create goblin
        self.power = 3
        self.move_direction = 'center'
        self.walk_direction = 'left'
        self.high = 180

        self.sound_hooch = full_file(['Resources', 'sound', 'wound.mp3'])
        self.sound_dead = full_file(['Resources', 'sound', 'died.mp3'])
        self.__attack = False
        self.timer = RepeatedTimer()

    def create(self):

        self.walkRight = [
            self.load_image('R1E.png'),
            self.load_image('R2E.png'),
            self.load_image('R3E.png'),
            self.load_image('R4E.png'),
            self.load_image('R5E.png'),
            self.load_image('R6E.png'),
            self.load_image('R7E.png'),
            self.load_image('R8E.png'),
            self.load_image('R5E.png')
        ]

        self.walkLeft = [
            self.load_image('L1E.png'),
            self.load_image('L2E.png'),
            self.load_image('L3E.png'),
            self.load_image('L4E.png'),
            self.load_image('L5E.png'),
            self.load_image('L6E.png'),
            self.load_image('L7E.png'),
            self.load_image('L8E.png'),
            self.load_image('L5E.png')
        ]
        self.standing = [self.load_image('L1E.png')]

        self.attack_right = [
            self.load_image('R9E.png'),
            self.load_image('R10E.png'),
            self.load_image('R11E.png')
        ]
        self.attack_left = [
            self.load_image('L9E.png'),
            self.load_image('L10E.png'),
            self.load_image('L11E.png')
        ]

    def draw(self):

        if self.__attack == False:
            super().draw()

        elif self.__attack == True:
            self._frame_count += 1
            if self.move_direction == 'left':

                self._environment.win.blit(
                    self.attack_left[self._frame_count % 3],
                    (self.position_x, self.position_on_canvas_y()))
            elif self.move_direction == 'right':

                self._environment.win.blit(
                    self.attack_right[self._frame_count % 3],
                    (self.position_x, self.position_on_canvas_y()))

    def attack(self):

        self.timer.set_attr(timer_function=self.box_attack,
                            start_input_args=[True],
                            stop_function=self.box_attack,
                            stop_input_args=[False],
                            interval=0.1,
                            limit=0.5)
        self.timer.start()

    def box_attack(self, state: bool = True):

        self.__attack = state