示例#1
0
    def _init_hanoi(self):
        # Variables for the animation
        self._next_move = True
        self._move = 0
        self._starting_left = 0
        self._starting_top = 0
        self._target_left = 0
        self._target_top = 0
        self._acceleration = 0
        self._time_spent = 0

        # Flags indicating the state of the program
        self._running_flag = False
        self._step_by_step_flag = False
        self._over_flag = False

        # Reset the trigger_button to 'Start'
        self._trigger_button.text = 'Start'

        # Hanoi algorithm object
        self._hanoi = Hanoi(input('Please enter the number of plates\n'))

        # Initialization of the plate images
        for each_plate in self._hanoi.get_plates(0):
            plate_image = TextButton(self)
            plate_image.rect = (70 + self._hanoi.get_total() * PLATE_BASE_WIDTH / 2) - each_plate.number * PLATE_BASE_WIDTH / 2, \
                               (WINDOW_HEIGHT - self._hanoi.get_total() * PLATE_HEIGHT) + each_plate.number * PLATE_HEIGHT, \
                               PLATE_BASE_WIDTH * (each_plate.number + 1), \
                               PLATE_HEIGHT

            plate_image.background = r'Images\Root_button.png'
            self._plate_images.insert(0, plate_image)

        # Start running the hanoi algorithm and animation
        self._steps = self._hanoi.move(self._hanoi.get_total(), 0, 2)
        self._animation = koan.anim.IntervalExecute(TIME_INTERVAL,
                                                    self._onTimer)
示例#2
0
 def _init_hanoi(self):
     # Variables for the animation
     self._next_move = True
     self._move = 0
     self._starting_left = 0
     self._starting_top = 0
     self._target_left = 0
     self._target_top = 0
     self._acceleration = 0
     self._time_spent = 0
     
     # Flags indicating the state of the program
     self._running_flag = False
     self._step_by_step_flag = False
     self._over_flag = False
     
     # Reset the trigger_button to 'Start'
     self._trigger_button.text = 'Start'
     
     # Hanoi algorithm object
     self._hanoi = Hanoi(input('Please enter the number of plates\n'))
     
     # Initialization of the plate images    
     for each_plate in self._hanoi.get_plates(0):
         plate_image = TextButton(self)
         plate_image.rect = (70 + self._hanoi.get_total() * PLATE_BASE_WIDTH / 2) - each_plate.number * PLATE_BASE_WIDTH / 2, \
                            (WINDOW_HEIGHT - self._hanoi.get_total() * PLATE_HEIGHT) + each_plate.number * PLATE_HEIGHT, \
                            PLATE_BASE_WIDTH * (each_plate.number + 1), \
                            PLATE_HEIGHT     
         
         plate_image.background = r'Images\Root_button.png'
         self._plate_images.insert(0, plate_image)
         
     # Start running the hanoi algorithm and animation    
     self._steps = self._hanoi.move(self._hanoi.get_total(), 0, 2)
     self._animation = koan.anim.IntervalExecute(TIME_INTERVAL, self._onTimer)