-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
80 lines (60 loc) · 2.28 KB
/
gui.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
import math
import random
import time
from PyQt6.QtWidgets import *
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.wins = 0
self.ties = 0
self.defeats = 0
self.setWindowTitle("Rock, Paper, Scissors")
self.result = QLabel("Press Rock, Paper, or Scissors!")
self.stats = QLabel("See how much you can win!")
self.buttonLayout = QHBoxLayout()
self.rock = QPushButton("Rock")
self.rock.pressed.connect(self.rockCall)
self.paper = QPushButton("Paper")
self.paper.pressed.connect(self.paperCall)
self.scissors = QPushButton("Scissors")
self.scissors.pressed.connect(self.scissorsCall)
self.buttonLayout.addWidget(self.rock)
self.buttonLayout.addWidget(self.paper)
self.buttonLayout.addWidget(self.scissors)
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.result)
self.mainLayout.addWidget(self.stats)
self.mainLayout.addLayout(self.buttonLayout)
self.myWidget = QWidget()
self.myWidget.setLayout(self.mainLayout)
self.setCentralWidget(self.myWidget)
self.show()
def rockCall(self):
self.turnHandler(input="rock")
def paperCall(self):
self.turnHandler(input="paper")
def scissorsCall(self):
self.turnHandler(input="scissors")
def turnHandler(self, input):
botPossible = ["rock", "paper", "scissors"]
botInput = botPossible[math.floor(random.random() * 3)]
if input == botInput:
self.result.setText("It was a tie!")
self.ties += 1
elif input == "paper" and botInput == "rock":
self.result.setText("You won!")
self.wins += 1
elif input == "rock" and botInput == "scissors":
self.result.setText("You won!")
self.wins += 1
elif input == "scissors" and botInput == "paper":
self.result.setText("You won!")
self.wins += 1
else:
self.result.setText("You lost!")
self.defeats += 1
self.stats.setText(f"Wins: {self.wins}; Ties: {self.ties}; Defeats: {self.defeats}; Bot selection: {botInput}")
app = QApplication(sys.argv)
w = MainWindow()
app.exec()