Class UrRobot

java.lang.Object
  extended by greenfoot.Actor
      extended by UrRobot

public class UrRobot
extends greenfoot.Actor

A UrRobot can carry out the five basic operations: move, turnLeft, pickBeeper, putBeeper, and turnOff. Extend this class to solve some interesting problems.

Version:
1.0 (Greenfoot) January 2010
Author:
Joseph Bergin

Constructor Summary
UrRobot()
          Create an EAST facing robot with no beepers
UrRobot(int beepers)
          Create an EAST facing robot with a specified number of beepers
UrRobot(int street, int avenue, KarelWorld.Direction direction, int beepers)
          Create a robot on a specific street and avenue, facing a given direction with a given number of beepers.
UrRobot(KarelWorld.Direction direction)
          Create a robot facing a given direction KarelWorld.EAST, KarelWorld.NORTH, KarelWorld.WEST, or KarelWorld.SOUTH, with no beepers.
UrRobot(KarelWorld.Direction direction, int beepers)
          Create a robot facing a given direction with a given number of beepers in its beeper bag.
 
Method Summary
 void act()
          Act - do nothing.
protected  void addedToWorld(greenfoot.World world)
          used internally
 java.lang.String color()
          Get the current color of this robot
 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.
static void playSounds(boolean play)
          Play a sound at every action when true
 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 setColor(java.lang.String color)
          Set the color of this robot to either "red", "yellow", "blue", or "green".
 void setLocation(int x, int y)
          Used internally.
protected  void sleep()
          Pause the execution for a bit so that users can see what is happening.
 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 greenfoot.Actor
getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getX, getY, intersects, setImage, setImage, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrRobot

public UrRobot()
Create an EAST facing robot with no beepers


UrRobot

public UrRobot(int beepers)
Create an EAST facing robot with a specified number of beepers

Parameters:
beepers - the initial number of beepers in the beeper bag

UrRobot

public UrRobot(int street,
               int avenue,
               KarelWorld.Direction direction,
               int beepers)
Create a robot on a specific street and avenue, facing a given direction with a given number of beepers.

Parameters:
street - the street on which to place the robot
avenue - the avenue on which to place the robot
direction - the direction the robot will initially face
beepers - the initial number of beepers in the beeper bag

UrRobot

public UrRobot(KarelWorld.Direction direction)
Create a robot facing a given direction KarelWorld.EAST, KarelWorld.NORTH, KarelWorld.WEST, or KarelWorld.SOUTH, with no beepers.

Parameters:
direction - the direction the robot will initially face

UrRobot

public UrRobot(KarelWorld.Direction direction,
               int beepers)
Create a robot facing a given direction with a given number of beepers in its beeper bag. If the number of beepers is negative it will be interpreted as infinitely many beepers. You may also use the constant KarelWorld.INFINITE for infinitely many beepers.

Parameters:
direction - the direction the robot will initially face
beepers - the initial number of beepers in the beeper bag
Method Detail

act

public void act()
Act - do nothing. This is used only to test the base code. Subclasses may override this for a robot task.

Overrides:
act in class greenfoot.Actor

addedToWorld

protected void addedToWorld(greenfoot.World world)
used internally

Overrides:
addedToWorld in class greenfoot.Actor

color

public java.lang.String color()
Get the current color of this robot

Returns:
the current color, one of "RED", "YELLOW", "GREEN", and "BLUE".

move

public void move()
The robot will move to the next intersection in the direction it is facing, provided that its front is not blocked. If it is blocked it will generate an error and turn off. If it is not running it does nothing.


pickBeeper

public void pickBeeper()
The robot will pick exactly one beeper from the current corner provided there is at least one there to pick. If there are no beepers on the corner, an error will be issued and the robot will turn off. If it is not running it does nothing.


playSounds

public static void playSounds(boolean play)
Play a sound at every action when true

Parameters:
play - if true the robots will play a sound for every action, move, turnLeft, ...

putBeeper

public void putBeeper()
The robot will put exactly one beeper on the current corner provided that it has at least one in its beeper bag. If it has no beepers an error will be generated and the robot will turn off. If it is not running it does nothing.


setColor

public void setColor(java.lang.String color)
Set the color of this robot to either "red", "yellow", "blue", or "green". The default color is "yellow".


setLocation

public void setLocation(int x,
                        int y)
Used internally. Note that the parameters are NOT street and avenue.

Overrides:
setLocation in class greenfoot.Actor

sleep

protected void sleep()
Pause the execution for a bit so that users can see what is happening.


turnLeft

public void turnLeft()
The robot will turn 90 degrees to the left (counter-clockwise) from its current direction. If it is not running it does nothing.


turnOff

public void turnOff()
The robot will turn off. After it turns off, it will no longer respond to the UrRobot commands.