JavaKara
World editor
Program editor
JavaKaraProgramm
Info

Your JavaKara programs have to be subclassed from the class JavaKaraProgram. This way they will be embedded into the JavaKara runtime environment. In your class, you have to overwrite the method public void myProgram(). This method is going to be executed as a "main program".

Within your class you have access to three different objects, which are inherited from the JavaKaraProgram class. Do not change these three objects, e.g. by trying to create a new Kara using kara=new JavaKara();! The newly created Kara would not be embedded into the environment and therefore invisible. The three objects you can access are:

How does JavaKara work? When executing your own program, a new Thread is started. The class JavaKaraProgram is the link from your program to JavaKara. Important: Since your program runs within its own thread, JavaKara cannot control it, for instance, pause or stop your program`s execution.

This is why a small trick is applied: Each time you make use of any of Kara's commands - kara.move() or kara.turnRight() etc - the method tools.checkState() is called first. This method checks whether the program should pause or even stop; otherwise the thread goes to sleep for an amount of time corresponding to the adjustment of the execution speed controller. You should make sure that your program calls either any of the Kara methods or the tools.checkState()-method! Otherwise you might happen to program an infinite loop, for instance, that cannot be stopped anymore without terminating JavaKara.

Note: If you want to write a program that uses your own classes, these classes have to be located in the same directory as your JavaKaraProgram subclasses. This relates to the way your JavaKara subclasses are going to be loaded. Classes such as java.awt.Point can be used without any restrictions.

Note: In a constructor of a Java class derived from a JavaKaraProgram, the programmer is prevented from accessing three objects: kara, world and tools! Furthermore, no constructor is allowed to receive parameters. Only if these conditions are satisfied, your JavaKaraProgram subclass is linked to the objects kara, world and tools.

kara  
   void move() A step forward
   void turnLeft() 90° left turn
   void turnRight() 90° right turn
   void putLeaf() Lay cloverleaf down
   void removeLeaf() Pick cloverleaf up
   boolean treeFront() Kara in front of a tree?
   boolean treeLeft() Is there a tree to Kara`s left?
   boolean treeRight() Is there a tree to Kara's right?
   boolean onLeaf() Is Kara on top of a cloverleaf?
   boolean mushroomFront() Is Kara in front of a mushroom?
   void setPosition (int x, int y) Put Kara at position (x,y)
   java.awt.Point getPosition() Returns the coordinates of Kara's current position

world  
   void clearAll() Remove all elements
   void setLeaf (int x, int y, boolean putLeaf) Lay down a leaf or pick one up
   void setTree (int x, int y, boolean putTree) Plant or remove tree
   void setMushroom (int x, int y, boolean putMushroom) Plant or remove mushroom
   void setSize (int newSizeX, int newSizeY) Change world size
   boolean isEmpty (int x, int y) Field empty?
   boolean isTree (int x, int y) Is there a tree on the field?
   boolean isMushroom (int x, int y) Is there a mushroom on the field?
   boolean isLeaf (int x, int y) Is there a leaf on the field?
   int getSizeX() Horizontal world size
   int getSizeY() Vertical world size

tools  
   void println (String string) Write string to standard output
   void showMessage (String message) Write string to a dialog window
   int random (int bound) Returns random number in the range [0..bound]
   void checkState() Checks the execution controller
   void sleep (int ms) Sleeps ms milliseconds
   String stringInput (String title) Lets the user input a string in a dialog window with a title. Returns null if the dialog is aborted using Cancel.
   int intInput (String title) Lets the user input a integer number in a dialog window with a title. Returns Integer.MIN_VALUE if the dialog is aborted using Cancel.
   double doubleInput (String title) Lets the user input a real number in a dialog window with a title. Returns Double.MIN_VALUE if the dialog is aborted using Cancel.