Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java: Pig is a two player game involving a single die. One player is chosen to go first. A player's turn involves repeatedly rolling the
Java: Pig is a two player game involving a single die. One player is chosen to go first. A player's turn involves repeatedly rolling the die until one of the following happens:
- A 1 is rolled - players turn is over, no points earned.
- The player chooses to keep points earned on this turn.
At the end of a player's turn, game-play continues with the other player. The game is over when one of the players reaches the total number of points required to win (for example, 25 points).
- Your program should ask for the number of points needed to win and use that number as the end of game limit.
- If either player gets a total score that exceeds that amount, a message indicating the winner should be displayed.
- It should then ask for the seed for the random number generator.
- If a number less than zero is entered, then do not initialize your die with a seed.
- If 0 or greater is entered, your die should seed with that value - this will allow the grader to have a predictable path to victory or defeat for testing.
- It is safe to assume that the user (grader) will enter an integer.
- Your program will be built for single-player play. The second player will be a computer who uses the following logic:
- Always continue to roll until the points for the turn are at least 20. If 20 or more points have been rolled, the computer shall choose to keep their points and transfer play back to the person playing.
- The number of points required to win must indeed stop the game and signify the winner when reached.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started