Final Project

11
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."

Transcript of Final Project

Page 1: Final Project

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."

Page 2: Final Project

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

Page 3: Final Project

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

Page 4: Final Project

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!"

Page 5: Final Project

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 again\n")

def introMessage():

#Intro message

print ("Welcome to Rock, Paper, Scissors!\n")

def menu():

Page 6: Final Project

#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:

Page 7: Final Project

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():

Page 8: Final Project

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")

Page 9: Final Project

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!")

Page 10: Final Project

Code Running:

Page 11: Final Project