DDR爱好者之家 Design By 杰米
本文介绍的是利用pyqt5实现井字棋,下面话不多说了,来一起看看详细的介绍
作者:袁少泽
代码如下(示例):
import random import sys import time from PyQt5.QtCore import * from PyQt5.QtWidgets import * start=time.time() class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(415, 346) self.label_3 = QtWidgets.QLabel(Form) self.label_3.setGeometry(QtCore.QRect(30, 290, 241, 20)) self.label_3.setObjectName("label_3") self.pushButton_10 = QtWidgets.QPushButton(Form) self.pushButton_10.setGeometry(QtCore.QRect(210, 310, 75, 23)) self.pushButton_10.setCheckable(False) self.pushButton_10.setDefault(False) self.pushButton_10.setObjectName("pushButton_10") self.label_2 = QtWidgets.QLabel(Form) self.label_2.setGeometry(QtCore.QRect(20, 260, 241, 20)) self.label_2.setObjectName("label_2") self.label = QtWidgets.QLabel(Form) self.label.setGeometry(QtCore.QRect(290, 10, 111, 31)) self.label.setObjectName("label") self.layoutWidget = QtWidgets.QWidget(Form) self.layoutWidget.setGeometry(QtCore.QRect(70, 40, 191, 191)) self.layoutWidget.setObjectName("layoutWidget") self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setObjectName("gridLayout") self.pushButton = QtWidgets.QPushButton(self.layoutWidget) self.pushButton.setEnabled(True) self.pushButton.setToolTip("") self.pushButton.setText("") self.pushButton.setObjectName("pushButton") self.gridLayout.addWidget(self.pushButton, 0, 0, 1, 1) self.pushButton_4 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_4.setText("") self.pushButton_4.setObjectName("pushButton_4") self.gridLayout.addWidget(self.pushButton_4, 0, 1, 1, 1) self.pushButton_7 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_7.setEnabled(True) self.pushButton_7.setText("") self.pushButton_7.setObjectName("pushButton_7") self.gridLayout.addWidget(self.pushButton_7, 0, 2, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_2.setText("") self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 1, 0, 1, 1) self.pushButton_5 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_5.setText("") self.pushButton_5.setObjectName("pushButton_5") self.gridLayout.addWidget(self.pushButton_5, 1, 1, 1, 1) self.pushButton_8 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_8.setText("") self.pushButton_8.setObjectName("pushButton_8") self.gridLayout.addWidget(self.pushButton_8, 1, 2, 1, 1) self.pushButton_3 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_3.setText("") self.pushButton_3.setObjectName("pushButton_3") self.gridLayout.addWidget(self.pushButton_3, 2, 0, 1, 1) self.pushButton_6 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_6.setText("") self.pushButton_6.setObjectName("pushButton_6") self.gridLayout.addWidget(self.pushButton_6, 2, 1, 1, 1) self.pushButton_9 = QtWidgets.QPushButton(self.layoutWidget) self.pushButton_9.setText("") self.pushButton_9.setObjectName("pushButton_9") self.gridLayout.addWidget(self.pushButton_9, 2, 2, 1, 1) self.label_4 = QtWidgets.QLabel(Form) self.label_4.setGeometry(QtCore.QRect(70, 10, 131, 21)) self.label_4.setObjectName("label_4") self.pushButton_11 = QtWidgets.QPushButton(Form) self.pushButton_11.setGeometry(QtCore.QRect(300, 310, 75, 23)) self.pushButton_11.setObjectName("pushButton_11") self.retranslateUi(Form) self.pushButton_11.clicked.connect(Form.close) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.label_3.setText(_translate("Form", "TextLabel")) self.pushButton_10.setText(_translate("Form", "重新开始")) self.label_2.setText(_translate("Form", "TextLabel")) self.label.setText(_translate("Form", "TextLabel")) self.label_4.setText(_translate("Form", "TextLabel")) self.pushButton_11.setText(_translate("Form", "退出")) from PyQt5 import QtCore, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(294, 167) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(110, 20, 161, 31)) self.label.setObjectName("label") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(50, 80, 75, 23)) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_2.setGeometry(QtCore.QRect(180, 80, 75, 23)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_3.setGeometry(QtCore.QRect(270, 10, 21, 23)) self.pushButton_3.setObjectName("pushButton_3") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) self.pushButton_3.clicked.connect(MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "井字棋-模式选择")) self.label.setText(_translate("MainWindow", "模式选择")) self.pushButton.setText(_translate("MainWindow", "双人")) self.pushButton_2.setText(_translate("MainWindow", "单人")) self.pushButton_3.setText(_translate("MainWindow", "X")) class QIPAN(): def __init__(self): self.qi11 = ' ' self.qi12 = ' ' self.qi13 = ' ' self.qi21 = ' ' self.qi22 = ' ' self.qi23 = ' ' self.qi31 = ' ' self.qi32 = ' ' self.qi33 = ' ' qipan = QIPAN() class danren(QWidget): def __init__(self): super(danren, self).__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle('单人模式') self.initUI() self.ui.label_4.setText("单人模式") self.time = 0 self.setWindowFlags(QtCore.Qt.CustomizeWindowHint)### def initUI(self): self.ui.pushButton.setText(qipan.qi11) self.ui.pushButton_2.setText(qipan.qi12) self.ui.pushButton_3.setText(qipan.qi13) self.ui.pushButton_4.setText(qipan.qi21) self.ui.pushButton_5.setText(qipan.qi22) self.ui.pushButton_6.setText(qipan.qi23) self.ui.pushButton_7.setText(qipan.qi31) self.ui.pushButton_8.setText(qipan.qi32) self.ui.pushButton_9.setText(qipan.qi33) self.ui.pushButton.setToolTip('pushButton/qi11') self.ui.pushButton_2.setToolTip('pushButton_2/qi12') self.ui.pushButton_3.setToolTip('pushButton_3/qi13') self.ui.pushButton_4.setToolTip('pushButton_4/qi21') self.ui.pushButton_5.setToolTip('pushButton_5/qi22') self.ui.pushButton_6.setToolTip('pushButton_6/qi23') self.ui.pushButton_7.setToolTip('pushButton_7/qi31') self.ui.pushButton_8.setToolTip('pushButton_8/qi32') self.ui.pushButton_9.setToolTip('pushButton_9/qi33') self.ui.label.setText('') self.ui.label_2.setText('当前为O玩家VS电脑') self.ui.label_3.setText('') self.timer = QTimer() self.timer.timeout.connect(self.showtime) self.startTimer() self.CONNECT() def CONNECT(self): self.ui.pushButton.clicked.connect(self.change) self.ui.pushButton_2.clicked.connect(self.change2) self.ui.pushButton_3.clicked.connect(self.change3) self.ui.pushButton_4.clicked.connect(self.change4) self.ui.pushButton_5.clicked.connect(self.change5) self.ui.pushButton_6.clicked.connect(self.change6) self.ui.pushButton_7.clicked.connect(self.change7) self.ui.pushButton_8.clicked.connect(self.change8) self.ui.pushButton_9.clicked.connect(self.change9) self.ui.pushButton.clicked.connect(self.PANDUAN) self.ui.pushButton_2.clicked.connect(self.PANDUAN) self.ui.pushButton_3.clicked.connect(self.PANDUAN) self.ui.pushButton_4.clicked.connect(self.PANDUAN) self.ui.pushButton_5.clicked.connect(self.PANDUAN) self.ui.pushButton_6.clicked.connect(self.PANDUAN) self.ui.pushButton_7.clicked.connect(self.PANDUAN) self.ui.pushButton_8.clicked.connect(self.PANDUAN) self.ui.pushButton_9.clicked.connect(self.PANDUAN) self.ui.pushButton_10.clicked.connect(self.HUANYUAN) self.ui.pushButton_11.clicked.connect(self.HUANYUAN) def change(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton.setText(a) else: a = "O" self.ui.pushButton.setText(a) self.ui.pushButton.setEnabled(False) if self.time < 9: self.suiji() def change2(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_2.setText(a) else: a = "O" self.ui.pushButton_2.setText(a) self.ui.pushButton_2.setEnabled(False) if self.time < 9: self.suiji() def change3(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_3.setText(a) else: a = "O" self.ui.pushButton_3.setText(a) self.ui.pushButton_3.setEnabled(False) if self.time<9: self.suiji() def change4(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_4.setText(a) else: a = "O" self.ui.pushButton_4.setText(a) self.ui.pushButton_4.setEnabled(False) if self.time < 9: self.suiji() def change5(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_5.setText(a) else: a = "O" self.ui.pushButton_5.setText(a) self.ui.pushButton_5.setEnabled(False) if self.time < 9: self.suiji() def change6(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_6.setText(a) else: a = "O" self.ui.pushButton_6.setText(a) self.ui.pushButton_6.setEnabled(False) if self.time < 9: self.suiji() def change7(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_7.setText(a) else: a = "O" self.ui.pushButton_7.setText(a) self.ui.pushButton_7.setEnabled(False) if self.time<9: self.suiji() def change8(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_8.setText(a) else: a = "O" self.ui.pushButton_8.setText(a) self.ui.pushButton_8.setEnabled(False) if self.time<9: self.suiji() def change9(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton_9.setText(a) else: a = "O" self.ui.pushButton_9.setText(a) self.ui.pushButton_9.setEnabled(False) if self.time<9: self.suiji() def showtime(self): end = time.time() self.ui.label.setText(f'游戏开始{int(end - start)}秒') def PANDUAN(self): if self.time<9: if ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_7.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_6.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton_3.text() == 'X' and self.ui.pushButton_6.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X'): self.ui.label_3.setText("电脑获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time=0 elif ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_2.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_7.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_9.text() == 'O') or ( self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_6.text() == 'O') or ( self.ui.pushButton_7.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_3.text() == 'O' and self.ui.pushButton_6.text() == 'O' and self.ui.pushButton_9.text() == 'O'): self.ui.label_3.setText("O玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time=0 else: self.ui.label_3.setText("暂未分出胜负") elif self.time==9: if ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_7.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_6.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton_3.text() == 'X' and self.ui.pushButton_6.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X'): self.ui.label_3.setText("X玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time=0 elif ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_2.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_7.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_9.text() == 'O') or ( self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_6.text() == 'O') or ( self.ui.pushButton_7.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_3.text() == 'O' and self.ui.pushButton_6.text() == 'O' and self.ui.pushButton_9.text() == 'O'): self.ui.label_3.setText("O玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time=0 else: self.ui.label_3.setText("平局") self.time=0 def HUANYUAN(self): self.ui.label_2.setText('当前为O玩家回合') self.ui.pushButton.setText(qipan.qi11) self.ui.pushButton_2.setText(qipan.qi12) self.ui.pushButton_3.setText(qipan.qi13) self.ui.pushButton_4.setText(qipan.qi21) self.ui.pushButton_5.setText(qipan.qi22) self.ui.pushButton_6.setText(qipan.qi23) self.ui.pushButton_7.setText(qipan.qi31) self.ui.pushButton_8.setText(qipan.qi32) self.ui.pushButton_9.setText(qipan.qi33) self.ui.pushButton.setEnabled(True) self.ui.pushButton_2.setEnabled(True) self.ui.pushButton_3.setEnabled(True) self.ui.pushButton_4.setEnabled(True) self.ui.pushButton_5.setEnabled(True) self.ui.pushButton_6.setEnabled(True) self.ui.pushButton_7.setEnabled(True) self.ui.pushButton_8.setEnabled(True) self.ui.pushButton_9.setEnabled(True) self.time=0 def suiji(self): Truelabel=[] labels=[self.ui.pushButton,self.ui.pushButton_2,self.ui.pushButton_3, self.ui.pushButton_4,self.ui.pushButton_5,self.ui.pushButton_6, self.ui.pushButton_7,self.ui.pushButton_8,self.ui.pushButton_9] for label in labels: if label.isEnabled()==True: Truelabel.append(label) luckylabel=random.choice(Truelabel) if luckylabel==self.ui.pushButton: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" self.ui.pushButton.setText(a) else: a = "O" self.ui.pushButton.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton.setEnabled(False) self.PANDUAN() elif luckylabel==self.ui.pushButton_2: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_2.setText(a) else: a = "O" b = 'X' self.ui.pushButton_2.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_2.setEnabled(False) self.PANDUAN() elif luckylabel == self.ui.pushButton_3: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_3.setText(a) else: a = "O" b = 'X' self.ui.pushButton_3.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_3.setEnabled(False) self.PANDUAN() elif luckylabel==self.ui.pushButton_4: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_4.setText(a) else: a = "O" b = 'X' self.ui.pushButton_4.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_4.setEnabled(False) self.PANDUAN() elif luckylabel==self.ui.pushButton_5: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = "O" self.ui.pushButton_5.setText(a) else: a = "O" b = "X" self.ui.pushButton_5.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_5.setEnabled(False) self.PANDUAN() elif luckylabel==self.ui.pushButton_6: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_6.setText(a) else: a = "O" b = "X" self.ui.pushButton_6.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_6.setEnabled(False) self.PANDUAN() elif luckylabel==self.ui.pushButton_7: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_7.setText(a) else: a = "O" b = 'X' self.ui.pushButton_7.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_7.setEnabled(False) self.PANDUAN() elif luckylabel == self.ui.pushButton_8: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_8.setText(a) else: a = "O" b = 'X' self.ui.pushButton_8.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_8.setEnabled(False) self.PANDUAN() elif luckylabel == self.ui.pushButton_9: self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_9.setText(a) else: a = "O" b = 'X' self.ui.pushButton_9.setText(a) self.ui.label_2.setText('当前为o玩家VS电脑') self.ui.pushButton_9.setEnabled(False) self.PANDUAN() def startTimer(self): self.timer.start(1000) class shuangren(QWidget): def __init__(self): super(shuangren, self).__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle('双人模式') self.ui.label_4.setText("双人模式") self.ui.pushButton_11.clicked.connect(self.HUANYUAN) self.initUI() self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) def initUI(self): self.ui.pushButton.setText(qipan.qi11) self.ui.pushButton_2.setText(qipan.qi12) self.ui.pushButton_3.setText(qipan.qi13) self.ui.pushButton_4.setText(qipan.qi21) self.ui.pushButton_5.setText(qipan.qi22) self.ui.pushButton_6.setText(qipan.qi23) self.ui.pushButton_7.setText(qipan.qi31) self.ui.pushButton_8.setText(qipan.qi32) self.ui.pushButton_9.setText(qipan.qi33) self.ui.pushButton.setToolTip('pushButton/qi11') self.ui.pushButton_2.setToolTip('pushButton_2/qi12') self.ui.pushButton_3.setToolTip('pushButton_3/qi13') self.ui.pushButton_4.setToolTip('pushButton_4/qi21') self.ui.pushButton_5.setToolTip('pushButton_5/qi22') self.ui.pushButton_6.setToolTip('pushButton_6/qi23') self.ui.pushButton_7.setToolTip('pushButton_7/qi31') self.ui.pushButton_8.setToolTip('pushButton_8/qi32') self.ui.pushButton_9.setToolTip('pushButton_9/qi33') self.ui.label.setText('') self.ui.label_2.setText('当前为O玩家回合') self.ui.label_3.setText('') self.timer = QTimer() self.timer.timeout.connect(self.showtime) self.startTimer() self.bangding() def bangding(self): self.ui.pushButton.clicked.connect(self.change) self.ui.pushButton_2.clicked.connect(self.change2) self.ui.pushButton_3.clicked.connect(self.change3) self.ui.pushButton_4.clicked.connect(self.change4) self.ui.pushButton_5.clicked.connect(self.change5) self.ui.pushButton_6.clicked.connect(self.change6) self.ui.pushButton_7.clicked.connect(self.change7) self.ui.pushButton_8.clicked.connect(self.change8) self.ui.pushButton_9.clicked.connect(self.change9) self.ui.pushButton.clicked.connect(self.PANDUAN) self.ui.pushButton_2.clicked.connect(self.PANDUAN) self.ui.pushButton_3.clicked.connect(self.PANDUAN) self.ui.pushButton_4.clicked.connect(self.PANDUAN) self.ui.pushButton_5.clicked.connect(self.PANDUAN) self.ui.pushButton_6.clicked.connect(self.PANDUAN) self.ui.pushButton_7.clicked.connect(self.PANDUAN) self.ui.pushButton_8.clicked.connect(self.PANDUAN) self.ui.pushButton_9.clicked.connect(self.PANDUAN) self.ui.pushButton_10.clicked.connect(self.HUANYUAN) self.time = 0 def change(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton.setText(a) else: a = "O" b = 'X' self.ui.pushButton.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton.setEnabled(False) def change2(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_2.setText(a) else: a = "O" b = 'X' self.ui.pushButton_2.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_2.setEnabled(False) def change3(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_3.setText(a) else: a = "O" b = 'X' self.ui.pushButton_3.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_3.setEnabled(False) def change4(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_4.setText(a) else: a = "O" b = 'X' self.ui.pushButton_4.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_4.setEnabled(False) def change5(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = "O" self.ui.pushButton_5.setText(a) else: a = "O" b = "X" self.ui.pushButton_5.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_5.setEnabled(False) def change6(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_6.setText(a) else: a = "O" b = "X" self.ui.pushButton_6.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_6.setEnabled(False) def change7(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_7.setText(a) else: a = "O" b = 'X' self.ui.pushButton_7.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_7.setEnabled(False) def change8(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_8.setText(a) else: a = "O" b = 'X' self.ui.pushButton_8.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_8.setEnabled(False) def change9(self): self.time = self.time + 1 if (self.time + 2) % 2 == 0: a = "X" b = 'O' self.ui.pushButton_9.setText(a) else: a = "O" b = 'X' self.ui.pushButton_9.setText(a) self.ui.label_2.setText(f'当前为{b}玩家回合') self.ui.pushButton_9.setEnabled(False) def showtime(self): end = time.time() self.ui.label.setText(f'游戏开始{int(end - start)}秒') def PANDUAN(self): if self.time < 9: if ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_7.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_6.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton_3.text() == 'X' and self.ui.pushButton_6.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X'): self.ui.label_3.setText("X玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time = 0 elif ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_2.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_7.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_9.text() == 'O') or ( self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_6.text() == 'O') or ( self.ui.pushButton_7.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_3.text() == 'O' and self.ui.pushButton_6.text() == 'O' and self.ui.pushButton_9.text() == 'O'): self.ui.label_3.setText("O玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time = 0 else: self.ui.label_3.setText("暂未分出胜负") elif self.time == 9: if ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_7.text() == 'X') or ( self.ui.pushButton.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_4.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_6.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_3.text() == 'X') or ( self.ui.pushButton_3.text() == 'X' and self.ui.pushButton_6.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X'): self.ui.label_3.setText("X玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time = 0 elif ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_2.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_7.text() == 'O') or ( self.ui.pushButton.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_9.text() == 'O') or ( self.ui.pushButton_4.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_6.text() == 'O') or ( self.ui.pushButton_7.text() == 'O' and self.ui.pushButton_5.text() == 'O' and self.ui.pushButton_3.text() == 'O') or ( self.ui.pushButton_7.text() == 'X' and self.ui.pushButton_8.text() == 'X' and self.ui.pushButton_9.text() == 'X') or ( self.ui.pushButton_2.text() == 'X' and self.ui.pushButton_5.text() == 'X' and self.ui.pushButton_8.text() == 'X') or ( self.ui.pushButton_3.text() == 'O' and self.ui.pushButton_6.text() == 'O' and self.ui.pushButton_9.text() == 'O'): self.ui.label_3.setText("O玩家获胜") self.ui.label_2.setText("结束") self.ui.pushButton.setEnabled(False) self.ui.pushButton_2.setEnabled(False) self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_5.setEnabled(False) self.ui.pushButton_6.setEnabled(False) self.ui.pushButton_7.setEnabled(False) self.ui.pushButton_8.setEnabled(False) self.ui.pushButton_9.setEnabled(False) self.time = 0 else: self.ui.label_3.setText("平局") self.time = 0 def HUANYUAN(self): self.ui.pushButton.setText(qipan.qi11) self.ui.pushButton_2.setText(qipan.qi12) self.ui.pushButton_3.setText(qipan.qi13) self.ui.pushButton_4.setText(qipan.qi21) self.ui.pushButton_5.setText(qipan.qi22) self.ui.pushButton_6.setText(qipan.qi23) self.ui.pushButton_7.setText(qipan.qi31) self.ui.pushButton_8.setText(qipan.qi32) self.ui.pushButton_9.setText(qipan.qi33) self.ui.pushButton.setEnabled(True) self.ui.pushButton_2.setEnabled(True) self.ui.pushButton_3.setEnabled(True) self.ui.pushButton_4.setEnabled(True) self.ui.pushButton_5.setEnabled(True) self.ui.pushButton_6.setEnabled(True) self.ui.pushButton_7.setEnabled(True) self.ui.pushButton_8.setEnabled(True) self.ui.pushButton_9.setEnabled(True) self.ui.label_3.setText("") def startTimer(self): self.timer.start(1000) class MODLECHOSE(QMainWindow): def __init__(self): super(MODLECHOSE,self).__init__() self.ui=Ui_MainWindow() self.ui.setupUi(self) self.ui.pushButton.clicked.connect(self.caoshuang) self.ui.pushButton_2.clicked.connect(self.caodan) self.danwin = danren() self.shuangwin = shuangren() self.setWindowFlags(QtCore.Qt.CustomizeWindowHint)####### def caodan(self): self.danwin.show() def caoshuang(self): self.shuangwin.show() if __name__ == '__main__': app = QApplication(sys.argv) main = MODLECHOSE() main.show() sys.exit(app.exec_())
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年11月24日
2024年11月24日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]