Nathan Coulas

CCC '03 S1 - Snakes and Ladders

ccc03s1 JAVA8 07 Feb, 2020 0.476s 5 points

Source Code

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String args[]) {
		
		Scanner in = new Scanner(System.in);
		int rolled;
		int position = 1;
		
		do {
			rolled = in.nextInt();
			if(rolled == 0){
				System.out.println("You Quit!");
				break;
			}
			
			if(position + rolled <= 100) {
				position += rolled;
			}
			position = snakeCheck(position);
		
			if(position >= 100) {
				System.out.println("You are now on square " + 100);
				System.out.println("You Win!");
				break;
			}else {
				System.out.println("You are now on square " + position);
			}
			
			
			
		}while(rolled != 0);
		return;
	}
	
	public static int snakeCheck(int pos) {
		
		switch(pos) {
		
		case(9):
			return 34;
		
		case(40):
			return 64;
		
		case(54):
			return 19;
		
		case(67):
			return 86;
		
		case(90):
			return 48;
		
		case(99):
			return 77;
		
		
		}
		
		return pos;
	}
	
}