Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The game of Morra is a hand game that dates back to ancient Greece and Rome. In the real game, any number of players can

image text in transcribedimage text in transcribedimage text in transcribed

The game of Morra is a hand game that dates back to ancient Greece and Rome. In the real game, any number of players can play, but for this question we will assume two players only. The game is played in rounds. Each round, both players throw out one hand showing between 0 and 5 fingers and simultaneously call out what they think the sum of the fingers on the hands of all players will be. Any player who guesses correctly gets a point. The first player to 3 points wins. You will write a program that simulates a two-player game of Morra. Your program must do the following for each round of play until the game is over: - At the beginning of each round, print out the round number. The first round is round 1. - Read from the console the number of fingers shown by player 1 , the number of fingers shown by player 2, player 1's guess at the sum, and player 2's guess at the sum. - Print to the console whether any players made a correct guess, and if so, that player's new point total. If neither player guessed correctly, print a message indicating this. Note that BOTH players might guess correctly, in which case they both earn a point! Once the game is over, print the final outcome of the game. There are a few possibilities: - Print Player X wins! where X is either 1 or 2 depending on which player won. - If, however, the winning player won by a score of 3 to 0 , instead print Player X wins a glorious victory!, again where X is either 1 or 2 as appropriate. - It is possible that the game is a tie. For example, if the score is 2 to 2 , and both players guess correctly in the next round, both players will have three points when the game ends. In such a case, instead of printing either of the above messages, print It s a tie!. Sample Runs A couple of sample runs demonstrating program behaviour are given in the appendix at the end of this document (this is not because they are unimportant, but because they are rather long to insert here). Tips and Hints (a) Remember: you don't have to generate player moves randomly. You are reading them from the console each round. Think of your program as the referee - it asks for the players moves each round using console input, then reports on the outcome of each round using console output, and finally prints the outcome of the game. (b) Your program only has to play one full game. To referee another game, run the program again! (c) You may assume that the user enters only valid data. That is, you do not have to actually check whether player moves are between 0 and 5 and that their guesses are between 0 and 10 . Just assume that valid values are always entered. Appendix: Sample Run tor Morra In our first example, player 1 has uncanny knowledge of the future and guesses correctly every time, winning a glorious victory! Note: green text was console input entered by a user. Round 1: How many fingers will player 1 hold out? 3 How many fingers will player 2 hold out? 1 What is player 1 s guess of the total number of fingers? 4 What is player 2 s guess of the total number of fingers? 8 Player 1 guessed correctly! Player 1 now has 1 points. Round 2: How many fingers will player 1 hold out? 0 How many fingers will player 2 hold out? 5 What is player 1 s guess of the total number of fingers? 5 What is player 2 s guess of the total number of fingers? 3 Player 1 guessed correctly! Player 1 now has 2 points. Round 3: How many fingers will player 1 hold out? 3 How many fingers will player 2 hold out? 3 What is player 1 s guess of the total number of fingers? 6 What is player 2 s guess of the total number of fingers? 5 Player 1 guessed correctly! Player 1 now has 3 points. Player 1 wins a glorious victory ! In our second game, both players play well, and player 1 wins 3 to 2 . In round 1 , both players guess wrong. Again, green text was console input entered by a user. Round 1: How many fingers will player 1 hold out? 2 How many fingers will player 2 hold out? 3 What is player 1 s guess of the total number of fingers ? 4 What is player 2 s guess of the total number of fingers ? 6 Neither player made a correct guess. Round 2: How many fingers will player 1 hold out? 3 How many fingers will player 2 hold out? 1 What is player 1 s guess of the total number of fingers ? 4 What is player 2 s guess of the total number of fingers ? 8 Player 1 guessed correctly! Player 1 now has 1 points. Round 3: How many fingers will player 1 hold out? 5 How many fingers will player 2 hold out? 2 What is player 1 s guess of the total number of fingers? 6 What is player 2 s guess of the total number of fingers? 7 Player 2 guessed correctly! Player 2 now has 1 points Round 4 : How many fingers will player 1 hold out? 1 How many fingers will player 2 hold out? 1 What is player 1 s guess of the total number of fingers ? 2 What is player 2 s guess of the total number of fingers ? 9 Player 1 guessed correctly! Player 1 now has 2 points. Round 5: How many fingers will player 1 hold out? 2 How many fingers will player 2 hold out? 4 What is player 1 s guess of the total number of fingers? 3 What is player 2 s guess of the total number of fingers? 6 Player 2 guessed correctly! Player 2 now has 2 points Round 6: How many fingers will player 1 hold out ? 3 How many fingers will player 2 hold out? 2 What is player 1 s guess of the total number of fingers? 5 What is player 2 s guess of the total number of fingers? 7 Player 1 guessed correctly! Player 1 now has 3 points. Player 1 wins

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions