|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object KoalaRobot alice.kareltherobot.UrRobot
public class UrRobot
A UrRobot can carry out the five basic operations: move, turnLeft, pickBeeper, putBeeper, and turnOff. Extend this class to solve some interesting problems. If you click on a robot in the world, it will tell you about its current state.
Constructor Summary | |
---|---|
UrRobot(int street,
int avenue,
Direction direction)
Constructs a robot at a given corner facing a given direction, with no beepers. |
|
UrRobot(int street,
int avenue,
Direction direction,
int beepers)
Create a robot on a specific street and avenue, facing a given direction with a given number of beepers. |
|
UrRobot(int street,
int avenue,
Direction direction,
int beepers,
Color color)
Create a robot on a specific street and avenue, facing a given direction with a given number of beepers and a given head color. |
Method Summary | |
---|---|
void |
assertFacingEast()
Assert that the robot is facing east. |
void |
assertFacingNorth()
Assert that the robot is facing north. |
void |
assertFacingSouth()
Assert that the robot is facing south. |
void |
assertFacingWest()
Assert that the robot is facing west. |
void |
assertFrontIsBlocked()
Assert that the robot's front is blocked. |
void |
assertFrontIsClear()
Assert that the robot's front is clear. |
void |
assertHasBeepers()
Assert that the robot as at least one beeper in its beeper bag Throw an exception otherwise |
void |
assertHasNoBeepers()
Assert that the robot's beeper bag is empty Throw an exception otherwise |
void |
assertNextToABeeper()
Assert that the robot's corner has at least one beeper Throw an exception otherwise |
void |
assertNextToARobot()
Assert that the robot's corner has at least one other robot Throw an exception otherwise |
void |
assertOnAvenue(int avenue)
Assert that the robot is on a given avenue. |
void |
assertOnStreet(int street)
Assert that the robot is on a given street. |
java.lang.String |
currentState()
Return the state of this robot |
AbstractCamera |
getCamera()
Get a reference to a camera from the world of this robot |
KarelWorld |
getWorld()
Get the world to which this object has been added (but only after you add it). |
void |
move()
The robot will move to the next intersection in the direction it is facing, provided that its front is not blocked. |
void |
pickBeeper()
The robot will pick exactly one beeper from the current corner provided there is at least one there to pick. |
void |
putBeeper()
The robot will put exactly one beeper on the current corner provided that it has at least one in its beeper bag. |
void |
setSpeed(double newSpeed)
Set the speed with which this robot operates. |
void |
setTracing(boolean trace)
Turn tracing on or off. |
void |
turnLeft()
The robot will turn 90 degrees to the left (counter-clockwise) from its current direction. |
void |
turnOff()
The robot will turn off. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UrRobot(int street, int avenue, Direction direction)
street
- the street of the robot (>= 1)avenue
- the avenue of the robot (>= 1)direction
- the original direction that the robot facespublic UrRobot(int street, int avenue, Direction direction, int beepers)
street
- the street on which to place the robot (>= 1)avenue
- the avenue on which to place the robot (>= 1)direction
- the direction the robot will initially facebeepers
- the initial number of beepers in the beeper bagpublic UrRobot(int street, int avenue, Direction direction, int beepers, Color color)
street
- the street on which to place the robot (>= 1)avenue
- the avenue on which to place the robot (>= 1)direction
- the direction the robot will initially facebeepers
- the initial number of beepers in the beeper bagcolor
- the color of this robot's headMethod Detail |
---|
public void setSpeed(double newSpeed)
newSpeed
- the new speed >0.0 and <= 100.0public KarelWorld getWorld()
public void turnOff()
public AbstractCamera getCamera()
public void setTracing(boolean trace)
trace
- true to turn tracing on.public void move()
public void turnLeft()
If timing is important to your simulation, note that a robot can turn completely around (four turnLeft instructions) in about the same time as it can move one block.
public void pickBeeper()
public void putBeeper()
public java.lang.String currentState()
public void assertFacingEast()
java.lang.RuntimeException
- if the robot is not facing eastpublic void assertFacingNorth()
java.lang.RuntimeException
- if the robot is not facing northpublic void assertFacingSouth()
java.lang.RuntimeException
- if the robot is not facing southpublic void assertFacingWest()
java.lang.RuntimeException
- if the robot is not facing westpublic void assertFrontIsClear()
java.lang.RuntimeException
- if the robot's front is blocked by a wallpublic void assertFrontIsBlocked()
java.lang.RuntimeException
- if the robot's front is clearpublic void assertHasBeepers()
java.lang.RuntimeException
- if the robot's beeper bag is emptypublic void assertHasNoBeepers()
java.lang.RuntimeException
- if the robot has any beepers in its beeper bagpublic void assertOnAvenue(int avenue)
avenue
- the avenue the robot is supposed to be on
java.lang.RuntimeException
- if the robot is not on the given avenuepublic void assertOnStreet(int street)
street
- the street the robot is supposed to be on
java.lang.RuntimeException
- if the robot is not on the given streetpublic void assertNextToABeeper()
java.lang.RuntimeException
- if the robot's corner has no beeperspublic void assertNextToARobot()
java.lang.RuntimeException
- if the robot's corner has no other robots
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |