|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkareltherobot.World
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, infinity, North, South, West |
Method Summary | |
static World |
asObject()
Obtain a singleton object representing the world |
static java.lang.String |
asText(java.lang.String sep)
Return a String version of the world's contents suitable for saving and restoring. |
static void |
clearBeepers(int Street,
int Avenue)
Clear all beepers, if any, from the given corner. |
static int |
delay()
Return the current delay value. |
static void |
getWorld(java.lang.String commands)
Read a world from a string. |
static void |
makeView()
This is normally not called, but is left public for the rare situations (like embedding this system in another) in which you need to manually create the view system. |
static void |
placeBeepers(int Street,
int Avenue,
int howMany)
Put some (additional) beepers on a corner. |
static void |
placeEWWall(int NorthOfStreet,
int atAvenue,
int lengthTowardEast)
Place a chain of one or more east west walls |
static void |
placeNSWall(int atStreet,
int EastOfAvenue,
int lengthTowardNorth)
Place a chain of one or more 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 |
removeEWWall(int NorthOfStreet,
int atAvenue)
Remove a single east-west wall segment. |
static void |
removeNSWall(int atStreet,
int EastOfAvenue)
Remove a signle north-south wall segment |
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)
Save a representation of th eworld in XML format. |
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 |
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()
Toggle the visibility state. |
static void |
setVisible(boolean show)
Make the frame visible or not. |
static void |
setVisible(boolean show,
int width,
int height)
Set the world visible or invisible and simultaneously set its pixel size. |
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 |
showBeepers()
Show a report about all the beepers in the world on System.out |
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 |
public static final World asObject
Method Detail |
public static final World asObject()
public static void placeBeepers(int Street, int Avenue, int howMany)
Street
- the street of the required cornerAvenue
- the avenue of the required cornerhowMany
- the number of beepers. An integer or "infinity"public static void clearBeepers(int Street, int Avenue)
Street
- the street of the required cornerAvenue
- the avenue of the required cornerpublic static java.awt.Canvas worldCanvas()
public static final void placeEWWall(int NorthOfStreet, int atAvenue, int lengthTowardEast)
NorthOfStreet
- the chain of walls will be north of this streetatAvenue
- the first segment will cross this avenuelengthTowardEast
- how many avenues to cross toward the eastpublic static final void placeNSWall(int atStreet, int EastOfAvenue, int lengthTowardNorth)
atStreet
- the first segment will cross this streetEastOfAvenue
- the chain of walls will be east of this avenuelengthTowardNorth
- how many strets to cross toward the northpublic static final void removeEWWall(int NorthOfStreet, int atAvenue)
NorthOfStreet
- the wall north of this streetatAvenue
- the segment that crosses this avenuepublic static final void removeNSWall(int atStreet, int EastOfAvenue)
atStreet
- the segment that crosses this streetEastOfAvenue
- the wall east of this avenuepublic static final void saveWorld(java.lang.String filename)
filename
- the name of the file to be savedpublic static final void saveXMLWorld(java.lang.String filename)
filename
- the name of the file to savepublic static final java.lang.String asText(java.lang.String sep)
sep
- the separator to use between world commands, generally newlinepublic static final void saveWorld(java.lang.String directoryPath, java.lang.String filename)
directoryPath
- a full path to the directory in which to save the filefilename
- the name of the file to be savedpublic static void saveXMLWorld(java.lang.String directoryPath, java.lang.String filename)
directoryPath
- a full path to the directory in which to save the filefilename
- the name of the file to be savedpublic static final void showBeepers()
public static final void showWorld()
public static final void readWorld(java.lang.String filename)
filename
- the name of the file in the current directory to readpublic static final void readWorld(java.lang.String directoryPath, java.lang.String filename)
directoryPath
- a full path to the file containing the worldfilename
- the nameof the file to readpublic static void getWorld(java.lang.String commands)
commands
- a string in the form of a world file. Tokens are
separated by the usual white spacepublic static final void reset()
public static final void setDelay(int d)
d
- the delay. The delay is the opposite of speed.public static final int delay()
public static final void resume()
public static final void stop()
public static final void setSize(int numberOfStreets, int numberOfAvenues)
numberOfStreets
- the number of streets to show. This sets the vertical
size of the world's window.numberOfAvenues
- the number of avenues to show. If they won't fit in
the visible window, a scroller will be created.public static final void setTrace(boolean t)
t
- turn tracing on if true. It is on by default.public static final void setupThread(java.lang.Runnable r)
r
- any runnable object, not just a robotpublic static final void showSpeedControl(boolean show)
show
- show the speed dialog if truepublic static final void setVisible(boolean show)
show
- show the world if truepublic static final void setVisible(boolean show, int width, int height)
show
- true to show the world, false to hide itwidth
- the number of pixels of width in the windowheight
- the number of pixels of height in the windowpublic static final void setVisible()
public static final void replaceCloser(java.awt.event.WindowListener w)
w
- a new WindowListener or nullpublic static final void setStreetColor(java.awt.Color color)
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.
color
- the color for streets and avenuespublic static final void setNeutroniumColor(java.awt.Color color)
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.
color
- the color for walls, which are made of Neutronium, an impenetrable substancepublic static final void setBeeperColor(java.awt.Color color)
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.
color
- the color for beepers.public static final void setWorldColor(java.awt.Color color)
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.
color
- the color for the background of the world.public static final void repaint()
public static final void startThreads()
public static final void makeView()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |