Python Forum
Rock Paper Scissors Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock Paper Scissors Game
#1
I just want to receive some feedback on my code on things I can improve such as if my code can be cleaner or things I can add, anything helps!

import time
import random

rps = ("R","P","S")

def stop():
    while True:
        for i in range(1):
            break
def score():
    while True:
        time.sleep(1)
        print("\nThe Score\nWins -",counter_W,"\nLoses -",counter_L, "\nTies -", c_T)
        break

def restart():
    global rounds
    time.sleep(.5)
    rounds -= user_R
    while True:
        restart = input("\nType 'C' to Continue\nType 'Q' to Quit: ")
        restart = restart.upper()
        if restart == 'C':
            time.sleep(.5)
            game()
        elif restart == 'Q':
            print("\nEnding game...")
            stop()

# Counters (Tie, Win, Loss)

c_T = 0
counter_W = 0
counter_L = 0

rounds = 0

def game():
    global c_T, counter_W, counter_L, rounds, user_R
    user_R = int(input("\nType the amount of rounds you would like to play: "))
    while True:
        rps_R = random.choice(rps)
        time.sleep(.5)
        user = input("\nType 'R' for Rock\nType 'P' for Paper\nType 'S' for Scissors: ")
        user = user.upper()
        # Tie
        if user == 'R' and rps_R == 'R' or user == 'P' and rps_R == 'P' or user == 'S' and rps_R == 'S':
            c_T += 1
            rounds += 1
            print("\nUser has tied", c_T)
        # User Wins Rock
        if user == 'R' and rps_R == 'S':
            counter_W += 1
            rounds += 1
            print("\nUser has won:", counter_W)
        # User Wins Paper
        elif user == 'P' and rps_R == 'R':
            counter_W += 1
            rounds += 1
            print("\nUser has won:", counter_W)
        # User Wins Scissors
        elif user == 'S' and rps_R == 'P':
            counter_W += 1
            rounds += 1
            print("\nUser has won:", counter_W)
        # -----------------------------------
        # User loses Rock
        if user == 'R' and rps_R == 'P':
            counter_L += 1
            rounds += 1
            print("\nUser has lost:", counter_L)
        # User Wins Paper
        elif user == 'P' and rps_R == 'S':
            counter_L += 1
            rounds += 1
            print("\nUser has lost:", counter_L)
        # User Wins Scissors
        elif user == 'S' and rps_R == 'R':
            counter_L += 1
            rounds += 1
            print("\nUser has lost:", counter_L)

        if rounds == user_R:
            score()
            restart()

def intro():
    print("Rock Paper Scissors Game")
    time.sleep(.1)
    print("  _____  _____   _____  ")
    print(" |  __ \|  __ \ / ____|")
    time.sleep(.1)
    print(" | |__) | |__) | (___  ")
    print(" |  _  /|  ___/ \___ \ ")
    time.sleep(.1)
    print(" | | \ \| |     ____) | ")
    print(" |_|  \_\_|    |_____/ ")
    time.sleep(.1)
    print(" Coded by NectDz\n")

def main():
    intro()
    time.sleep(1)
    while True:
        start = input("Type 'Start' to begin: ")
        start = start.upper()
        if start == 'START':
            game()
        else :
            print("\nDid not understand restarting...\n")
            time.sleep(2)
            main()

main()
Reply


Messages In This Thread
Rock Paper Scissors Game - by NectDz - May-28-2020, 04:41 PM
RE: Rock Paper Scissors Game - by pyzyx3qwerty - May-29-2020, 05:23 AM
RE: Rock Paper Scissors Game - by ndc85430 - May-30-2020, 07:21 AM
RE: Rock Paper Scissors Game - by NectDz - May-30-2020, 09:42 AM
RE: Rock Paper Scissors Game - by Calli - May-30-2020, 06:22 PM
RE: Rock Paper Scissors Game - by NectDz - May-31-2020, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code review of my rock paper scissors game Milan 0 2,031 May-25-2022, 06:59 AM
Last Post: Milan
  Rock paper Scissors Milan 2 2,803 Feb-01-2021, 03:42 PM
Last Post: Milan
  2nd Project: Rock, Paper, Scissors MiNigle 3 2,733 Jun-05-2020, 12:50 PM
Last Post: MiNigle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020