Introduction

In this project, you simulate the play of a popular childrens game: Chutes and Ladders as shown in the picture below. see image.

The Chutes and Ladders game is played on a 100 square game board. Each square on the board is numbered 1 through 100. There can be as many players as desired but for the project, each of your team members will be a player in a game. Each player starts off the board at a figurative square 0. Each player rolls a single die with 1 through 6 face values and advances to the number of spaces shown on the die. For example, if the player is at position 2 and rolls a 5, the player moves to position 7. When any one of the players lands exactly on the square 100, the player wins, and the game is over.

There are 2 rules to the player movement.

(1)If the player lands on a slide (chutes), the player slides down. If the player lands on a ladder, the player climbs up. See the picture for the square where a slide or a ladder is, and the table below. see image.

For example, if the player lands on square 1, the player advances to square 38. If the player lands on square 98, the player slides down to square 78.

(2)The player must land exactly on square numbered 100 to win. If the player rolls a die that would advance to a square beyond square 100, the player stays put at its place. For example, the player at square 97, the player must roll exactly a 3 to win. A roll between 4 and 6 would make the player stay put at the current square, and the player loses a turn.

Source Code Files

Like project #1, the provided classes are skeleton that you will need to fill in the blank spaces. You are required to fill in the missing parts so that the code for the game is complete and runs properly.

The simulation is split into the following classes:

(1)Die class (Die.hpp) allows a player to roll the die, which generates a number between 1 and 6, inclusive, randomly using the math librarys rand(). Client of the Die class can get the die face value via the accessor: getFaceValue(). This class is ready for use in your program. No change is needed.

(2)GameBoard represents the gameboard numbering 1 to 100. TO DO: you need to implement a storage to store each square on the board, and the following methods:

  • Constructor this method reserves an additional square and builds the gameboard by calling buildBoard.
  • checkChutesLadders this method returns a new position if the player lands on a chute or a ladder. The method throws an index out of bounds exception the input position is outside of the game board.
  • buildBoard this method determines the player movement: whether the player climbs up, slides down, or stays put. After the player rolls the die, the player advances to a new square. If the landing square is a chute, the player slides down to the lower square indicated in the table above. If the landing square is a ladder, the player climbs up to the a higher square. Otherwise, the player stays put at the new landing square.

(3)Player class (Player.hpp and Player.cpp) represents a player in the game. It contains the player name, the players current position, and a die.

RollDieAndMove - Each player has its own die. The player rolls the die and advances to the new square based on the face value of the die. The method must make sure that the players position is inside the gameboard. If the player rolls the die that moves her/him past the square 100, s/he must stay put at the current square, and lose a turn.

TO DO: you need to implement the following methods:

  • RollDieAndMove(). This method returns the players new position after the player rolls the die. If the new position is outside of the board, the player stays put. If not, the player moves to the new square (= players current position plus dies face value).
  • Parameterized constructor.
  • Copy constructor.
  • Assignment operator.
    • ChutesAndLadersGames
    • resetGame 5 points
    • playGame 20 points

(4)ChutesAndLaddersGame class that simulates the Chutes and Ladders game. The game starts and runs until a player reaches the winning square 100.

TO DO: you must use ArrayQueue to store the players, and implement the following items/methods:

  • Set MIN_NUMBER_OF_PLAYERS to your team size in the hpp file.
  • Constructor with a default value of your team size. Each of your team member is enqueued and waits for her/his turn to play the game.
  • Destructor dequeue players from the queue.
  • The accessor, getNumberOfPlayers.
  • resetGame this method rebuilds the list of players and resets their positions to the figurative square zero. You need to ensure that the players are in the same order as in the constructor.
  • playGame this is the main function that simulates the Chutes and Ladders game. The game stops when a player reaches the winning square 100. Below is the pseudo code:
    • The game runs in a while loop until there is a winner.
    • Each player takes turn to roll the die and move to the new square by invoking players rollDieAndMove. (The player is dequeued from the queue when it is the players turn to roll the die).
    • The players new position is checked against the game boards checkChutesLatters, which returns a different square if player lands on a chute or a latter. In other words, the player can climb up, or slide down to the square, or stay put.
    • If checkChutesLatters returns a square that is different than the one that is returned by rollDieAndMove, then the players position is set to the new square.
    • If the player lands on the winning square 100, the game is over, and a congratulations message is printed.
    • If not, the player is enqueued and waits for her/his next turn.

(5)PlayChutesAndLaddersGame is the main test driver. The driver uses the assert macro to test whether the code works or not.

Because the provided code is only a template, PlayChutesAndLaddersGame will fail immediately with runtime errors. As you add functionality and fix any bugs that may arise, PlayChutesAndLaddersGame will be able to run further and further. You should run PlayChutesAndLaddersGame and observe the runtime errors to help you solve problems in your code. When the files are working completely as intended, PlayChutesAndLaddersGame will run to completion with no runtime errors.

Finally, the skeleton code contains a README.md file with a brief description of the project.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.