The Python code implements a rock-paper-scissors game with a menu-driven interface that allows the user to see the rules, play against the computer, play against another person, or quit the game. The main function displays an intro message and menu, gets the user's selection, and calls the appropriate function. Functions are defined to handle each selection, including displaying rules, playing rounds against the computer by randomly generating its move, and determining winners between two player-inputted moves. The game allows replaying by calling main again.
1. Psuedocode:
//Rachel Joseph
//07/30/16
//This program will play rock paper scissors
main module
//print intro and menu
input selection
if selection 1
seeRules module
elif selection 2
againstCP module
elif selection 3
againstHum module
elif selection 4
quitGame module
else
display "This selection is not valid"
end if
//intro message
introMessage module
display "Welcome to rock, paper, scissors"
//Menu for making a selection on what to do
menu module
display "Select what you want to do"
display "1. see the rules"
display "2. Play against the computer."
display "3. Play against another person."
2. display "4. Quit"
//replay option
replay module
display "do you want to play again?"
input yes or no
while playAgain.lower = yes
display "Thanks for playing!"
end while
//game rules
seeRules module
display "The rules are as follows:"
display "Paper covers rock"
display "rock smashed scissors"
display "scissors cut paper"
//playing against the computer
againstCP module
import randint
declare q = "rock", "paper", "Scissors"
declare computer = q[randint(0,2)]
declare player = false
while player == false
input "rock, paper, or scissors"
if player == computer
display "Tie"
elif player == rock
3. if computer == paper
dispaly "you lose"
else:
display "You win"
elif player == paper
if computer == scissors
display "You lose"
else:
display "you win"
elif player == scissors
if computer == rock
display "you lose"
else:
display "you win"
else:
display "Thats not a valid play"
//playing against another human player
againstHum module
declare p1 = input "rock, paper or scissors?"
declare p2 = input "rock, paper or scissors?"
declare choices = rock, paper, scissors
rock = false
paper = false
scissors = false
if p1 == p2
display "Tie"
if p1 == rock
rock = true
4. if p2 == rock
rock = true
if p1 == paper
paper = true
if p2 == paper
paper = true
if p1 == scissors
scissors = true
if p2 == scissors
scissors = true
if rock and paper
display "paper wins"
if rock and scissors
display "rock wins"
if scissors and paper
display "scissors wins"
if p1 not in choices
display "That is not a valid play"
call againstHum
elif p2 not in choices
display "That is not a valid play"
call againstHum
else:
display "Game over"
//quitting the game
quitGame module
display "Thanks for playing!"
5. Python Code:
#Rachel Joseph
#07/30/16
#This program will display a menu and allow user to play Rock, Paper, Scissors
def main():
selection = 0
#print intro and menu of options
introMessage()
menu()
#get selection from user
selection = eval(input("Please choose an option: "))
#Begin decision structure
if selection == 1:
seeRules()
elif selection == 2:
againstCP()
elif selection == 3:
againstHum()
elif selection == 4:
quitGame()
print ("Program end")
else: #validate selection
print ("This is not a valid selection, please try againn")
def introMessage():
#Intro message
print ("Welcome to Rock, Paper, Scissors!n")
def menu():
6. #Menu for user to select what they want to do
print ("Select what you want to do!n")
print ("1. See the rules")
print ("2. Play against the computer")
print ("3. Play a two player game")
print ("4. Quit")
#option to replay the game
def replay():
playAgain = ""
playAgain = input("Do you want to play again, yes or no? ")
while playAgain.lower() != "yes":
print("Thanks for playing!")
#Rules for the game
def seeRules():
print ("The rules are as follows:")
print ("Paper Covers Rock")
print ("Rock Smashed Scissors")
print ("Scissors Cut Paper")
#Rock, paper, scissors against the computer
def againstCP():
from random import randint
q = ["rock", "paper", "scissors"]
computer = q[randint(0,2)]
player = False
while player == False:
7. player = input("rock, paper, scissors?")
if player == computer:
print("Tie!")
elif player == "rock":
if computer == "paper":
print("You lose.", computer, "covers", player)
else:
print("You win!", player, "smashes", computer)
elif player == "paper":
if computer == "scissors":
print("You lose.", computer, "cut", player)
else:
print("You win!", player, "covers", computer)
elif player == "scissors":
if computer == "rock":
print("You lose.", computer, "smashes", player)
else:
print("You win!", player, "cut", computer)
else:
print("That's not a play!")
player = False
computer = q[randint(0,2)]
#Option 4, quitting the game
def quitGame():
print("Thanks for playing!")
#playing against another human player
def againstHum():
8. p1 = input("Player 1: Rock, Paper, or Scissors? ")
p2 = input("Player 2: Rock, Paper, or Scissors? ")
choices = ["rock","paper","scissors"]
rock = False
paper = False
scissors = False
if p1==p2:
print ("Tie")
if p1=="rock":
rock=True
if p2=="rock":
rock=True
if p1=="paper":
paper=True
if p2=="paper":
paper=True
if p1=="scissors":
scissors=True
if p2=="scissors":
scissors=True
if rock and paper:
print ("Paper wins")
if rock and scissors:
print ("Rock wins")
9. if scissors and paper:
print ("Scissors wins")
if p1 not in choices:
print ("Player 1, choose a valid play")
againstHum()
elif p2 not in choices:
print ("Player 2, choose a valid play")
againstHum()
else:
print ("Game over!")