Simple Rock-Paper-Scissors Command Line Interface game, user vs computer. First to get 5 points wins.
import random
import unittest
def showOption():
print('Choose an option:\n1. Rock\n2. Paper\n3. Scissors\n4. QUIT GAME')
def game(user_choice, comp_choice):
if user_choice == 0:
#user choose Rock
if comp_choice == 1:
#Computer choose Paper
return 'Computer'
elif comp_choice == 2:
#Computer choose Scissors
return 'You'
elif comp_choice == 0:
return 'Draw'
elif user_choice == 1:
#user choose Paper
if comp_choice == 2:
#Computer choose Scissors
return 'Computer'
elif comp_choice == 0:
#Computer choose Rock
return 'You'
elif comp_choice == 1:
return 'Draw'
elif user_choice == 2:
#user choose Scissors
if comp_choice == 0:
#Computer choose Rock
return 'Computer'
elif comp_choice == 1:
#Computer choose Paper
return 'You'
elif comp_choice == 2:
return 'Draw'
def continueGame():
print('Do you want to restart or quit?\n1.Restart\n2.Quit')
i = int(input())
if i == 2:
print('GAME FINISHED')
return False
else:
print('RESTARTING THE GAME')
return True
options = ['Rock', 'Paper', 'Scissors']
round_number = 1
computer_point = 0
user_point = 0
isRunning = True
while isRunning:
showOption()
choice = int(input())
if choice == 4:
isRunning = False
break
print('You choose', options[choice-1])
comp_choice = random.randint(0,2)
print('Computer choose', options[comp_choice])
winner = game(choice-1, comp_choice)
if winner == 'Draw':
print('That\'s a draw')
else:
if winner == 'You':
user_point+=1
elif winner == 'Computer':
computer_point+=1
print('Round winner is', winner)
print('Round no.',round_number,'\nYou -',user_point,':',computer_point,'- Computer')
round_number+=1
if user_point >= 5:
print('Game winner is YOU')
isRunning = continueGame()
elif computer_point >= 5:
print('Game winner is Computer')
isRunning = continueGame()