Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

////////////////////////////////////////////////////////Java Program///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// with comments to help me understand the problem thank you you need to create a class called LadderAndSnake. A LadderAndSnake object has a

image text in transcribed

////////////////////////////////////////////////////////Java Program/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

with comments to help me understand the problem thank you

you need to create a class called LadderAndSnake. A LadderAndSnake object has a board of 10x10 and a number of players attached to it, which is initialized at the creation time of the object. The number of players must be between 2 and 4 inclusively. The number of players must be set through the use of a parameterized constructor of the class.

Besides the constructors, and all basic methods in the class, the class must include two methods, one called flipDice(), which should return a random value between 1 and 6 inclusively. The other method is called play(), which actually initiate the core engine of the game where the players

start to

play the game. The rules of the game are as below: Before any of the players starts playing, the order of playing turns must be determined. For that, each player must throw the dice to obtain the largest possible number. In case of a tie between any of the players, the process is repeated only between those players. This process is concluded once the order of playing is determined. At this point, the players start playing the game by alternating dice flipping. Each dice flip will move a player form square 1 with the value of the dice. For example, if a player is at square 1 and the dice value was 4, then the player moves to square 5. If the reached square has a bottom of a ladder, then the player moves up to the square that has the top of the ladder. For instance, if a player is at square 33, and the flipped dice value was 3, then the player moves to square 36, which in turn will end moving the player up to square 44. If the reached square has a head of a snake, then the player moves down the square that has the tail of the snake. For instance, if a player is at square 77, and the flipped dice value 2, then the player moves to square 79 (which has the tip of the snakes head), which in turn end moving the player down to square 19.

You will have to find a way to record the relation between these particular ladder and snake squares.

The game is concluded once any of the players EXACTLY, reaches square 100. If a player is close to 100, and the dice value exceeds the maximum possible moves, the player moves backward with the excessive amount. For instance, if a player is at square 96 and the dice value is 5, then the player moves to 99 (that is 4 moves to 100, then 1 move backward to 99).

general requirement, you must show/display ALL operations of the game.

As a start, you should indicate something like:

  • - Game is Played by x players (where x is the number of players set for that game);

  • - Now deciding which player will start playing;

  • - Player 1 got a dice value of 5

    Player 2 got a dice value of 3 Player 3 got a dice value of 3 A tie was achieved between Player 2 and Player 3. Attempting to break the tie Player 2 got a dice value of 2 Player 3 got a dice value of 6

  • - Reached final decision on order of playing: Player 1, Player 3, Player 2

  • - Player 1 got dice value of 4; now in square 5

  • - Player 2 got dice value of 6; now in square 7

  • - Player 3 got dice value of 3; gone to square 4 then up to square 14

  • - Game not over; flipping again

  • - Player 1 got dice value of 4; gone to square 9 then up to square 31

  • - Player 2 got dice value of 3; now in square 10

  • - Player 3 got dice value of 2; gone to square 16 then down to square 6

  • - Game not over; flipping again -: -: -

    The above sample of displays is the basic minimum that you should have. A better mark is given for more elaborate/creative displays (i.e. possibly visibly showing the plays/moves, giving each of the players a name, etc.)

    Create a public driver class called PlayLadderAndSnake. In the main() method, you need to prompt the user to enter the number of players that he/she needs to play the game with. The user must enter a value between 2 and 4. If the user does not enter a correct value, the program must prompt the user again to enter a correct value. However, there is a limit of 4 total attempts. If the user enters an incorrect value 4 times, then the program must display a message to this effect and terminates. For instance, the program behaviour may look something similar to the following:

Enter the # of players for your game Number must be between 2 and 4 inclusively:

6 Bad Attempt 1 - Invalid # of players. Please enter a # between 2 and 4 inclusively:

8 Bad Attempt 2 - Invalid # of players. Please enter a # between 2 and 4 inclusively:

i. 5 Bad Attempt 3 - Invalid # of players. Please enter a # between 2 and 4 inclusively. This is your last attempt:

10 Bad Attempt 4! You have exhausted all your chances. Program will terminate!

image text in transcribed
100 FINISH 99 98 971 96 95 94 93 92 91 83 84 89 THOUT 81 86 85 76 75 82 90 87 88 73 74 68 80 77 79 62 78 63 66 72 71 70 69 61 64 65 53 52 51 54 47 58 57 56 43 45 44 36 38 37 46 49 48 33 60 59 42 41 40 39 22 21 20 50 31 35 34 32 29 27 28 30 23 24 25 26 17 16 15 18 12 19 14 13 11 2 3 6 7 8 9 10 NOTE: PRINT IN A CORTON PAPER Lllectile.com 99 98 100 FINISH 97 96 95 9493 92 91 83 84 86 89 181 82 90 85 76 75 8788 73 80 77 74 79 62 78 63 72 71 70 66 68 61 64 65 67 69 53 TIN 54 52 51 60 59 42 47 58 57 56 43 45 44 36 38 37 46 41 40 49 48 33 50 31 35 34 39 22 32 29 27 28 30 21 20 23 24 25 17 16 26 15 12 19 18 14 13 11 2 3 4 5 6 7 8 9 10 100 FINISH 99 98 971 96 95 94 93 92 91 83 84 89 THOUT 81 86 85 76 75 82 90 87 88 73 74 68 80 77 79 62 78 63 66 72 71 70 69 61 64 65 53 52 51 54 47 58 57 56 43 45 44 36 38 37 46 49 48 33 60 59 42 41 40 39 22 21 20 50 31 35 34 32 29 27 28 30 23 24 25 26 17 16 15 18 12 19 14 13 11 2 3 6 7 8 9 10 NOTE: PRINT IN A CORTON PAPER Lllectile.com 99 98 100 FINISH 97 96 95 9493 92 91 83 84 86 89 181 82 90 85 76 75 8788 73 80 77 74 79 62 78 63 72 71 70 66 68 61 64 65 67 69 53 TIN 54 52 51 60 59 42 47 58 57 56 43 45 44 36 38 37 46 41 40 49 48 33 50 31 35 34 39 22 32 29 27 28 30 21 20 23 24 25 17 16 26 15 12 19 18 14 13 11 2 3 4 5 6 7 8 9 10

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions