/*              Simple program to try and guess a number
 *               with input and output via Display class 
 *
 *    File: IfGuess/java
 *    Compile with :      javac IfGuess.java
 *    Run with :          java IfGuess
 */

import uk.ac.ed.ph.sciprog.*;                  // Display class


public class IfGuess {
    public static void main(String args[]) {

	//                  Setup the Display (one prompt)

	Display panel = new Display("Guess a number");
	Input guessInput = new Input("Next try (between 1-10)",0);
	panel.addInput(guessInput);

	//                  Set a target (Random number between 1-10)

	final int TARGET = (int)(10.0*Math.random()) + 1; 	

	//                  Loop asking for input and checking
	//                  reponse

	while(true) {                         // Infinte loop
	    
	    //              Read number from display
	    panel.waitForButtonPress();
	    int guess = guessInput.getInt();

	    //              Check to see if it matched the TARGET,
	    //              if so print message and break loop.

	    if (guess == TARGET) {
		panel.printLine("You guessed correctly, the Target was " +
			      TARGET);
		break;                      // Exit the loop
	    }
	    
	    //              Not correct, print message and go round again

	    panel.println("You got it wrong, try again");
	}
	
	//               Outside the loop, print message and
	//               wait for Close button

        panel.println("Press Close to exit the program");
    }
}
		
	    
