Comm4nd0

Rock, Paper Scissors

Jul 6th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.53 KB | None | 0 0
  1. #Some imports needed for the game
  2. from random import randrange
  3. import time
  4.  
  5. #Some constants
  6. R = "ROCK"
  7. P = "PAPER"
  8. S = "SCISSORS"
  9. P_SCORE = 0
  10. C_SCORE = 0
  11. NAME = ""
  12.  
  13. #This is the welcome message and sets the NAME constant
  14. def welcome():
  15.     print"Welcome to 'Rock, Paper or Scissors', the most basic game ever!"
  16.     NAME = raw_input("What is your name? ")
  17.     NAME = NAME.upper()
  18.     print"Hello %s" % (NAME)
  19.     return NAME
  20.  
  21. #This is where the player makes his/her choice
  22. def player_choice():
  23.     print"Please select your weapon!"
  24.     print"[1] - Rock"
  25.     print"[2] - Paper"
  26.     print"[3] - Scissors"
  27.     p_weapon = input("choice: ")
  28.  
  29.     if p_weapon is 1:
  30.         print"You have selected 'Rock' as your weapon"
  31.         print"Computer is now selecting their weapon"
  32.     elif p_weapon is 2:
  33.         print"You have selected 'Paper' as your weapon"
  34.         print"Computer is now selecting their weapon"
  35.     elif p_weapon is 3:
  36.         print"You have selected 'Scissors' as your weapon"
  37.         print"Computer is now selecting their weapon"
  38.     else:
  39.         print ("%d is not a valid option. Please select 1, 2 or 3.\n" % p_weapon)
  40.         player_choice()
  41.     return p_weapon
  42.  
  43. #The computer selects a random number from 1, 2 or 3 and waits 5 seconds
  44. def computer_choice():
  45.     c_weapon = randrange(1,4)
  46.     time.sleep(5)
  47.     print"OK, I've made my choice!"
  48.     return c_weapon
  49.  
  50. #This is where the two options are compaired
  51. def who_wins(p_weapon, c_weapon):
  52.     winner = 0
  53.     if p_weapon is 1 and c_weapon is 1:
  54.         print "you chose %s | computer chose %s" % (R, R)
  55.         print"It's a DRAW!\n"
  56.         winner = 0
  57.            
  58.     elif p_weapon is 1 and c_weapon is 2:
  59.         print "you chose %s | computer chose %s" % (R, P)
  60.         winner = 2
  61.     elif p_weapon is 1 and c_weapon is 3:
  62.         print "you chose %s | computer chose %s" % (R, S)
  63.         winner = 1
  64.     elif p_weapon is 2 and c_weapon is 1:
  65.         print "you chose %s | computer chose %s" % (P, R)
  66.         winner = 1
  67.     elif p_weapon is 2 and c_weapon is 2:
  68.         print "you chose %s | computer chose %s" % (P, P)
  69.         print"It's a draw!\n"
  70.         winner = 0
  71.     elif p_weapon is 2 and c_weapon is 3:
  72.         print "you chose %s | computer chose %s" % (P, S)
  73.         winner = 2
  74.     elif p_weapon is 3 and c_weapon is 1:
  75.         print "you chose %s | computer chose %s" % (S, R)
  76.         winner = 2
  77.     elif p_weapon is 3 and c_weapon is 2:
  78.         print "you chose %s | computer chose %s" % (S, P)
  79.         winner = 1
  80.     elif p_weapon is 3 and c_weapon is 3:
  81.         print "you chose %s | computer chose %s" % (S, S)
  82.         print"It's a draw!\n"
  83.         winner = 0
  84.     return winner
  85.  
  86. #This is where the score is printed
  87. def print_score():
  88.     print"%s : %d || COMPUTER : %d" % (NAME, P_SCORE, C_SCORE)
  89.  
  90. #End of game message
  91. def end_game():
  92.     print"Thanks for playing, goodbye!"
  93.  
  94. NAME = welcome()
  95.  
  96. game_on = 1
  97.  
  98. while game_on is 1:
  99.     p_weapon = player_choice()
  100.     c_weapon = computer_choice()
  101.     winner = who_wins(p_weapon, c_weapon)
  102.  
  103.     if winner is 1:
  104.         P_SCORE = P_SCORE + 1
  105.         print"Congratulations!"
  106.         print_score()
  107.    
  108.     if winner is 2:
  109.         C_SCORE = C_SCORE + 1
  110.         print"Better luck next time!"
  111.         print_score()
  112.  
  113.     if winner is 0:
  114.         print"It's a draw!"
  115.         print_score()
  116.  
  117.     print"Play again? "
  118.     again = raw_input("Y/n: ")
  119.     if again.lower() == "y":
  120.         print"OK, lets go again!"
  121.     elif again.lower() == "n":
  122.         game_on = 0
  123.  
  124.  
  125. end_game()
Advertisement
Add Comment
Please, Sign In to add comment