COP 2220 Project 4: Simulation of Chutes and Ladders solved

$25.00

Original Work ?

Download Details:

  • Name: game.zip
  • Type: zip
  • Size: 194.27 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (5 votes)
In this project we will build a simulation of the children’s board game Chutes and Ladders.
https://en.wikipedia.org/wiki/Snakes_and_Ladders The board game is given in the attached
image.
Step 1: Write a one dimensional array to represent the board. The array element i should hold
the final array position should we land on board game space i. See the attached board image
below. If our player lands on square 1, query array position 1 which gives us square 38. If our
player lands on square 2 the array should return 2 since no ladder or slide began at 2.
The array looks like:
int gameboard[100] =
{38,2,3,14,5,6,7,8,31,10,
11,12,13,14,15,6,16,18,19,20,
42,22,23,24,25,26,27,84,29,30,
31,32,33,34,35,44,37,38,39,40,
41,42,43,44,45,46,26,48,11,50,
67,52,53,54,55,53,57,58,59,60,
61,19,63,60,65,66,67,68,69,70,
91,72,73,74,75,76,77,78,79,100,
81,82,83,84,85,86,24,88,89,90,
91,92,73,94,75,96,97,78,99,100};
Step 1: Write a function DiceRoll that returns an integer value. This function should generate a
random integer between 1 and 6.
Step 2: Write a function named UpdatePositionByTakingTurn
The input arguments to the function are:
1. The game board array
2. The current position
3. The dice roll
The output of the function is an integer representing the new position of the player after they
have moved from their current position to their new position.
This function should also print out a message that tells the player their old position, new
position, and their updated position if they landed on a chute or ladder.
Note that if the new position would be greater than 100, the player is not moved from their
current position. They need to land on 100 exactly.
Step 3: Write your main such that it repeatedly calls dice roll and then updates the position until
the user position is 100. It should print a message telling the player they won, and also print out
the number of moves that it took the user to win.
Notes:
1. The random number generator is seeded with time(NULL), by using function
srand(time(NULL));
2. To get the game to pause and then progress by pressing enter to initiate the dice roll the
solution file uses:
printf(“Press Enter to roll dice: \n”);
getchar();