-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
113 lines (76 loc) · 3.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import sys
import random
from PyQt5 import QtWidgets , QtGui , QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from NumberGuessing import Ui_MainWindowNumberGuessing
class UiNumberGuessingForm(QMainWindow):
counter = 0
const = 0
def __init__(self):
QMainWindow.__init__(self)
self.uinumberguessingform = Ui_MainWindowNumberGuessing()
self.uinumberguessingform.setupUi(self)
self.setWindowFlag(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.uinumberguessingform.help_btn.clicked.connect(self.help)
self.btnchecked()
self.btnreset()
self.show()
def mousePressEvent(self, evt):
self.oldpos = evt.globalPos()
def mouseMoveEvent(self, evt) :
delta = QPoint(evt.globalPos() - self.oldpos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldpos = evt.globalPos()
def btnchecked(self):
self.uinumberguessingform.check.clicked.connect(self.checked)
def btnreset(self):
self.uinumberguessingform.reset.clicked.connect(self.reset)
def random(self):
if self.const == 0:
self.start = int(self.uinumberguessingform.start.text())
self.stop = int(self.uinumberguessingform.stop.text())
self.randomnumber = random.randint(self.start, self.stop)
self.const += 1
def checked(self):
self.chances = int(self.uinumberguessingform.chances.text())
if self.const == 0:
self.start = int(self.uinumberguessingform.start.text())
self.stop = int(self.uinumberguessingform.stop.text())
self.randomnumber = random.randint(self.start, self.stop)
self.const += 1
self.counter += 1
self.guessnumber = int(self.uinumberguessingform.yourguess.text())
print(self.const)
print(self.randomnumber) # Prints the number guessed by the program
if self.counter <= self.chances: # Here we check the "chances"
if self.guessnumber > self.randomnumber: # If "guessnumber" was bigger than "randomnumber"
self.uinumberguessingform.Suggestioandresult.setText("Go Down")
elif self.guessnumber < self.randomnumber: # If "randomnumber" was bigger than "guessnumber"
self.uinumberguessingform.Suggestioandresult.setText("Go Up")
elif self.guessnumber == self.randomnumber: # If "guessnumber" was equal to "randomnumber"
self.uinumberguessingform.Suggestioandresult.setText("You Did it Well done !")
elif self.counter > self.chances:
self.uinumberguessingform.Suggestioandresult.setText(f"You lost, you losser ")
def reset(self): # Resets everything
self.const -= 1
self.uinumberguessingform.chances.setText("")
self.uinumberguessingform.start.setText("")
self.uinumberguessingform.stop.setText("")
self.uinumberguessingform.yourguess.setText("")
self.uinumberguessingform.Suggestioandresult.setText("Suggestion and Result")
self.counter = 0
def help(self):
message_box = QtWidgets.QMessageBox()
message_box.setWindowTitle("Developer information")
message_box.setWindowIcon(QtGui.QIcon('royal_lionn.ico'))
message_box.setIcon(QMessageBox.Information)
message_box.setText("Developer : Amin Jafari\n"
"---------------------------------\n"
"Gmail : [email protected]\n")
message_box.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
root = UiNumberGuessingForm()
sys.exit(app.exec_())