package logo.lang;

import java.util.Enumeration;
import logo.lang.rLogoPrimitive;

public class rLogoHelp {

   rLogoPrimitive r = new rLogoPrimitive();

   public String topic(String s) { //note: this is *too big* for the runtime version!
      String result=new String();
      if (s==null || s.trim().length()==0) {
        result="Try 'help topic_name' (or 'help topics' to ";
        result=result.concat("list all topics)");
      } else
      switch ( r.lookup(s.toLowerCase()) ) {
          case rLogoPrimitive.TOPICS :
            result=result.concat("Help is available for the following topics:\n");
            Enumeration cmdList=r.keys();
            while ( cmdList.hasMoreElements() ) {
              result=result.concat((String)cmdList.nextElement()+" ");
            }
            result=result.concat("\nType 'help topic_name' for more information");
            break;
          case rLogoPrimitive.TOPIC_NAME :
            result=result.concat("Instead of typing 'help topic_name' literally, try ");
            result=result.concat("typing the word 'help' followed by the name of the ");
            result=result.concat("topic for which you need help. For example, 'help ");
            result=result.concat("forward' gives help on the'forward' command. You ");
            result=result.concat("may also wish to try 'help tutorial' for a short ");
            result=result.concat("introductory tutorial, and 'help topics' to list ");
            result=result.concat("all available topics.");

            break;
          case rLogoPrimitive.TUTORIAL :
            result=result.concat("rLogo Tutorial.\n");
            result=result.concat("rLogo is a mini programming language, designed to  ");
            result=result.concat("help beginners learn about computer programming.  ");
            result=result.concat("It is also a powerful language that can be used to ");
            result=result.concat("create dynamic graphics for use in World Wide Web ");
            result=result.concat("pages. Type 'help tutorial2' for the next part of  ");
            result=result.concat("this tutorial.");
            break;
          case rLogoPrimitive.TUTORIAL2 :
            result=result.concat("rLogo centers on the Turtle, which is the name for ");
            result=result.concat("the small triangle located at the top of the screen. ");
            result=result.concat("You may control the turtle by clicking the 'forward,'  ");
            result=result.concat("'right,' 'left,' 'back,' and 'home' buttons,  ");
            result=result.concat("or by typing simple commands into the Command Box. ");
            result=result.concat("To move the turtle forward (and draw a line),  ");
            result=result.concat("type 'forward' followed by a number that tells it  ");
            result=result.concat("how far to move forward. For example, try typing  ");
            result=result.concat("'forward 20' (and don't type the quote marks ('')  ");
            result=result.concat("Type 'help tutorial3' for the rest of this tutorial.");
            break;
          case rLogoPrimitive.TUTORIAL3 :
            result=result.concat("As soon as you are comfortable with that, try typing  ");
            result=result.concat("'left 45' For some more introductory commands,  ");
            result=result.concat("try 'help back''help right''help penup'  ");
            result=result.concat("'help pendown' and 'help penup' These should ");
            result=result.concat("get you started!");
            break;
          case rLogoPrimitive.SHOW :
            result=result.concat("show (expression) - prints out the value ");
            result=result.concat("of the named expression in the Command Box ");
            result=result.concat("Note: most arithmetic expressions need to ");
            result=result.concat("be enclosed in parentheses (like '(2+3)*5')");
            break;
          case rLogoPrimitive.RUN :
            result=result.concat("run [list] - executes the statements contained ");
            result=result.concat("in the list. ");
            break;
          case rLogoPrimitive.REPEAT :
            result=result.concat("repeat (count) [ list ] - repeatedly executes ");
            result=result.concat("the statements contained in the list count times.");
            break;
          case rLogoPrimitive.WHILE :
            result=result.concat("while (condition) [ list ] - executes the statements ");
            result=result.concat("in the list as long as condition evaulates to true ");
            result=result.concat("(true is any non-zero expression)");
            break;
          case rLogoPrimitive.IF_ELSE :
            result=result.concat("ifelse (conditon) [true_list] [false_list] - if  ");
            result=result.concat("condition evaluates to true, executes the statements ");
            result=result.concat("in [true_list], otherwise, executes the statements ");
            result=result.concat("in [false_list].");
            break;
          case rLogoPrimitive.MAKE :
            result=result.concat("make name (value) - assigns a value to the named variable. ");
            result=result.concat("Note: You must preceded the variable name with a colon ");
            result=result.concat("when using it in an expression (e.g. 'forward :length')");
            break;
          case rLogoPrimitive.TO :
            result=result.concat("to subroutine_name - starts the editor on the named subroutine. ");
            break;
          case rLogoPrimitive.FORWARD :
            result=result.concat("forward (distance) - causes the turtle to move forward ");
            result=result.concat("the specified number of units. May be abbreviated as 'fd'");
            break;
          case rLogoPrimitive.BACK :
            result=result.concat("back (distance) - causes the turtle to move backward the ");
            result=result.concat("specified number of units. May be abbreviated as 'bk'");
            break;
          case rLogoPrimitive.RIGHT :
            result=result.concat("right (degrees) - causes the turtle to turn the specified ");
            result=result.concat("number of degrees to the right. May be abbreviated as 'rt'");
            break;
          case rLogoPrimitive.LEFT :
            result=result.concat("left (degrees) - causes the turtle to turn the specified ");
            result=result.concat("number of degrees to the left. May be abbreviated as 'lt'");
            break;
          case rLogoPrimitive.PEN_UP :
            result=result.concat("penup - causes the turtle to stop drawing, until the 'pendown' ");
            result=result.concat("command is issued. May be abbreviated as 'pu'");
            break;
          case rLogoPrimitive.PEN_DOWN :
            result=result.concat("pendown - causes the turtle to resume drawing after a 'penup' ");
            result=result.concat("command. May be abbreviated as 'pd'");
            break;
          case rLogoPrimitive.SHOW_TURTLE :
            result=result.concat("showturtle - causes the turtle to re-appear after a 'hideturtle' ");
            result=result.concat("command. May be abbreviated as 'st'");
            break;
          case rLogoPrimitive.HIDE_TURTLE :
            result=result.concat("hideturtle - causes the turtle to hide; i.e. to disappear from ");
            result=result.concat("the screen. This effect is merely visual; the turtle retains its ");
            result=result.concat("normal functionality. May be abbreviated as 'ht'");
            break;
          case rLogoPrimitive.CLEAR_SCREEN :
            result=result.concat("clearscreen - erases the screen. May be abbreviated as 'cs' ");
            break;
          case rLogoPrimitive.AUTO :
            result=result.concat("auto - Returns the screen to its normal state, where the screen ");
            result=result.concat("refreshes automatically. Used after the 'manual' command. ");
            result=result.concat("Try 'help manual' for more information.");
            break;
          case rLogoPrimitive.MANUAL :
            result=result.concat("manual - Until the 'auto' command is invoked, no screen refreshes ");
            result=result.concat("will occur automatically. While the turtle is still active, its ");
            result=result.concat("drawings will not occur until a 'paint' command is received. This ");
            result=result.concat("is useful for animations and other visual effects.");
            break;
          case rLogoPrimitive.PAINT :
            result=result.concat("paint - Forces the screen to refresh immediately. Used in  ");
            result=result.concat("conjunction with 'manual' Try 'help manual' for more information.");
            break;
          case rLogoPrimitive.HOME :
            result=result.concat("home - Returns the turtle to its 'home' position, the center ");
            result=result.concat("of the screen.");
            break;
          case rLogoPrimitive.SET_PEN_COLOR :
            result=result.concat("setpencolor (red) (green) (blue) - Causes future drawing to occur ");
            result=result.concat("in the specified color. The 3 parameters specify the relative amount ");
            result=result.concat("of the color to 'mix together' and range from 0 to 255. May be ");
            result=result.concat("abbreviated as 'setpc'");
            break;
          case rLogoPrimitive.SET_BACK_COLOR :
            result=result.concat("setbackcolor (red) (green) (blue) - Causes the background to  ");
            result=result.concat("change to the specified color. May be abbreviated as 'setbc' Try ");
            result=result.concat("'help setpc' for more information.");
            break;
          case rLogoPrimitive.WRITE :
            result=result.concat("write (string) - writes string at the current turtle location. ");
            result=result.concat("Does not currently support writing at any angle other than 90 degrees");
            break;
          case rLogoPrimitive.PAUSE :
            result=result.concat("pause (duration) - causes rLogo to pause for the specified number ");
            result=result.concat("of milliseconds (e.g. 1000 is 1 second). Meant to be used within ");
            result=result.concat("subroutines for visual effects; unexpected results may occur if ");
            result=result.concat("you type commands in the Command Box while a 'pause' is in effect.");
            break;
          case rLogoPrimitive.PARAMS :
            result=result.concat("params [ param1 param2 ...] - Used to pass parameters to a subroutine. ");
            result=result.concat("When the first line of a subroutine begins with 'params', it will ");
            result=result.concat("expect to be invoked with parameters. This is equivalent to typing ");
            result=result.concat("'make var1 value1' 'make var2 value2' before invoking the subroutine. ");
            result=result.concat("Example: (copy this & type 'batch', paste it in, and click 'finished' ");
            result=result.concat("to try it out)\n");
            result=result.concat("to demonstrate\n");
            result=result.concat("params [x y]\n");
            result=result.concat("show x\n");
            result=result.concat("show y\n");
            result=result.concat("end\n");
            result=result.concat("demonstrate 12 13");
            break;
          case rLogoPrimitive.BATCH :
            result=result.concat("batch - places rLogo into batch command mode. All commands entered ");
            result=result.concat("will be immediately executed when 'finished' is clicked. This is how ");
            result=result.concat("rLogo 'loads' files, typically by using cut-and-paste. Try 'help dump' ");
            result=result.concat("for more information.");
            break;
          case rLogoPrimitive.DUMP :
            result=result.concat("dump - dumps all variable definitions and subroutines into the editor. ");
            result=result.concat("You may copy this & paste it into a text-editor or word-processor for ");
            result=result.concat("permanent storage. Use the 'dump' command to load it back in later.");
            break;
          case rLogoPrimitive.END :
            result=result.concat("This command has no effect, except that it must be placed at the ");
            result=result.concat("end of a procedure definition when being loaded with the 'batch' ");
            result=result.concat("command. You will probably never need to use this.");
            break;
          case rLogoPrimitive.HELP :
            result=result.concat("help (topic) - displays help for the named topic. Use 'help topics' ");
            result=result.concat("for a list of all available topics.");
            break;
          default :
            result=result.concat("Sorry; no help is available for "+s);
      }

      return result;
   }

}
