python+pyqt5实现实现24点小游戏点小游戏
本文实例为大家分享了python实现24点游戏的具体代码,供大家参考,具体内容如下
描述:一副牌中A、J、Q、K可以当成是1、11、12、13。任意抽取4张牌,用加、减、乘、除(可加括号)把牌面上的数算成24。每
张牌对应的数字必须用一次且只能用一次。在规定时间内输入算式,输入正确加十分,输入错误生命值减一,点击确定提交并进入下
一题,点击清空可清空算式。点击开始游戏进入游戏,可重新开始游戏。
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QBasicTimer
from PyQt5.QtGui import QPixmap
import sys
class Ui_Form(QWidget):
def setupUi(self,Form):
Form.setObjectName("Form")
Form.resize(946, 515)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(70, 30, 131, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.on_click1)
self.pushButton_4 = QtWidgets.QPushButton(Form)
self.pushButton_4.setGeometry(QtCore.QRect(280, 30, 131, 41))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_4.clicked.connect(self.on_click4)
self.pushButton_4.setEnabled(False)
self.textEdit = QtWidgets.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(700, 120, 191, 301))
self.textEdit.setObjectName("textEdit")
self.textEdit.setReadOnly(True)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(70, 300, 111, 31))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(170, 300, 361, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setMaxLength(15)
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(70, 100, 101, 171))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(220, 100, 101, 171))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Form)
self.label_4.setGeometry(QtCore.QRect(370, 100, 101, 171))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Form)
self.label_5.setGeometry(QtCore.QRect(510, 100, 101, 171))
self.label_5.setObjectName("label_5")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(170, 360, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.clicked.connect(self.on_click2)
self.pushButton_3 = QtWidgets.QPushButton(Form)
self.pushButton_3.setGeometry(QtCore.QRect(300, 360, 93, 28))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_3.clicked.connect(self.on_click3)
self.progressBar = QtWidgets.QProgressBar(Form)
self.progressBar.setGeometry(QtCore.QRect(170, 430, 401, 21))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.timer = QBasicTimer()
self.step = 0
self.retranslateUi(Form)