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 singleperson version of the game has the following rules: The player starts in position Each turn, a pair of 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 a ladder they move an additional steps forward. If the player lands in a position that is evenly divisible by a chute they move steps backwards. If the player lands in position or due to their natural roll ie not due to moving via a chute or ladder they return to starting position The game ends when the player reaches position 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. 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 for a pair of dice instead. A sample output from this initial program is: Chutes and Ladders version Enter the result of the die roll: Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: Your position is now You finished in moves Ask a TA to check this before continuing. 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 Enter the result of the die roll: Your position is now Enter the result of the die roll: You climbed a ladder! Your position is now Enter the result of the die roll: You returned to the start! Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: You fell down a chute! Your position is now Enter the result of the die roll: You climbed a ladder! Your position is now Enter the result of the die roll: Your position is now Enter the result of the die roll: You climbed a ladder! Your position is now
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
