|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Scene alice.kareltherobot.KarelWorld
public abstract class KarelWorld
A basis for creating worlds in which robots may perform tasks.
You must create a subclass and override two methods to use this. Set up all of the walls, beepers, and robots in your setTheStage method and put the task for the robots in the run method.
Field Summary | |
---|---|
static int |
INFINITE
Represents infinitely many beepers either in the world or in some robot's beeper bag. |
Constructor Summary | |
---|---|
KarelWorld()
Performs basic set up of the world. |
|
KarelWorld(GalleryModel groundImage)
Create a world with a given background image for the ground. |
Method Summary | |
---|---|
void |
addComponent(Transformable item)
If the component is a robot it will set that robot's speed to the default speed of the world. |
void |
addDecorations()
Add some decoration to the world. |
UrRobot |
addRobot(UrRobot karel)
Add a robot to this world (usually invoked in setTheStage) and give the robot a speed equal to the current default speed of this world. |
void |
cameraFollow(AbstractCamera camera,
Model model)
Specify an object (in class Model) to be tracked by a camera. |
void |
cameraFollow(Model model)
Specify an object (in class Model) to be tracked by the standard camera. |
void |
cameraStayFocusedOn(int street,
int avenue)
Point the camera at a particular corner and keep it pointed there if the camera moves |
void |
cameraStayFocusedOn(int street,
int avenue,
double height)
Point the camera at a spot above or below a particular corner and keep it pointed there if the camera moves |
void |
clearBeepers(int street,
int avenue)
Remove all beepers from a given corner |
static KarelWorld |
currentWorld()
Obtain a reference to the most recently constructed world |
double |
defaultSpeed()
Get the current speed of the simulation |
SymmetricPerspectiveCamera |
getCamera()
Obtain a reference to the main camera of this world. |
void |
moveCameraTo(int street,
int avenue,
double height)
Move the camera to a point above (or below) a particular corner |
void |
moveCameraTo(int street,
int avenue,
double height,
double duration)
Move the camera to a point above (or below) a particular corner |
void |
placeBeepers(int street,
int avenue,
int howMany)
Place any number of beepers on a corner |
void |
placeWallEastOf(int street,
int avenue)
Place a one segment vertical wall East of a given corner |
void |
placeWallNorthOf(int street,
int avenue)
Place a one segment horizontal wall North of a given corner |
void |
readWorld(java.lang.String filename)
Read a world from a file in the current directory. |
void |
readWorld(java.lang.String directoryPath,
java.lang.String filename)
Read a world from a file in the directory given by the path. |
void |
removeWallEastOf(int street,
int avenue)
Remove any wall segment one half block east of a given corner |
void |
removeWallNorthOf(int street,
int avenue)
Remove any wall segment one half block north of a given corner |
void |
reset()
Remove all walls and beepers from the world. |
abstract void |
run()
Override this for the task to be performed in your own world. |
void |
saveWorld(java.lang.String filename)
Save a world to a file in the current directory. |
void |
saveWorld(java.lang.String directoryPath,
java.lang.String filename)
Save the world in a file in the given directory path. |
void |
say(java.lang.String message)
Ask the ground image to say something |
void |
setSpeed(double defaultSpeed)
Set the default speed of robots created in this world. |
abstract void |
setTheStage()
Override this to set up your robots, walls, and beepers for the task to be executed by the run command |
void |
show2DScene(int minStreet,
int minAvenue,
int maxStreet,
int maxAvenue)
Show a static but saveable window with the current world components (walls, beepers, and robots) It is useful for printing a visual representation (map) of the world. |
void |
think(java.lang.String message)
Ask the ground image to think something |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INFINITE
Constructor Detail |
---|
public KarelWorld()
public KarelWorld(GalleryModel groundImage)
If you click on the background, then the world will respond to the following keys
Up-Arrow doubles the speed of the simulation
Down-Arrow halves the speed
Left-Arrow moves the camera back (out) a bit
Right-Arrow moves the camera forward (in) a bit
groundImage
- the GaleryModel ground image to use for the backgroundMethod Detail |
---|
public static KarelWorld currentWorld()
public SymmetricPerspectiveCamera getCamera()
public void setSpeed(double defaultSpeed)
defaultSpeed
- the default speed of robots in this world.public double defaultSpeed()
public void show2DScene(int minStreet, int minAvenue, int maxStreet, int maxAvenue)
If you use extension ".ps" it will create a PostScript file suitable for printing or translating to a PDF. If you use something like ".gif" it will create a graphic file in that format if possible. (gif, png, jpg, possibly others).
Note that the world is drawn rotated with the origin at the upper left corner of the page, so that north points to the left, and east downward.
This was written by Cay Horstmann with a few minor edits by Joe Bergin. It is useful for producing handouts for students or documenting your work by taking a "snapshot" of the world at the point at which it is invoked.
minStreet
- the first (southern-most) street (with a 1 street buffer provided)minAvenue
- the first (western-most) avenue (with a 1 avenue buffer provided)maxStreet
- the last streetmaxAvenue
- the last avenuepublic void cameraStayFocusedOn(int street, int avenue)
street
- the street at which to pointavenue
- the avenue at which to pointpublic void cameraStayFocusedOn(int street, int avenue, double height)
street
- the street at which to pointavenue
- the avenue at which to pointheight
- the height of the focus of the camerapublic void moveCameraTo(int street, int avenue, double height)
street
- the street to move the camera toavenue
- the avenue to move the camera toheight
- the new height of the camerapublic void moveCameraTo(int street, int avenue, double height, double duration)
street
- the street to move the camera toavenue
- the avenue to move the camera toheight
- the new height of the cameraduration
- the amount of time it takes the camer to movepublic void cameraFollow(AbstractCamera camera, Model model)
camera
- the camera that will trackmodel
- the object that will be trackedpublic void cameraFollow(Model model)
model
- the robot that will be trackedpublic abstract void setTheStage()
public abstract void run()
public void say(java.lang.String message)
message
- what to saypublic void think(java.lang.String message)
message
- what to thinkpublic final UrRobot addRobot(UrRobot karel)
karel
- the robot to be added
public void addComponent(Transformable item)
org.alice.apis.moveandturn.Composite#addComponent(org.alice.apis.moveandturn.Transformable)
public void addDecorations()
public final void readWorld(java.lang.String filename)
filename
- the name of the file in the current directory to readpublic final void readWorld(java.lang.String directoryPath, java.lang.String filename)
directoryPath
- a valid path to the directory containing the file (may be null
for current directory).filename
- the name of the file in the current directory to readpublic final void saveWorld(java.lang.String filename)
filename
- the name of the file to writepublic 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 void placeBeepers(int street, int avenue, int howMany)
street
- the street on which to place the beepersavenue
- the avenue on which to place the beepershowMany
- how many beepers to place (-1 means infinity)public void clearBeepers(int street, int avenue)
street
- the street from which to remove beepersavenue
- the avenue from which to remove beeperspublic void placeWallEastOf(int street, int avenue)
street
- the street that the wall will crossavenue
- the avenue that will be just west of the new wall segmentpublic void removeWallEastOf(int street, int avenue)
street
- the street that the wall crosses (if any)avenue
- the avenue just west of the wall (if any)public void removeWallNorthOf(int street, int avenue)
street
- the street just south of the wall (if any)avenue
- the avenue that the wall crosses (if any)public void placeWallNorthOf(int street, int avenue)
street
- the street that will be just south of the new wall segmentavenue
- the avenue that the wall will crosspublic void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |