|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcs1705.TestableWorld
cs1705.World
public class World
This class can be used to build and maintain the world in which robots work and play.
This class is a subclass of the original kareltherobot.World
class, with some enhancements. Most notably, it provides a
startFromURL(String) method that makes it trivial to initialize
the world from a URL, show the frame, and show the speed controls.
Similar startFromFile(String) and startFromString(String)
methods are also provided.
The original class's readWorld() method was difficult
to use within BlueJ.
You can save worlds in files and restore them. You can even create a world definition in a text editor. Information on the external form of worlds is available from Bergin's web site.
| Method Summary | |
|---|---|
static int |
delay()
Return the current delay setting. |
static World |
getWorldAsObject()
Returns the singleton instance of this class. |
static String |
getWorldDescription()
Returns the configuration of the current world as a string. |
static void |
overrideNextStartUsingFile(String fileName)
Define the file name to read a world description from on the next startFrom...() call. |
static void |
overrideNextStartUsingString(String world)
Define the world description tu use on the next startFrom...() call. |
static void |
overrideNextStartUsingURL(String url)
Define the URL to read a world description from on the next startFrom...() call. |
static void |
reset()
Remove everything from the world and returns it to a pristine state. |
static void |
setDelay(int d)
Slow down (or speed up) the operation of robots in the world. |
static void |
setSize(int numberOfStreets,
int numberOfAvenues)
Set the size of the world. |
static void |
setTrace(boolean tracingOn)
Turns tracing on or off. |
static void |
setupThread(Runnable runnable)
Sets up a runnable object (usually a robot) in a separate thread that will be executed in parallel with the world simulation. |
static void |
setVisible(boolean show)
Show or hide the world's graphic frame. |
static void |
showSpeedControl(boolean show)
Show or hide the speed dialog. |
static void |
startEmpty()
Initializes Karel's world to be completely empty. |
static void |
startFromFile(String fileName)
Initializes Karel's world by reading the world configuration file from the file indicated by the given file name. |
static void |
startFromString(String world)
Initializes Karel's world from the given string. |
static void |
startFromURL(String url)
Initializes Karel's world by downloading the world configuration file from a URL, given as a string. |
static void |
startThreads()
Starts all of the threads associated with this world, so they begin executing in parallel. |
static void |
waitForRobotThreads()
Wait until all concurrently executing robot threads have completed. |
| Methods inherited from class cs1705.TestableWorld |
|---|
assertBeepersAt, assertBeepersAt, assertBeepersInWorld, assertBeepersInWorld, assertEWWallAt, assertNoBeepersAt, assertNoBeepersInWorld, assertNoEWWallAt, assertNoNSWallAt, assertNoRobotsInWorld, assertNSWallAt, assertRobotsInWorld, assertRobotsInWorld |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static int delay()
public static World getWorldAsObject()
public static String getWorldDescription()
public static void overrideNextStartUsingFile(String fileName)
startFrom...() call.
This method is primarily useful for testing. Typically, a
RobotTask will call World.startFrom...()
to indicate the initial world configuration to use. Often, to
fully test such tasks, you would like to start often with a
different world (maybe several different worlds or start locations,
each in a different test case). Using this method at the start
of your test case allows you to "override" the behavior of
the RobotTask's call to World.startFrom...()
so that the world description specified here will be used instead.
fileName - a String object that contains an
absolute or relative pathname indicating the file to
read. The world file contents are then used to
construct the world that Karel will navigate.public static void overrideNextStartUsingString(String world)
startFrom...() call.
See the comments under overrideNextStartUsingFile(String).
world - A world description as a stringpublic static void overrideNextStartUsingURL(String url)
startFrom...() call.
See the comments under overrideNextStartUsingFile(String).
url - a String object that contains the fully
qualified URL from which to read the world file. The
world file contents are then used to construct the
world that Karel will navigate.public static void reset()
public static void setDelay(int d)
public static void setSize(int numberOfStreets,
int numberOfAvenues)
public static void setTrace(boolean tracingOn)
System.out
after each action.
public static void setupThread(Runnable runnable)
public static void setVisible(boolean show)
public static void showSpeedControl(boolean show)
public static void startEmpty()
public static void startFromFile(String fileName)
fileName - a String object that contains an
absolute or relative pathname indicating the file to
read. The world file contents are then used to
construct the world that Karel will navigate.public static void startFromString(String world)
world - A world description as a stringpublic static void startFromURL(String url)
url - a String object that contains the fully
qualified URL from which to read the world file. The
world file contents are then used to construct the
world that Karel will navigate.public static void startThreads()
public static void waitForRobotThreads()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||