How do I Create Rounds For Rock, Paper Scissors Game?

Viewed 38

I've been working on a Rock, Paper Scissors project for python and pyqt6 practice. It's almost done but the problem I have is that I'm trying to implement a three round system. It's not working and when I open the the game menu, it starts at 3 instead of at 1 and work its way up to 3. There's also a picture I've provided where no button has been clicked. Pressing the buttons do not add to it either.

import sys
import random
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QWidget, QStackedWidget, QPushButton, QMenuBar,QStatusBar
from PyQt6 import uic
import time

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        uic.loadUi("gui/RPS start menu.ui",self)

        self.setWindowTitle("Rock Paper Scissors")
        self.startBttn.clicked.connect(self.start_clicked)

    #Changes screen after start button is clicked
    def start_clicked(self):
        w.setCurrentIndex(1)
        

class gameScreen(QMainWindow):
    def __init__(self):
        super(gameScreen, self).__init__()
        uic.loadUi("gui/RPS game.ui",self)
        
        
        global compChoice

        randomChoice = random.randrange(1,4)
        if randomChoice == 1:
            compChoice = "rock"
        elif randomChoice == 2:
            compChoice = "paper"
        elif randomChoice == 3:
            compChoice = "scissors"
            
        rounds = 1
        for rounds in range(3):
            if self.option1.clicked:
                rounds += 1
                self.roundNumber.setText("round {}".format(rounds))
                
        #Calls functions for PC player when one of the buttons are pressed
        self.option1.clicked.connect(self.compRock)
        self.option2.clicked.connect(self.compPaper)
        self.option3.clicked.connect(self.compScissors)


            

    def compRock(self):
        
        self.whatUChose.setText("rock")
        time.sleep(1)
        
        self.whatPCChose.setText(compChoice)

        if compChoice == "rock":
            self.roundWin.setText("It's a tie")
        elif compChoice == "paper":
            self.roundWin.setText("Paper beats rock, you lose")
        elif compChoice == "scissors":
            self.roundWin.setText("Rock beats scissors, you win!")

    
    def compPaper(self):

        self.whatUChose.setText("paper")
        time.sleep(1)
        self.whatPCChose.setText(compChoice)

        if compChoice == "rock":
            self.roundWin.setText("Paper covers rock, you win!")
        elif compChoice == "paper":
            self.roundWin.setText("It's a tie")
        elif compChoice == "scissors":
            self.roundWin.setText("Scissors beats paper, you lose")


    def compScissors(self):

        self.whatUChose.setText("scissors")
        time.sleep(1)        
        self.whatPCChose.setText(compChoice)

        if compChoice == "rock":
            self.roundWin.setText("Rock beats scissors, you lose")
        elif compChoice == "paper":
            self.roundWin.setText("Scissors beats paper, you win!")
        elif compChoice == "scissors":
            self.roundWin.setText("It's a tie")


app = QApplication(sys.argv)

w = QStackedWidget()
win = MainWindow()
win2 = gameScreen()


w.addWidget(win)
w.addWidget(win2)
w.setFixedSize(1000, 550)
w.show()

app.exec()

enter image description here

0 Answers
Related