class Bot: def __init__(self): print("Starting...") self.controller = Controller() self.image = Image() self.stopwatch = Stopwatch() def update(self): while True: if win32gui.GetWindowText(win32gui.GetForegroundWindow()) == config.dino_title: self.image.get_screenshot() self.event_handler() def event_handler(self): max_x = 400 if self.stopwatch.get_time() > 20: max_x = 500 elif self.stopwatch.get_time() > 60: max_x = 1110 elif self.stopwatch.get_time() > 80: max_x = 1200 elif self.stopwatch.get_time() > 100: max_x = 1300 elif self.stopwatch.get_time() > 120: max_x = 1500 for x in range(120, max_x, 2): for y in range(config.bird_y, config.cactus_y, 5): if self.image.get_pixel(x, y).color == config.enemy_color: # check for an enemy if self.controller.jump(): print("[" + datetime.now().strftime("%H:%M:%S") + "; " + str(self.stopwatch.get_time()) + "] Jumping...") return True return False
except Exception: print("Error: Incorrect format provided") exit() try: read_file() except IOError: print("Error: No such file found, quitting") exit() check_necessary_args() passkey = get_key_by_val(__PASS__, params) for i in range(n_threads): t = Thread(target=check_each_password) t.setDaemon(True) t.start() threads.append(t) #wait for all threads to finish for thread in threads: thread.join() sw.stop() print(ANSIColor.OKGREEN + "Finished in " + sw.get_time() + ", attempted " + str(attempted_passwords) + " passwords") except KeyboardInterrupt, ki: print(str(ki)) processing = False
class Window(QWidget): """ The Stopwatch window """ def __init__(self): super().__init__() self.stopwatch = Stopwatch() self.init_window() self.updater = ValueUpdater(self) def init_window(self): """ Initialize window content """ # Window properties self.setGeometry(50, 50, 300, 200) self.setWindowTitle('PythonTimer') # Label self.timer_label = QLabel(self) self.timer_label.setText(self.get_formatted_time()) self.timer_label.setFont(QFont('SansSerif', 20)) # Push buttons self.start_button = QPushButton('Start / Pause', self) self.start_button.clicked.connect(self.start_pressed) self.reset_button = QPushButton('Reset', self) self.reset_button.clicked.connect(self.reset_pressed) # Layout label_row = QHBoxLayout() label_row.addStretch(1) label_row.addWidget(self.timer_label) label_row.addStretch(1) button_row = QHBoxLayout() button_row.addStretch(1) button_row.addWidget(self.start_button) button_row.addWidget(self.reset_button) button_row.addStretch(1) vert_layout = QVBoxLayout() vert_layout.addStretch(1) vert_layout.addLayout(label_row) vert_layout.addStretch(1) vert_layout.addLayout(button_row) self.setLayout(vert_layout) self.show() def start_pressed(self): """ Start button behaviour """ if self.updater.isRunning(): self.updater.quit() else: self.updater.start() self.stopwatch.start_or_pause() def reset_pressed(self): """ Reset button behaviour """ self.stopwatch.reset() def get_formatted_time(self): """ Get the stopwatch time and format it """ sec = self.stopwatch.get_time() hour = (int)(sec // 3600) sec -= hour * 3600 mins = (int)(sec // 60) sec -= mins * 60 return "{:02d}:{:02d}:{:04.1f}".format(hour, mins, sec)