Question: In this studio you will write a C + + program based on the classic Chutes & Ladders game ( similar to one of the

In this studio you will write a C++ program based on the classic Chutes & Ladders game (similar to one of the problems on the midterm exam). Our single-person version of the game has the following rules: The player starts in position 1. Each turn, a pair of 6-sided dice are rolled, and the player moves forward by that many steps. If the player lands on a position that is evenly divisible by 6(a ladder), they move an additional 3 steps forward. If the player lands in a position that is evenly divisible by 7(a chute), they move 3 steps backwards. If the player lands in position 11,22, or 33 due to their natural roll (i.e. not due to moving via a chute or ladder), they return to starting position 1. The game ends when the player reaches position 50(or greater) at the end of their turn. Your program will roll the virtual dice each turn to decide how far to move and will keep track of the players position in the game. To make the task easier, we will break the code development into a sequence of steps. Start by thinking about the algorithm itself without worrying about the actual C++ program: How do you determine the result of a die roll? OK, youll need a way to generate a random number and assign this value to a variable (of type int, right?). How do you track a position? OK, so you need another int variable for that. How can I keep performing multiple turns? OK, a loop of some kind will be needed, and since we dont know how many times the loop will need to be run, that narrows the choice. When do I roll the die? OK, that part needs to be inside the loop since it happens once every round. When should I check whether the player hit a chute or ladder? OK, after I rolled the dice and moved my position forward. And so on. Remember that a good strategy for writing complex code is to write the steps in plain English, which will then be converted to comments as your code develops. 1. Begin by writing a simplified Chutes & Ladders program that will request die roll values from the player, and output the new position after each roll. This simplified program has no chutes or ladders and does not track how many moves youve used (but it still stops once youve reached the final position). Since we dont yet know how to generate a random die roll, ask the player to enter the value (2-12 for a pair of dice) instead. A sample output from this initial program is: Chutes and Ladders -- version 1----- Enter the result of the die roll: 7 Your position is now 7 Enter the result of the die roll: 12 Your position is now 19 Enter the result of the die roll: 12 Your position is now 31 Enter the result of the die roll: 3 Your position is now 34 Enter the result of the die roll: 9 Your position is now 43 Enter the result of the die roll: 8 Your position is now 51 You finished in 6 moves Ask a TA to check this before continuing. 2. In the next version, add the chutes and the ladders. This new code should go somewhere inside the loop since you need to make this test each time the player moves. A sample output should now look like: Chutes and Ladders -- version 2----- Enter the result of the die roll: 5 Your position is now 5 Enter the result of the die roll: 1 You climbed a ladder! Your position is now 9 Enter the result of the die roll: 2 You returned to the start! Your position is now 1 Enter the result of the die roll: 12 Your position is now 13 Enter the result of the die roll: 8 You fell down a chute! Your position is now 18 Enter the result of the die roll: 12 You climbed a ladder! Your position is now 33 Enter the result of the die roll: 12 Your position is now 45 Enter the result of the die roll: 9 You climbed a ladder! Your position is now 57

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!