Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Some imports needed for the game
- from random import randrange
- import time
- #Some constants
- R = "ROCK"
- P = "PAPER"
- S = "SCISSORS"
- P_SCORE = 0
- C_SCORE = 0
- NAME = ""
- #This is the welcome message and sets the NAME constant
- def welcome():
- print"Welcome to 'Rock, Paper or Scissors', the most basic game ever!"
- NAME = raw_input("What is your name? ")
- NAME = NAME.upper()
- print"Hello %s" % (NAME)
- return NAME
- #This is where the player makes his/her choice
- def player_choice():
- print"Please select your weapon!"
- print"[1] - Rock"
- print"[2] - Paper"
- print"[3] - Scissors"
- p_weapon = input("choice: ")
- if p_weapon is 1:
- print"You have selected 'Rock' as your weapon"
- print"Computer is now selecting their weapon"
- elif p_weapon is 2:
- print"You have selected 'Paper' as your weapon"
- print"Computer is now selecting their weapon"
- elif p_weapon is 3:
- print"You have selected 'Scissors' as your weapon"
- print"Computer is now selecting their weapon"
- else:
- print ("%d is not a valid option. Please select 1, 2 or 3.\n" % p_weapon)
- player_choice()
- return p_weapon
- #The computer selects a random number from 1, 2 or 3 and waits 5 seconds
- def computer_choice():
- c_weapon = randrange(1,4)
- time.sleep(5)
- print"OK, I've made my choice!"
- return c_weapon
- #This is where the two options are compaired
- def who_wins(p_weapon, c_weapon):
- winner = 0
- if p_weapon is 1 and c_weapon is 1:
- print "you chose %s | computer chose %s" % (R, R)
- print"It's a DRAW!\n"
- winner = 0
- elif p_weapon is 1 and c_weapon is 2:
- print "you chose %s | computer chose %s" % (R, P)
- winner = 2
- elif p_weapon is 1 and c_weapon is 3:
- print "you chose %s | computer chose %s" % (R, S)
- winner = 1
- elif p_weapon is 2 and c_weapon is 1:
- print "you chose %s | computer chose %s" % (P, R)
- winner = 1
- elif p_weapon is 2 and c_weapon is 2:
- print "you chose %s | computer chose %s" % (P, P)
- print"It's a draw!\n"
- winner = 0
- elif p_weapon is 2 and c_weapon is 3:
- print "you chose %s | computer chose %s" % (P, S)
- winner = 2
- elif p_weapon is 3 and c_weapon is 1:
- print "you chose %s | computer chose %s" % (S, R)
- winner = 2
- elif p_weapon is 3 and c_weapon is 2:
- print "you chose %s | computer chose %s" % (S, P)
- winner = 1
- elif p_weapon is 3 and c_weapon is 3:
- print "you chose %s | computer chose %s" % (S, S)
- print"It's a draw!\n"
- winner = 0
- return winner
- #This is where the score is printed
- def print_score():
- print"%s : %d || COMPUTER : %d" % (NAME, P_SCORE, C_SCORE)
- #End of game message
- def end_game():
- print"Thanks for playing, goodbye!"
- NAME = welcome()
- game_on = 1
- while game_on is 1:
- p_weapon = player_choice()
- c_weapon = computer_choice()
- winner = who_wins(p_weapon, c_weapon)
- if winner is 1:
- P_SCORE = P_SCORE + 1
- print"Congratulations!"
- print_score()
- if winner is 2:
- C_SCORE = C_SCORE + 1
- print"Better luck next time!"
- print_score()
- if winner is 0:
- print"It's a draw!"
- print_score()
- print"Play again? "
- again = raw_input("Y/n: ")
- if again.lower() == "y":
- print"OK, lets go again!"
- elif again.lower() == "n":
- game_on = 0
- end_game()
Advertisement
Add Comment
Please, Sign In to add comment