Advertisement
Helium

Lab 4 - Rock paper scissors game

Sep 10th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.76 KB | None | 0 0
  1. # Rock paper scissors game
  2. # featuring 3 modes
  3. # last edited by Mansur at 19:17 10/09/2013
  4.  
  5. # imports
  6. import time
  7. import random
  8.  
  9. # function defining
  10. def start():
  11.     print("\nRock....")
  12.     time.sleep(0.5)
  13.     print("Paper....")
  14.     time.sleep(0.5)
  15.     print("Scissors....\n")
  16.  
  17. # intro
  18. print("Welcome to Rock-Paper-Scissors game!\n")
  19.  
  20. # game loop
  21. while True:
  22.  
  23.     # declaring important variables
  24.     mode = input("\nPlease select a mode (Noob / Normal / Pro), or 'Q' to quit: ")
  25.     done = False
  26.     g = ("rock", "paper", "scissors")
  27.     no = ("nopestopfalsenahmeh")
  28.     yes = ("yesurefinegoyupyepleaseyeahokay")
  29.  
  30.     # normal mode loop
  31.     if mode.lower() == "normal":
  32.         while done == False:
  33.  
  34.             # getting variables
  35.             user = input("\nYour Move? ")
  36.             cpu = random.choice(g)
  37.             user = user.upper()
  38.             cpu = cpu.upper()
  39.             start()
  40.             print("YOU:", user)
  41.             print("CPU:", cpu)
  42.  
  43.             # comparing mech
  44.             if user == cpu:
  45.                 print("IT'S A TIE")
  46.             elif user == "ROCK":
  47.                 if cpu == "PAPER":
  48.                     print("YOU LOSE!")
  49.                 else:
  50.                     print("YOU WIN!")
  51.             elif user == "PAPER":
  52.                 if cpu == "ROCK":
  53.                     print("YOU WIN!")
  54.                 else:
  55.                     print("YOU LOSE!")
  56.             elif user == "SCISSORS":
  57.                 if cpu == "ROCK":
  58.                     print("YOU LOSE!")
  59.                 else:
  60.                     print("YOU WIN")
  61.             else:
  62.                 print("THAT IS NOT A VALID MOVE!")
  63.  
  64.             # choice at the end of each round
  65.             choice = input("\nWould you like to go again? ")
  66.             if choice.lower() in no:
  67.                 done = True
  68.             elif choice.lower() in yes:
  69.                 None
  70.             else:
  71.                 print("Invalid input, choosing 'yes' by default")
  72.  
  73.     # pro mode loop
  74.     elif mode.lower() == "pro":
  75.         while done == False:
  76.             user = input("\nYour move? ")
  77.             user = user.upper()
  78.             if user == "ROCK":
  79.                 cpu = "PAPER"
  80.             elif user == "PAPER":
  81.                 cpu = "SCISSORS"
  82.             elif user == "SCISSORS":
  83.                 cpu = "ROCK"
  84.             else:
  85.                 continue
  86.             start()
  87.             print("YOU:", user)
  88.             print("CPU:", cpu)
  89.             print("YOU LOSE!")
  90.             choice = input("\nWould you like to go again? ")
  91.             if choice.lower() in no:
  92.                 done = True
  93.             elif choice.lower() in yes:
  94.                 None
  95.             else:
  96.                 print("Invalid input, choosing 'yes' by default")
  97.  
  98.     # noob mode loop
  99.     elif mode.lower() == "noob":
  100.         while done == False:
  101.             user = input("\nYour move? ")
  102.             user = user.upper()
  103.             if user == "ROCK":
  104.                 cpu = "SCISSORS"
  105.             elif user == "PAPER":
  106.                 cpu = "ROCK"
  107.             elif user == "SCISSORS":
  108.                 cpu = "PAPER"
  109.             else:
  110.                 continue
  111.             start()
  112.             print("YOU:", user)
  113.             print("CPU:", cpu)
  114.             print("YOU WIN!")
  115.             choice = input("\nWould you like to go again? ")
  116.             if choice.lower() in no:
  117.                 done = True
  118.             elif choice.lower() in yes:
  119.                 None
  120.             else:
  121.                 print("Invalid input, choosing 'yes' by default")
  122.  
  123.     # choice of quitting the program
  124.     elif mode.lower() == "q":
  125.         break
  126.     else:
  127.         print("Please enter a valid input!\n")
  128.  
  129. # outro
  130. input("\n\nThanks for playing. Press the enter key to exit")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement