pyQT6实现围棋游戏

pyQT6实现围棋游戏,逻辑清晰,界面美观,非常NICE!资源下载链接https://editor.csdn.net/md/?articleId=128931802
在这里插入图片描述

  1. board.py
import copy

from PyQt6.QtWidgets import QFrame, QLabel, QMessageBox
from PyQt6.QtCore import Qt, QBasicTimer, pyqtSignal, QPointF, pyqtSlot
from PyQt6.QtGui import QPainter, QColor, QPen, QBrush, QCursor, QPixmap

class LaBel(QLabel):
    def __init__(self, parent):
        super().__init__(parent)
        self.setMouseTracking(True)

    def enterEvent(self, e):
        e.ignore()
class Board(QFrame):  # base the board on a QFrame widget
    updateTimerSignal = pyqtSignal(int)  # signal sent when timer is updated
    clickLocationSignal = pyqtSignal(str)  # signal sent when there is a new click location
    update_Black_Prisoners=pyqtSignal(int) #signal sent when Black Prisoners
    update_White_Prisoners=pyqtSignal(int) #signal sent when White Prisoners
    Repentance_return=pyqtSignal(int)
    Repentancep=0
    Resetp=0
    Passp = 0
    boardWidth = 7  # board is 0 squares wide # this needs updating
    boardHeight = 7
    timerSpeed = 1000  # the timer updates every 1 millisecond
    counter = 120  # the number the counter will count down from

    def __init__(self, parent):
        super().__init__(parent)
        self.initBoard()

    def initBoard(self):
        '''initiates board'''
        self.timer = QBasicTimer()  # create a timer for the game
        self.isStarted = False  # game is not currently started
        self.start()  # start the game which will start the time

        self.BDpixmap=QPixmap("BD-7.png");
        self.WDpixmap = QPixmap("WD-7.png");
        self.setCursor(QCursor(self.BDpixmap));
        self.present = 0
        self.my_turn = True
        self.stop = True
        ## Number of penitence, the number of times greater than 0 can be penitence, the initial 0 (the initial can not penitence), penitence after 0, chess or abandon the hand to restore to 1, in order to prohibit continuous penitence
        self.regretchance = 0
        self.mouse_point = LaBel(self)  # Change mouse image to chess piece
        self.mouse_point.setScaledContents(True)
        self.pieces = [[LaBel(self) for i in range(9)] for j in range(9)]  # Create a new piece TAB and prepare to draw pieces on the board
        for i in range(9):
            for j in range(9):
                self.pieces[i][j].setVisible(True)  # Picture viewable
                self.pieces[i][j].setScaledContents(True)  # The image size varies according to the label size
        self.mouse_point.raise_()  # The mouse is always on the top layer
        # Define the chessboard array, over the boundary: -1, no child: 0, Black: 1, white: 2
        self.positions = [[0 for i in range(9)] for i in range(9)]
        # Initialize the checkerboard, setting all values beyond the boundary to -1
        for m in range(9):
            for n in range(9):
                if (m * n == 0 or m == 8 or n == 8):
                    self.positions[m][n] = -1
        self.printBoardArray()
        self.last_3_positions = copy.deepcopy(self.positions)
        self.last_2_positions = copy.deepcopy(self.positions)
        self.last_1_positions = copy.deepcopy(self.positions)


    def printBoardArray(self):
        '''prints the boardArray in an attractive way'''
        print("boardArray:")
        print('\n'.join(['\t'.join([str(cell) for cell in row]) for row in self.positions]))

    def mousePosToColRow(self, event):
        '''convert the mouse click event to a row and column'''
        row= str(event.position().x())
        column=str(event.position().y())


    def squareWidth(self):
        '''returns the width of one square in the board'''
        return self.contentsRect().width() / self.boardWidth

    def squareHeight(self):
        '''returns the height of one square of the board'''
        return self.contentsRect().height() / self.boardHeight

    def start(self):
        '''starts game'''
        self.isStarted = True  # set the boolean which determines if the game has started to TRUE
        self.resetGame()  # reset the game
        self.timer.start(self.timerSpeed, self)  # start the timer with the correct speed
        print("start () - timer is started")


    def timerEvent(self, event):
        '''this event is automatically called when the timer is updated. based on the timerSpeed variable '''
        if event.timerId() == self.timer.timerId():  # if the timer that has 'ticked' is the one in this class
            if(self.Resetp==1):
                self.Resetp = 0
                self.resetGame1()
            if self.Passp == 1:
                # 悔棋恢复
                if not self.regretchance == 1:
                    self.regretchance += 1
                self.Passp = 0
                self.last_3_positions = copy.deepcopy(self.last_2_positions)
                self.last_2_positions = copy.deepcopy(self.last_1_positions)
                self.last_1_positions = copy.deepcopy(self.positions)
                if self.present == 0:
                    self.present = 1

                    self.setCursor(QCursor(self.WDpixmap));
                else:
                    self.present = 0
                    self.setCursor(QCursor(self.BDpixmap));
            if self.Repentancep==1:
                self.Repentancep=0
                self.regret()
            if self.counter == 0:
                print("Game over")
                if self.present == 0 :
                    self.showwarningbox("Game over","You're Out of Time! and  the White Wins !")
                else:
                    self.showwarningbox("Game over", "You're Out of Time! and  the Black Wins !")
                self.resetGame1()
            self.counter -= 1
            #print('timerEvent()', self.counter)
            self.updateTimerSignal.emit(self.counter)
        else:
            super(Board, self).timerEvent(event)  # if we do not handle an event we should pass it to the super
            # class for handling

    def paintEvent(self, event):
        '''paints the board and the pieces of the game'''
        painter = QPainter(self)
        self.drawBoardSquares(painter)
        #self.drawPieces(painter)
    def get_Black_Prisoners(self):
        m=0
        for i in range(0,9):
            for j in range(0,9):
                if(self.positions[i][j]==1):
                    m=m+1
        return m

    def get_White_Prisoners(self):
        m = 0
        for i in range(0, 9):
            for j in range(0, 9):
                if (self.positions[i][j] == 2):
                    m = m + 1
        return m

    def regret(self):
        #Determine whether you can repent, before the third game of chess recovery board
        if self.regretchance == 1:
            self.regretchance = 0
            list_of_b = []
            list_of_w = []
            for i in range(9):
                for j in range(9):
                    self.pieces[i][j].clear()
            if self.present == 0:
                self.setCursor(QCursor(self.BDpixmap));
            else:
                self.setCursor(QCursor(self.WDpixmap));
            for m in range(1, 8):
                for n in range(1, 8):
                    self.positions[m][n] = 0
            for m in range(len(self.last_3_positions)):
                for n in range(len(self.last_3_positions[m])):
                    if self.last_3_positions[m][n] == 1:
                        list_of_b += [[n, m]]
                    elif self.last_3_positions[m][n] == 2:
                        list_of_w += [[n, m]]
            self.recover(list_of_b, 0)
            self.recover(list_of_w, 1)
            self.last_1_positions = copy.deepcopy(self.last_3_positions)
            for m in range(1, 8):
                for n in range(1, 8):
                    self.last_2_positions[m][n] = 0
                    self.last_3_positions[m][n] = 0
    def mousePressEvent(self, event):
        '''this event is automatically called when the mouse is pressed'''
        clickLoc = "click location [" + str(event.position().x()) + "," + str(
            event.position().y()) + "]"  # the location where a mouse click was registered
        print("mousePressEvent() - " + clickLoc)
        clickLoc=clickLoc[15:100]
        self.clickLocationSignal.emit(clickLoc)
        self.printBoardArray()
        x=float(event.position().x())
        y=float(event.position().y())
        x,y = self.coordinate_transform_pixel2map(x,y)
        if  x != -1 and  y != -1:  # The piece lands on the board, eliminating the edge
            if self.positions[y][x] == 0:  # The chess pieces landed in the blank
                self.positions[y][x] = self.present + 1
                deadlist = self.get_deadlist(x, y)
                self.kill(deadlist)
                # Determine whether the chess game is repeated
                if not self.last_2_positions == self.positions:
                    # Determine whether it is gas and kill one of them
                    if len(deadlist) > 0 or self.if_dead([[x, y]], self.present + 1, [x, y]) == False:
                        # Dropping a piece is effective when the play is not repeated and it is one of the two sides that have gas or kill each other
                        if not self.regretchance == 1:
                            self.regretchance += 1
                        self.last_3_positions = copy.deepcopy(self.last_2_positions)
                        self.last_2_positions = copy.deepcopy(self.last_1_positions)
                        self.last_1_positions = copy.deepcopy(self.positions)
                        self.draw(y,x)
                        m1 = self.get_Black_Prisoners()
                        m2 = self.get_White_Prisoners()
                        self.update_Black_Prisoners.emit(m1);
                        self.update_White_Prisoners.emit(m2);
                    else:
                        # If it does not kill the other party or has gas, it is judged that there is no gas, and a warning box is displayed
                        self.positions[y][x] = 0
                        self.pieces[y][x].clear()
                        self.showwarningbox('Suicide Rule', "You're surrounded!")
                else:
                    # Previous game states are not allowed.
                    self.positions[y][x] = 0
                    self.pieces[y][x].clear()
                    self.recover(deadlist, (1 if self.present == 0 else 0))
                    self.showwarningbox("KO Rule", "Previous game states are not allowed!")

    # Warning message box that accepts the title and warning message
    def showwarningbox(self, title, message):
        msg_box =QMessageBox.warning(self, title, message)

    # Restore position list list_to_recover for the chess pieces specified by b_or_w
    def recover(self, list_to_recover, b_or_w):
        if len(list_to_recover) > 0:
            for i in range(len(list_to_recover)):
                self.positions[list_to_recover[i][1]][list_to_recover[i][0]] = b_or_w + 1
                self.photoWBD_list = [self.BDpixmap, self.WDpixmap]
                self.pieces[list_to_recover[i][1]][list_to_recover[i][0]].setPixmap(self.photoWBD_list[b_or_w])
                self.setCursor(QCursor(self.BDpixmap));
                x, y = self.coordinate_transform_map2pixel(list_to_recover[i][1], list_to_recover[i][0])
                self.pieces[list_to_recover[i][1]][list_to_recover[i][0]].setGeometry(x + 16, y + 16, 69, 72)

    def if_dead(self, deadList, yourChessman, yourPosition):
        for i in [-1, 1]:
            if [yourPosition[0] + i, yourPosition[1]] not in deadList:
                if self.positions[yourPosition[1]][yourPosition[0] + i] == 0:
                    return False
            if [yourPosition[0], yourPosition[1] + i] not in deadList:
                if self.positions[yourPosition[1] + i][yourPosition[0]] == 0:
                    return False
        if ([yourPosition[0] + 1, yourPosition[1]] not in deadList) and (
                self.positions[yourPosition[1]][yourPosition[0] + 1] == yourChessman):
            midvar = self.if_dead(deadList + [[yourPosition[0] + 1, yourPosition[1]]], yourChessman,
                                  [yourPosition[0] + 1, yourPosition[1]])
            if not midvar:
                return False
            else:
                deadList += copy.deepcopy(midvar)
        if ([yourPosition[0] - 1, yourPosition[1]] not in deadList) and (
                self.positions[yourPosition[1]][yourPosition[0] - 1] == yourChessman):
            midvar = self.if_dead(deadList + [[yourPosition[0] - 1, yourPosition[1]]], yourChessman,
                                  [yourPosition[0] - 1, yourPosition[1]])
            if not midvar:
                return False
            else:
                deadList += copy.deepcopy(midvar)
        if ([yourPosition[0], yourPosition[1] + 1] not in deadList) and (
                self.positions[yourPosition[1] + 1][yourPosition[0]] == yourChessman):
            midvar = self.if_dead(deadList + [[yourPosition[0], yourPosition[1] + 1]], yourChessman,
                                  [yourPosition[0], yourPosition[1] + 1])
            if not midvar:
                return False
            else:
                deadList += copy.deepcopy(midvar)
        if ([yourPosition[0], yourPosition[1] - 1] not in deadList) and (
                self.positions[yourPosition[1] - 1][yourPosition[0]] == yourChessman):
            midvar = self.if_dead(deadList + [[yourPosition[0], yourPosition[1] - 1]], yourChessman,
                                  [yourPosition[0], yourPosition[1] - 1])
            if not midvar:
                return False
            else:
                deadList += copy.deepcopy(midvar)
        return deadList



    # After the move, determine in turn whether any of the surrounding pieces have been killed, and return a list of dead chess positions
    def get_deadlist(self, x, y):
        deadlist = []
        for i in [-1, 1]:
            if self.positions[y][x + i] == (2 if self.present == 0 else 1) and ([x + i, y] not in deadlist):
                killList = self.if_dead([[x + i, y]], (2 if self.present == 0 else 1), [x + i, y])
                if not killList == False:
                    deadlist += copy.deepcopy(killList)
            if self.positions[y + i][x] == (2 if self.present == 0 else 1) and ([x, y + i] not in deadlist):
                killList = self.if_dead([[x, y + i]], (2 if self.present == 0 else 1), [x, y + i])
                if not killList == False:
                    deadlist += copy.deepcopy(killList)
        return deadlist

    # Kill the pawns in the position list killList by deleting the picture and setting the position value to 0
    def kill(self, killList):
        if len(killList) > 0:
            for i in range(len(killList)):
                self.positions[killList[i][1]][killList[i][0]] = 0
                self.pieces[killList[i][1]][killList[i][0]].clear()

    def draw(self, i, j):
        x, y = self.coordinate_transform_map2pixel(i, j)
        if self.present == 0:
            self.pieces[i][j].setPixmap(self.BDpixmap)  # Placing black chess pieces
            self.present = 1
            self.setCursor(QCursor(self.WDpixmap));
            self.positions[i][j]=1
        else:
            self.pieces[i][j].setPixmap(self.WDpixmap)  # Placing white chess pieces
            self.present = 0
            self.positions[i][j]=2
            self.setCursor(QCursor(self.BDpixmap));
        self.pieces[i][j].setGeometry(x+16, y+16, 69, 72)  # Draw the chess pieces
        self.counter=120

    def coordinate_transform_map2pixel(self, i, j):
        # chessMap The transformation of the logical coordinates in the map to the drawing coordinates on the UI
        return  (j-1) * self.squareWidth() ,  (i-1) * self.squareWidth()
    def coordinate_transform_pixel2map(self, x, y):
        # Conversion from drawing coordinates on the UI to logical coordinates in chessMap
        i, j = int(round((float(x)-50 ) / self.squareWidth())+1), int(round((float(y)-50 ) / self.squareWidth())+1)
        # We have MAGIN, which excludes the edge position causing i and j to cross the boundary
        if i < 0 or i >= 8 or j < 0 or j >= 8:
            return -1, -1
        else:
            return i, j

    def resetGame(self):
        '''clears pieces from the board'''
        self.counter = 120
        self.regretchance = 0
        self.pieces = [[LaBel(self) for i in range(9)] for j in range(9)]
        for i in range(9):
            for j in range(9):

                self.pieces[i][j].setVisible(True)
                self.pieces[i][j].setScaledContents(True)
        # # Over boundary: -1, no child: 0, Black: 1, White: 2
        self.positions = [[0 for i in range(9)] for i in range(9)]
        for m in range(9):
            for n in range(9):
                if (m * n == 0 or m == 8 or n == 8):
                    self.positions[m][n] = -1


    def resetGame1(self):
        '''clears pieces from the board'''
        self.counter = 120
        self.regretchance = 0
        for i in range(9):
            for j in range(9):
                self.pieces[i][j].clear()
        self.positions = [[0 for i in range(9)] for i in range(9)]
        for m in range(9):
            for n in range(9):
                if (m * n == 0 or m == 8 or n == 8):
                    self.positions[m][n] = -1
        self.present=0
        self.setCursor(QCursor(self.BDpixmap));
        for m in range (9):
            for n in range(9):
                self.last_3_positions[m][n] = 0
                self.last_2_positions[m][n] = 0
                self.last_1_positions[m][n] = 0
    def tryMove(self, newX, newY):
        '''tries to move a piece'''

    def drawBoardSquares(self, painter):
        '''draw all the square on the board'''
        painter.setBrush(QColor(197, 28, 81, 128))
        for row in range(0, Board.boardHeight):
            for col in range(0, Board.boardWidth):
                painter.save()
                colTransformation = self.squareWidth() * col
                rowTransformation = self.squareWidth() * row
        painter.translate(0,0)
        painter.fillRect(0, 0, rowTransformation+100, colTransformation+100, QColor(204,85,17, 255))
        for row in range(0, 7):
            pen = QPen()
            pen.setWidth(2)
            painter.setPen(pen)
            painter.drawLine(50, 50 + row * self.squareWidth(), 50+self.squareWidth()*6, 50 + row * self.squareWidth())
            painter.drawLine(50 + row * self.squareWidth(), 50, 50 + row * self.squareWidth(), 50+self.squareWidth()*6)
        pen = QPen()
        pen.setWidth(4)
        painter.setPen(pen)
        painter.drawLine(50 , 50, 50 + 6 * self.squareWidth(), 50 )
        painter.drawLine(50, 50 , 50, 50 + 6 * self.squareWidth())
        painter.drawLine(50 + 6 * self.squareWidth(), 50, 50 + 6 * self.squareWidth(), 50 + self.squareWidth() * 6)
        painter.drawLine(50,50 + 6 * self.squareWidth(), 50 + 6 * self.squareWidth(), 50 + self.squareWidth() * 6)
        painter.drawLine( 50 + 4 * self.squareWidth(),50, 50 + 4 * self.squareWidth(), 50 + self.squareWidth() * 6)
        painter.drawLine( 50, 50 + 4 * self.squareWidth(), 50 + self.squareWidth() * 6,50 + 4 * self.squareWidth())
        painter.drawLine(50, 50 + 2 * self.squareWidth(), 50 + self.squareWidth() * 6, 50 + 2 * self.squareWidth())
        painter.drawLine(50 + self.squareWidth()*2,50, 50 + self.squareWidth()*2, 50 + self.squareWidth() * 6 )
        painter.restore()

    def drawPieces(self, painter):
        '''draw the prices on the board'''
        colour = Qt.GlobalColor.transparent  # empty square could be modeled with transparent pieces
        for row in range(0, len(self.positions)):
            for col in range(0, len(self.positions[0])):
                painter.save()
                painter.translate(50, 50)
                radius = self.squareWidth() / 3
                center = QPointF(0, 0)
                painter.setBrush(QColor(0, 0, 0))
                painter.drawEllipse(center, radius, radius)
                painter.translate(self.squareWidth(), self.squareWidth())
                painter.drawEllipse(center, radius, radius)
                painter.setBrush(QColor(255, 255, 255))
                painter.translate(self.squareWidth(), 0)
                painter.drawEllipse(center, radius, radius)
                painter.translate(0, self.squareWidth())
                painter.drawEllipse(center, radius, radius)
                painter.restore()
    def make_connection(self, score_board):
        '''this handles a signal sent from the score_board class'''
        score_board.RepentanceSignal.connect(self.setRepentance)
        score_board.ResetSignal.connect(self.setReset)
        score_board.PassSignal.connect(self.setPass)

    @pyqtSlot(int)
    def setRepentance(self, t):
        '''updates the time remaining label to show the time remaining'''
        self.Repentancep=t;


    @pyqtSlot(int)
    def setReset(self, t):
        '''updates the time remaining label to show the time remaining'''
        self.Resetp = t;

    @pyqtSlot(int)
    def setPass(self, t):
        '''updates the time remaining label to show the time remaining'''
        self.Passp=t;

 2. _init_.py
  空
 3. _main_.py
 

