/*****************************************************************************
** File:             Magic8Ball.java
** Author:           pitter@cs.wisc.edu 
** Course:           CS 302, Spring 2000
** Compiler:         CodeWarrior Release 4, JDK 1.2
** Platform:         Windows NT 4.0
*************************************************************************/
import javabook.*;


/**
 * This class implements a magic 8 ball using a Die object.
 *
 * Bugs: none known
 **/

class Magic8Ball {

    /**         
    * Magic 8 Ball main program
    **/       
    public static void main (String[] args){
    	MainWindow mainwindow = new MainWindow ("Magic8Ball");
	mainwindow.show();
	InputBox inputbox = new InputBox(mainwindow);
	OutputBox output = new OutputBox (mainwindow);
	output.show();
	boolean keepGoing = true;
	
        // create 20 sided die
        Die icosahedron = new Die(20);
	
	output.printLine("Welcome to the Magic8Ball....");
	
        while(keepGoing){
	    
	    inputbox.getString("Ask your question now.");
	    icosahedron.roll();
	    
            // display message corresponding to die's top side
            switch (icosahedron.getTop()) {
	         case  1: output.printLine("Outlook Good"); 
		          break;
	         case  2: output.printLine("Outlook Not So Good"); 
		          break;
	         case  3: output.printLine("My Reply Is No"); 
		          break;
	         case  4: output.printLine("Don't Count On It"); 
		          break;
	         case  5: output.printLine("You May Rely On It");
		          break;
	         case  6: output.printLine("Ask Again Later"); 
		          break;
                 case  7: output.printLine("Most Likely"); 
		          break;
                 case  8: output.printLine("Cannot Predict Now"); 
		          break;
	         case  9: output.printLine("Yes"); 
		          break;
	         case 10: output.printLine("Yes Definately"); 
		          break;
                 case 11: output.printLine("Better Not Tell You Now"); 
		          break;
                 case 12: output.printLine("It Is Certain"); 
		          break;
	         case 13: output.printLine("Very Doubtful"); 
		          break;
                 case 14: output.printLine("It Is Decidedly So"); 
		          break;
                 case 15: output.printLine("Concentrate and Ask Again");
		          break;
                 case 16: output.printLine("Signs Point to Yes"); 
		          break;
                 case 17: output.printLine("My Sources Say No"); 
		          break;
                 case 18: output.printLine("Without a Doubt"); 
		          break;
	         case 19: output.printLine("Reply Hazy, Try Again"); 
		          break;
                 case 20: output.printLine("As I See It, Yes"); 
		          break;
	    default: output.printLine("Psychic temporarily out of service.");
	    }
	    
	    // check to see if user wants to ask another question
	    int i = inputbox.getInteger("enter 0 to exit, and 1 to continue");
	    if(i==0){
		keepGoing=false;
		output.printLine("Good bye.");
            }
	}
    }
}
