def timerEvent(self, event): if event.timerId() == self.timer.timerId(): # 如果TETRIS_AI存在,则由AI进行下一步操作 if TETRIS_AI and not self.nextMove: self.nextMove = TETRIS_AI.nextMove() if self.nextMove: k = 0 while BOARD_DATA.currentDirection != self.nextMove[0] and k < 4: BOARD_DATA.rotateRight() k += 1 k = 0 while BOARD_DATA.currentX != self.nextMove[1] and k < 5: if BOARD_DATA.currentX > self.nextMove[1]: BOARD_DATA.moveLeft() elif BOARD_DATA.currentX < self.nextMove[1]: BOARD_DATA.moveRight() k += 1 # lines = BOARD_DATA.dropDown() lines = BOARD_DATA.moveDown() self.tboard.score += lines if self.lastShape != BOARD_DATA.currentShape: self.nextMove = None self.lastShape = BOARD_DATA.currentShape self.updateWindow() else: super(Tetris, self).timerEvent(event)
def timerEvent(self, event): if event.timerId() == self.timer.timerId(): if TETRIS_AI and not self.nextMove: self.nextMove = TETRIS_AI.nextMove() if self.nextMove: k = 0 while BOARD_DATA.currentDirection != self.nextMove[0] and k < 4: BOARD_DATA.rotateRight() k += 1 k = 0 while BOARD_DATA.currentX != self.nextMove[1] and k < 5: if BOARD_DATA.currentX > self.nextMove[1]: BOARD_DATA.moveLeft() elif BOARD_DATA.currentX < self.nextMove[1]: BOARD_DATA.moveRight() k += 1 # lines = BOARD_DATA.dropDown() lines = BOARD_DATA.moveDown() self.tboard.score += lines if self.lastShape != BOARD_DATA.currentShape: self.nextMove = None self.lastShape = BOARD_DATA.currentShape self.updateWindow() else: super(Tetris, self).timerEvent(event)