Hey guys I have a program that runs the basics for chutes and ladders, the only problem is I need to keep track of spaces moved via die roll, chutes, and ladders. I am not too sure how to implement this is my already existing code all help is appreciated. Thanks.
Here is my code
package program1;
import java.util.Random;
public class Program1 {
public static final double GOAL_NUMBER = 100;
public static void main(String[] args) {
int forwardMoves, backwardMoves, location, roll, turn, skipped;
Random rand = new Random();
location = 0;
turn = 1;
skipped = 0;
do {
roll = rand.nextInt(6) + 1;
System.out.println("Turn #" + turn + " Position: " + location + " Roll: " + roll + ":");
location += roll;
if (location > GOAL_NUMBER) {
location = location - roll;
System.out.println(" Went past the end! Turn skipped");
turn = turn + 1;
skipped = skipped + 1;
}
if (location <= GOAL_NUMBER) {
switch (location) {
case 1:
location = 38;
System.out.println("You potted a plant! Climb to 38!");
break;
case 5:
location = 14;
System.out.println("You made cookies! Climb to 14!");
break;
case 9:
location = 31;
System.out.println("You mowed the yard! Climb to 31!");
break;
case 15:
location = 6;
System.out.println("You skipped your homework. Slide down to 6!");
break;
case 21:
location = 42;
System.out.println("You helped a puppy! Climb to 42!");
break;
case 28:
location = 84;
System.out.println("You rescued a cat! Climb to 84!");
break;
case 36:
location = 44;
System.out.println("You cleaned your room! Climb to 44!");
break;
case 47:
location = 26;
System.out.println("You skated on thin ice, slide down to 26!");
break;
case 49:
location = 11;
System.out.println("You ate too much candy, slide down to 11!!");
break;
case 51:
location = 68;
System.out.println("You swept the floor! Climb to 68!");
break;
case 56:
location = 53;
System.out.println("You played in mud, slide down to 83!");
break;
case 62:
location = 19;
System.out.println("You dropped the dishes, slide down to 19!;");
break;
case 64:
location = 60;
System.out.println("You rode your bike no handed, slide down to 60!");
break;
case 71:
location = 91;
System.out.println("You returned lost money! Climb to 91!");
break;
case 80:
location = 100;
System.out.println("You helped and Injured friend! Climb to 100!");
break;
case 87:
location = 24;
System.out.println("You stole from the cookie jar, slide down to 24!");
break;
case 93:
location = 73;
System.out.println("You threw dirt. slide down to 73!");
break;
case 95:
location = 75;
System.out.println("You broke the window, slide down to 75!");
break;
case 98:
location = 78;
System.out.println("You pulled a cats tail, slide down to 78!");
break;
}
System.out.println(" Moved to space #" + location);
turn = turn + 1;
}
} while (location < GOAL_NUMBER);
System.out.println("Game Over! Goal Reached!");
System.out.println("Game Stats:");
System.out.println("Number of turns: " + turn);
System.out.println("Number of turns skipped by passing goal: " + skipped);
}
}