示例#1
0
    def keyPressEvent(self, event):
        if not self.isStarted or BOARD_DATA.currentShape == Shape.shapeNone:
            super(Tetris, self).keyPressEvent(event)
            return

        key = event.key()
        
        if key == Qt.Key_P:
            self.pause()
            return
            
        if self.isPaused:
            return
        elif key == Qt.Key_Left:
            BOARD_DATA.moveLeft()
        elif key == Qt.Key_Right:
            BOARD_DATA.moveRight()
        elif key == Qt.Key_Up:
            BOARD_DATA.rotateLeft()
        elif key == Qt.Key_Down:
            BOARD_DATA.moveDown()
        elif key == Qt.Key_Space:
            self.tboard.score += BOARD_DATA.dropDown()
        else:
            super(Tetris, self).keyPressEvent(event)

        self.updateWindow()
示例#2
0
    def start(self):
        if self.isPaused:
            return

        self.isStarted = True
        self.tboard.score = 0
        BOARD_DATA.clear()

        self.tboard.msg2Statusbar.emit(str(self.tboard.score))

        BOARD_DATA.createNewPiece()
        self.timer.start(self.speed, self)
示例#3
0
    def start(self):
        if self.isPaused:
            return

        self.isStarted = True
        self.tboard.score = 0
        BOARD_DATA.clear()

        self.tboard.msg2Statusbar.emit(str(self.tboard.score))

        BOARD_DATA.createNewPiece()
        self.timer.start(self.speed, self)
示例#4
0
    def start(self):  #시작 함수
        if self.isPaused:
            return

        self.isStarted = True
        self.tboard.score = 0
        BOARD_DATA.clear()  #보드 데이터 초기화

        self.tboard.msg2Statusbar.emit(str(
            self.tboard.score))  #스테이터스 바에 줄 파괴횟수 표기

        BOARD_DATA.createNewPiece()
        self.timer.start(self.speed, self)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
    def keyPressEvent(self, event):
        if not self.isStarted or BOARD_DATA.currentShape == Shape.shapeNone:
            super(Tetris, self).keyPressEvent(event)
            return

        key = event.key()
        
        if key == Qt.Key_P:
            self.pause()
            return
            
        if self.isPaused:
            return
        elif key == Qt.Key_Left:
            BOARD_DATA.moveLeft()
        elif key == Qt.Key_Right:
            BOARD_DATA.moveRight()
        elif key == Qt.Key_Up:
            BOARD_DATA.rotateLeft()
        elif key == Qt.Key_Space:
            self.tboard.score += BOARD_DATA.dropDown()
        else:
            super(Tetris, self).keyPressEvent(event)

        self.updateWindow()
示例#8
0
    def keyPressEvent(self, event):
        if not self.isStarted or BOARD_DATA.currentShape == Shape.shapeNone:
            super(Tetris, self).keyPressEvent(event)  #keyPressEvent 재호출
            return

        key = event.key()

        if key == Qt.Key_P:  # p누르면 일시정지
            self.pause()
            return

        if self.isPaused:
            return
        elif key == Qt.Key_Left:  # 왼쪽키 > 좌측 이동
            BOARD_DATA.moveLeft()
        elif key == Qt.Key_Right:  # 우측 키 > 우측 이동
            BOARD_DATA.moveRight()
        elif key == Qt.Key_Up:  # 위 키 > 블럭 회전
            BOARD_DATA.rotateLeft()
        elif key == Qt.Key_Space:  # 스페이크 키 > 블럭 하강
            self.tboard.score += BOARD_DATA.dropDown()
        else:
            super(Tetris, self).keyPressEvent(event)  #keyPressEvent 재호출

        self.updateWindow()
示例#9
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Draw backboard
        for x in range(BOARD_DATA.width):
            for y in range(BOARD_DATA.height):
                val = BOARD_DATA.getValue(x, y)
                drawSquare(painter, x * self.gridSize, y * self.gridSize, val, self.gridSize)

        # Draw current shape
        for x, y in BOARD_DATA.getCurrentShapeCoord():
            val = BOARD_DATA.currentShape.shape
            drawSquare(painter, x * self.gridSize, y * self.gridSize, val, self.gridSize)

        # Draw a border
        painter.setPen(QColor(0x777777))
        painter.drawLine(self.width()-1, 0, self.width()-1, self.height())
        painter.setPen(QColor(0xCCCCCC))
        painter.drawLine(self.width(), 0, self.width(), self.height())
示例#10
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Draw backboard
        for x in range(BOARD_DATA.width):
            for y in range(BOARD_DATA.height):
                val = BOARD_DATA.getValue(x, y)
                drawSquare(painter, x * self.gridSize, y * self.gridSize, val, self.gridSize)

        # Draw current shape
        for x, y in BOARD_DATA.getCurrentShapeCoord():
            val = BOARD_DATA.currentShape.shape
            drawSquare(painter, x * self.gridSize, y * self.gridSize, val, self.gridSize)

        # Draw a border
        painter.setPen(QColor(0x777777))
        painter.drawLine(self.width()-1, 0, self.width()-1, self.height())
        painter.setPen(QColor(0xCCCCCC))
        painter.drawLine(self.width(), 0, self.width(), self.height())
示例#11
0
 def initBoard(self):
     self.score = 0
     BOARD_DATA.clear()
示例#12
0
 def calcStep1Board(self, d0, x0):
     board = np.array(BOARD_DATA.getData()).reshape(
         (BOARD_DATA.height, BOARD_DATA.width))
     self.dropDown(board, BOARD_DATA.currentShape, d0, x0)
     return board
示例#13
0
 def calcStep1Board(self, d0, x0):
     board = np.array(BOARD_DATA.getData()).reshape((BOARD_DATA.height, BOARD_DATA.width))
     self.dropDown(board, BOARD_DATA.currentShape, d0, x0)
     return board
示例#14
0
 def initBoard(self):
     self.score = 0
     BOARD_DATA.clear()
示例#15
0
 def initBoard(self):
     self.score = 0
     self.itemNum = 0
     self.setStyleSheet('color:white;background:black')
     BOARD_DATA.clear()
示例#16
0
    def keyPressEvent(self, event):
        if not self.isStarted or BOARD_DATA.currentShape == Shape.shapeNone:
            super(Tetris, self).keyPressEvent(event)
            return

        key = event.key()

        if key == Qt.Key_P:
            self.pause()
            return

        if self.isPaused:
            return
        elif key == Qt.Key_Left:
            BOARD_DATA.moveLeft()
        elif key == Qt.Key_Right:
            BOARD_DATA.moveRight()
        elif key == Qt.Key_Down:
            lineCheck = BOARD_DATA.moveDown()
            self.tboard.score += lineCheck
            if lineCheck >= 2:
                self.tboard.itemNum += int(lineCheck / 2)
        elif key == Qt.Key_Up:
            BOARD_DATA.rotateLeft()
        elif key == Qt.Key_Space:
            lineCheck = BOARD_DATA.dropDown()
            self.tboard.score += lineCheck
            if lineCheck >= 2:
                self.tboard.itemNum += int(lineCheck / 2)
        elif key == Qt.Key_Z:
            if self.tboard.itemNum >= 1:
                self.tboard.itemNum -= 1
                itemRandom = random.randint(1, 2)
                if itemRandom == 1:
                    BOARD_DATA.createNewPiece()
                elif itemRandom == 2:
                    BOARD_DATA.clear()
        elif key == Qt.Key_Escape:
            self.reGame()
        else:
            super(Tetris, self).keyPressEvent(event)

        self.updateWindow()