```python
from PyQt6.QtWidgets import QApplication
from go import Go
import sys

app = QApplication([])
myGo = Go()
sys.exit(app.exec())

  1. game_logic.py
 class GameLogic:
    print("Game Logic Object Created")
    # TODO add code here to manage the logic of your game
  1. go.py
from PyQt6.QtGui import QIcon, QAction
from PyQt6.QtWidgets import QMainWindow, QMessageBox
from PyQt6.QtCore import Qt
from board import Board
from score_board import ScoreBoard

class Go(QMainWindow):

    def __init__(self):
        super().__init__()
        self.initUI()

    def getBoard(self):
        return self.board

    #def getScoreBoard(self):
    #    return self.scoreBoard

    def initUI(self):
        '''initiates application UI'''
        self.board = Board(self)
        self.setCentralWidget(self.board)
        self.scoreBoard = ScoreBoard()
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.scoreBoard)
        self.scoreBoard.make_connection(self.board)
        self.board.make_connection(self.scoreBoard)
        self.resize(880, 750)
        self.center()
        self.setWindowTitle('Go')
        self.setWindowIcon(QIcon("./sh.jpg"))
        self.show()
    def center(self):
        '''centers the window on the screen'''
        gr = self.frameGeometry()
        screen = self.screen().availableGeometry().center()

        gr.moveCenter(screen)
        self.move(gr.topLeft())
        size = self.geometry()
        #self.move((screen.width() - size.width()) / 2,(screen.height() - size.height()) / 2)

  1. piece.py
# TODO: Add more functions as needed for your Pieces
class Piece(object):
    NoPiece = 0
    White = 1
    Black = 2
    Status = 0 #default to nopiece
    liberties = 0 #default no liberties
    x = -1
    y= -1

    def __init__(self, Piece,x,y):  #constructor
        self.Status = Piece
        self.liberties = 0
        self.x = x
        self.y = y

    def getPiece(self): # return PieceType
        return self.Status

    def getLiberties(self): # return Liberties
        self.libs = self.liberties
        return self.libs

    def setLiberties(self,liberties): # set Liberties
        self.liberties = liberties
  1. score_board.py
from PyQt6.QtWidgets import QDockWidget, QVBoxLayout, QWidget, QLabel, QPushButton, QMessageBox
from PyQt6.QtCore import pyqtSlot, pyqtSignal


class ScoreBoard(QDockWidget):
    '''# base the score_board on a QDockWidget'''
    RepentanceSignal = pyqtSignal(int)  # signal sent when timer is updated
    ResetSignal = pyqtSignal(int)
    PassSignal = pyqtSignal(int)  # signal sent when there is a new click location
    #self.updateTSignal.emit(clickLoc)
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        '''initiates ScoreBoard UI'''
        self.resize(100, 100)
        self.center()

        self.setWindowTitle('ScoreBoard')
        #create a widget to hold other widgets
        self.mainWidget = QWidget()
        self.mainLayout = QVBoxLayout()

        #create labels which will be updated by signals
        self.start = QPushButton("Start")
        self.mainLayout.addWidget(self.start)
        # self.start.clicked.connect(self.show_message_word)
        self.Pass = QPushButton("Pass")
        self.mainLayout.addWidget(self.Pass)
        self.Reset = QPushButton("Reset")
        self.mainLayout.addWidget(self.Reset)
        self.Repentance = QPushButton("Redo")
        self.mainLayout.addWidget(self.Repentance)
        self.Rule = QPushButton("Rule")
        self.mainLayout.addWidget(self.Rule)
        # self.start.clicked.connect(self.show_message_word)
        # self.start.clicked.connect(self.show_message_word)
        self.label_clickLocation1 = QLabel("Click Location:")
        self.label_clickLocation = QLabel("[0,0]")
        self.label_timeRemaining1 = QLabel("Time Remaining:")
        self.label_timeRemaining = QLabel("Time:")
        self.label_black_prisoners = QLabel("Black:")
        self.label_white_prisoners = QLabel("White:")
        self.mainWidget.setLayout(self.mainLayout)
        self.mainLayout.addWidget(self.label_clickLocation1)
        self.mainLayout.addWidget(self.label_clickLocation)
        self.mainLayout.addWidget(self.label_timeRemaining1)

        self.mainLayout.addWidget(self.label_timeRemaining)
        self.mainLayout.addWidget(self.label_black_prisoners)
        self.mainLayout.addWidget(self.label_white_prisoners)

        self.mainLayout.addStretch()
        self.setWidget(self.mainWidget)
        self.show()
        self.Repentance.clicked.connect(self.Repentancef)
        self.Reset.clicked.connect(self.Resetf)
        self.Pass.clicked.connect(self.Passf)
        self.Rule.clicked.connect(self.show_message_Rule)

    def Repentancef(self):
        self.RepentanceSignal.emit(1)

    def Resetf(self):
        self.ResetSignal.emit(1)

    def Passf(self):
        self.PassSignal.emit(1)

    def show_message_Rule(self):
        QMessageBox.about(self, "Rule",
                          "There  are  only  three  basic  rules  of  the  Go  Game :"+'\n'+"1. Both sides take turns to play chess, and black plays first; It cannot be placed on a grid that already has a chess piece."+'\n'+"2. A piece of chess (up and down, left and right, diagonal is not counted) completely surrounded by the opponent (adjacent upper and lower left and right squares are occupied), it will be eaten and taken from the board. "+'\n'+"3. At the time of final settlement, the territory occupied by black chess + the number of surviving children, if there are 4.5 or more more pieces than white chess, it wins. When calculating, the number of sub-children who eat the other party is counted in the sub-number of the local square.")

    def center(self):
        '''centers the window on the screen, you do not need to implement this method'''

    def make_connection(self, board):
        '''this handles a signal sent from the board class'''
        # when the clickLocationSignal is emitted in board the setClickLocation slot receives it
        board.clickLocationSignal.connect(self.setClickLocation)
        # when the updateTimerSignal is emitted in the board the setTimeRemaining slot receives it
        board.updateTimerSignal.connect(self.setTimeRemaining)
        board.update_Black_Prisoners.connect(self.setBlack_Prisoners)
        board.update_White_Prisoners.connect(self.setWhite_Prisoners)

    @pyqtSlot(str) # checks to make sure that the following slot is receiving an argument of the type 'int'
    def setClickLocation(self, clickLoc):
        '''updates the label to show the click location'''
        self.label_clickLocation.setText(clickLoc)

    @pyqtSlot(int)
    def setTimeRemaining(self, timeRemainng):
        '''updates the time remaining label to show the time remaining'''
        update = str(timeRemainng)+' s'
        self.label_timeRemaining.setText(update)

    @pyqtSlot(int)
    def setBlack_Prisoners(self, Black):
        '''updates the Black Prisoners label to show the Black Prisoners'''
        update = "Black: " + str(Black)
        self.label_black_prisoners.setText(update)

    @pyqtSlot(int)
    def setWhite_Prisoners(self, White):
        '''updates the Black Prisoners label to show the Black Prisoners'''
        update = "White:" + str(White)
        self.label_white_prisoners.setText(update)

WD-7.png
请添加图片描述
BD_7.png
请添加图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值