import java.util.Random; /** * The WatchYourStep game is a game of traps. You get 10 guesses and if you select correct * you win, but if you sect one of the 10 bad traps, you lose. * * John Sloan * 01-15-09 */ public class WatchYourStep { //Debug: false hides the traps, true displays the traps (doesn't work. personal project) public static boolean debug = false; private int [] A; private Random rand; /** * Constructs: * initializes a new array (A) with 100 integers. * creates a variable from the random collection. */ public WatchYourStep() { A = new int [100]; rand = new Random(); } /** * showTrap method shows the traps you don't want to step on. */ public void showTraps() { //comment these print methods to hide the traps from the player. System.out.println("The secret traps are:"); for(int i=0; i= 0 && UserGuess <= 99){ if(A[UserGuess] == 2){ System.out.println("You selected number " + UserGuess+ ", You already guessed that number dummy, guess again"); } if(A[UserGuess] == 0){ System.out.println("You selected number " + UserGuess+ ", Excellent choise! You got it right pick again"); A[UserGuess] = 2; GameTries++; } if(A[UserGuess] == 1){ System.out.println("You selected number " + UserGuess+ ", You hit a trap! Games Over"); Trapped = true; } } } if(GameTries == 10){ System.out.println(); System.out.println("Congradulatins, You Win!"); } } /** * showInstructions method */ public void ShowInstructions(){ System.out.println(); System.out.println("Watch Your Step"); System.out.println(); System.out.println("There are 100 squares, numbered 0 to 99."); System.out.println("10 of these squares have a trap hidden in them."); System.out.println("To win, you must try to step on 10 squares,"); System.out.println("without stepping on one with a trap."); System.out.println(); System.out.println("Good Luck!"); System.out.println(); System.out.println("Choose a square"); System.out.println(); } /** * Debug Method: */ public static void debug(String str) { if(debug) System.out.print(str); } /** * */ public static void main() { WatchYourStep wys = new WatchYourStep(); wys.PlayGame(); } }