kareltherobot
Class World

java.lang.Object
  extended bykareltherobot.World
All Implemented Interfaces:
Directions

public class World
extends java.lang.Object
implements Directions

Build and maintain the world in which Robots work and play. The normal operation is to show the world in its own frame, which is initially not visible. You can either call World.setVisible(true) to show this frame or extract its Canvas with World.worldCanvas() if you would rather show the world in another context. You can save worlds in files and restore them. You can even create the worlds in a text editor. For information on the external form of worlds see http://csis.pace.edu/~bergin/KarelJava2ed/karelexperimental.html , This format is also assumed by getWorld and is produced by asText when the separator is a newline. Note that the features here are not intended for normal robot programming, but for world initialization and maintenance.


Nested Class Summary
 
Nested classes inherited from class kareltherobot.Directions
Directions.Direction
 
Field Summary
static World asObject
           
 
Fields inherited from interface kareltherobot.Directions
East, EastVal, infinity, North, NorthVal, South, SouthVal, West, WestVal
 
Method Summary
static World asObject()
           
static java.lang.String asText(java.lang.String sep)
          Return a String version of the world's contents suitable for saving and restoring.
static int delay()
          Return the current delay value.
static void getWorld(java.lang.String commands)
          Read a world from a string.
static void makeView()
           
static void placeBeepers(int Street, int Avenue, int howMany)
          Put some beepers on a corner.
static void placeEWWall(int NorthOfStreet, int atAvenue, int lengthTowardEast)
          Place a chain of East-West walls.
static void placeNSWall(int atStreet, int EastOfAvenue, int lengthTowardNorth)
          Place a chain of North-South walls.
static void readWorld(java.lang.String filename)
          Read a world from a file in the current directory.
static void readWorld(java.lang.String directoryPath, java.lang.String filename)
          Read a world from a file in the given directory path.
static void repaint()
          Repaint the world.
static void replaceCloser(java.awt.event.WindowListener w)
          Replace the standard window closer (which calls exit) of the frame with one of your choice.
static void reset()
          Remove everything from this world.
static void resume()
          Resume all the threads after stopping them.
static void saveWorld(java.lang.String filename)
          Save the world in a file in the current directory.
static void saveWorld(java.lang.String directoryPath, java.lang.String filename)
          Save the world in a file in the given directory path.
static void saveXMLWorld(java.lang.String filename)
           
static void saveXMLWorld(java.lang.String directoryPath, java.lang.String filename)
          Save a world in XML format
static void setBeeperColor(java.awt.Color color)
          Change the color of beepers from the standard black to any color you choose.
static void setDelay(int d)
          Slow down the operation of robots in the world.
static void setNeutroniumColor(java.awt.Color color)
          Change the color of walls from the standard black to any color you choose.
static void setOS9Mac(boolean mac)
          HIDE.
static void setSize(int numberOfStreets, int numberOfAvenues)
          Set the size of the world.
static void setStreetColor(java.awt.Color color)
          Change the color of streets and avenues from the standard dark red to any color you choose.
static void setTrace(boolean t)
          Turn tracing on or off.
static void setupThread(java.lang.Runnable r)
          Let a robot run in its own thread.
static void setVisible()
           
static void setVisible(boolean show)
          Make the frame visible or not.
static void setWorldColor(java.awt.Color color)
          Change the color of the background of the world from the standard * white to any color you choose *
static void showSpeedControl(boolean show)
          Make the speed dialog visible or not.
static void showWorld()
          Print a representation of the world's contents on System.out.
static void startThreads()
          Start all the threads initially.
static void stop()
          Suspend all the threads in the world.
static java.awt.Canvas worldCanvas()
          Return the canvas that normally shows in the world's frame.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

asObject

public static final World asObject
Method Detail

asObject

public static final World asObject()

setOS9Mac

public static final void setOS9Mac(boolean mac)
HIDE. Obslolete. Set for opertion on a Macintosh.


placeBeepers

public static void placeBeepers(int Street,
                                int Avenue,
                                int howMany)
