Answered step by step
Verified Expert Solution
Link Copied!

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

  1. Your program should ask for the number of points needed to win and use that number as the end of game limit.
    1. If either player gets a total score that exceeds that amount, a message indicating the winner should be displayed.
  2. It should then ask for the seed for the random number generator.
    1. If a number less than zero is entered, then do not initialize your die with a seed.
    2. 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.
    3. It is safe to assume that the user (grader) will enter an integer.
  3. Your program will be built for single-player play. The second player will be a computer who uses the following logic:
    1. 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.
  4. The number of points required to win must indeed stop the game and signify the winner when reached.image text in transcribedimage text in transcribed
Winning Game $ java Pig Welcome to the game of Pig! How many points are required to win? 25 Enter a value to use to 'seed' the random number(negative number will not seed): 0 Your turn You rolled: 5 Your turn score is 5 and your total score is a If you hold, you will have 5 points. Enter 'r' to roll again, 's' to stop: r. You rolled: 2 Your turn score is 7 and your total score is a If you hold, you will have 7 points. Enter 'r' to roll again, 's' to stop: r You rolled: 4 Your turn score is 11 and your total score is O If you hold, you will have 11 points. Enter 'r' to roll again, 's' to stop: r You rolled: 4 Your turn score is 15 and your total score is a If you hold, you will have 15 points. Enter 'r' to roll again, 's' to stop: r You rolled: 4 Your turn score is 19 and your total score is O If you hold, you will have 19 points. Enter 'r' to roll again, 's' to stop: r You rolled: 2 Your turn score is 21 and your total score is a If you hold, you will have 21 points. Enter 'r' to roll again, 's' to stop: r You rolled: 3 Your turn score is 24 and your total score is If you hold, you will have 24 points. Enter 'r' to roll again, 's' to stop: r You rolled: 6 Your turn score is 30 and your total score is O If you hold, you will have 30 points. Enter 'r' to roll again, 's' to stop: s Your score is 30 YOU WIN! Losing Game $ java Pig Welcome to the game of Pig! How many points are required to win? 25 Enter a value to use to 'seed' the random number(negative number will not seed): 0 Your turn You rolled: 5 Your turn score is 5 and your total score is a If you hold, you will have 5 points. Enter 'r' to roll again, 's' to stop: 5 Your score is 5 It is the computer's turn. The computer rolled: 2 The computer rolled: 4 The computer rolled: 4 The computer rolled: 4 The computer rolled: 2 The computer rolled: 3 The computer rolled: 6 The computer holds. The computer's score is 25 THE COMPUTER 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

Step: 3

blur-text-image

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

2. Compare the sales and service departments at Auto World.

Answered: 1 week ago