Sale!

CECS 277 – Lab 2 – Functions solved

Original price was: $30.00.Current price is: $30.00. $18.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Rock-Paper-Scissors

Write a program that allows a user to play Rock-Paper-Scissors against the computer. Have the
program keep score of how many times each has won a round. Your program should have a
main method that has a loop that repeats the game until the user chooses to quit.

Display the
final score before exiting.

Write the following functions:
1. weapon_menu() – Asks the user to input their choice: (R)ock, (P)aper, (S)cissors,
or (B)ack. Checks user input for validity and then returns the inputted value.

2. comp_weapon() – Randomly chooses the computer’s throw and returns an “R”,
“P”, or “S”.

3. find_winner(player, comp) – Passes in the two weapons (R, P, or S),
displays the throws, compares the two weapons and displays the result and returns
who is the winner of that round (0=Tie, 1=Player, 2=Computer).
a. Rock crushes Scissors
b. Scissors cuts Paper
c. Paper covers Rock

4. display_scores(player, comp) – Displays the scores.
Example Output (user input is in italics):
RPS Menu:
1. Play game
2. Show Score
3. Quit
1
Choose your weapon:
R. Rock
P. Paper
S. Scissors
B. Back
P
You chose Paper
Computer chose Paper
Tie
Choose your weapon:
R. Rock
P. Paper
S. Scissors
B. Back
S
You chose Scissors
Computer chose Rock
Computer wins
Choose your weapon:
R. Rock
P. Paper
S. Scissors
B. Back
B
RPS Menu:
1. Play game
2. Show Score
3. Quit
2
Player = 0
Computer = 1
RPS Menu:
1. Play game
2. Show Score
3. Quit
3
Final Score:
Player = 0
Computer = 1

Notes:
1. You can use the check_input module provided on Canvas to check the user’s input in the
main menu (not the weapon menu).
2. Use the random module to randomly choose the computer’s weapon.

3. Please do not use any lists or global variables. Please pass all necessary values as
parameters to your functions.
4. Do not create any extra functions or add any extra parameters.

5. Please read through the Coding Standards document provided on Canvas for guidance on
how to name your variables and to format your program.
6. Use docstrings to document each of your five functions. Document all arguments and
return values.

7. Place your name, the date, and a brief description of the program in a comment block at
the top of your program.
8. Add brief comments in your functions to describe sections of code.

9. Thoroughly test your program before submitting/demoing.
a. Make sure each of your functions returns the correct value.
b. Make sure the computer’s throw returns a randomly assigned weapon choice.
c. Make sure that the correct winner is returned given the rules.

d. Make sure that the points are awarded to the correct player after winning a round.
e. Make sure that the points displayed are correct.
f. Make sure that the game doesn’t go back to the main menu until the user chooses
to go back.
g. Error check all user input (1, 2, 3 on the main menu, and R, P, S, B on the weapon
menu).

10. Feel free to expand the game to be the Rock-Paper-Scissors-Lizard-Spock version. Add
new menu options for (L)izard and Spoc(k). The updated set of rules are:
a. Rock crushes Scissors
b. Rock crushes Lizard
c. Paper covers Rock
d. Paper disproves Spock
e. Scissors cuts Paper
f. Scissors decapitates Lizard
g. Lizard poisons Spock
h. Lizard eats Paper
i. Spock smashes Scissors
j. Spock vaporizes Rock