Put some beepers on a corner.


worldCanvas

public static java.awt.Canvas worldCanvas()
Return the canvas that normally shows in the world's frame. Use this if you don't want a separate frame, but want the world to appear in some other panel.


placeEWWall

public static final void placeEWWall(int NorthOfStreet,
                                     int atAvenue,
                                     int lengthTowardEast)
Place a chain of East-West walls.


placeNSWall

public static final void placeNSWall(int atStreet,
                                     int EastOfAvenue,
                                     int lengthTowardNorth)
Place a chain of North-South walls.


saveWorld

public static final void saveWorld(java.lang.String filename)
Save the world in a file in the current directory.


saveXMLWorld

public static final void saveXMLWorld(java.lang.String filename)

asText

public static final java.lang.String asText(java.lang.String sep)
Return a String version of the world's contents suitable for saving and restoring.


saveWorld

public static final void saveWorld(java.lang.String directoryPath,
                                   java.lang.String filename)
Save the world in a file in the given directory path.


saveXMLWorld

public static void saveXMLWorld(java.lang.String directoryPath,
                                java.lang.String filename)
Save a world in XML format


showWorld

public static final void showWorld()
Print a representation of the world's contents on System.out.


readWorld

public static final void readWorld(java.lang.String filename)
Read a world from a file in the current directory.


readWorld

public static final void readWorld(java.lang.String directoryPath,
                                   java.lang.String filename)
Read a world from a file in the given directory path.


getWorld

public static void getWorld(java.lang.String commands)
Read a world from a string.


reset

public static final void reset()
Remove everything from this world.


setDelay

public static final void setDelay(int d)
Slow down the operation of robots in the world. A delay of 0 causes poor performance on some systems.


delay

public static final int delay()
Return the current delay value.


resume

public static final void resume()
Resume all the threads after stopping them.


stop

public static final void stop()
Suspend all the threads in the world.


setSize

public static final void setSize(int numberOfStreets,
                                 int numberOfAvenues)
Set the size of the world.


setTrace

public static final void setTrace(boolean t)
Turn tracing on or off. When on (default) robots show their state after actions.


setupThread

public static final void setupThread(java.lang.Runnable r)
Let a robot run in its own thread. Put its "task" into the run method and pass the robot to this method.


showSpeedControl

public static final void showSpeedControl(boolean show)
Make the speed dialog visible or not.


setVisible

public static final void setVisible(boolean show)
Make the frame visible or not. Note that it is invisible by default.


setVisible

public static final void setVisible()

replaceCloser

public static final void replaceCloser(java.awt.event.WindowListener w)
Replace the standard window closer (which calls exit) of the frame with one of your choice. Use null to get one that does nothing at all.


setStreetColor

public static final void setStreetColor(java.awt.Color color)
Change the color of streets and avenues from the standard dark red to any color you choose. *

* Note that the colors set in the world are NOT saved in the world files. * They are just a feature of the current run of the program. *

* @param c the color for streets and avenues


setNeutroniumColor

public static final void setNeutroniumColor(java.awt.Color color)
Change the color of walls from the standard black to any color you choose. *

* Note that the colors set in the world are NOT saved in the world files. * They are just a feature of the current run of the program. *

* @param c the color for walls, which are made of Neutronium, an impenetrable substance


setBeeperColor

public static final void setBeeperColor(java.awt.Color color)
Change the color of beepers from the standard black to any color you choose. *

* Note that the colors set in the world are NOT saved in the world files. * They are just a feature of the current run of the program. *

* @param c the color for beepers.


setWorldColor

public static final void setWorldColor(java.awt.Color color)
Change the color of the background of the world from the standard * white to any color you choose *

* Note that the colors set in the world are NOT saved in the world files. * They are just a feature of the current run of the program. *

* @param color the color for the background of the world.


repaint

public static final void repaint()
Repaint the world. Useful after reset() for example.


startThreads

public static final void startThreads()
Start all the threads initially. Normally called from the speed dialog only.


makeView

public static final void makeView()