becker.robots
Class Sim

java.lang.Object
  extended by becker.robots.Sim
Direct Known Subclasses:
Intersection, Robot, Thing

public abstract class Sim
extends Object

A Sim is an element of the robot city which participates in the simulation, namely a Thing (such as Walls, Lights), a Robot, or an Intersection.

Since this class is abstract it cannot be instantiated; only subclasses may be instantiated. This class exists to ensure that basic services required for the simulation are present and to provide common implementations for required several services.

Author:
Byron Weber Becker

Constructor Summary
Sim(City aCity, int aStreet, int anAvenue, Direction orientation, Icon anIcon)
          Construct a new Sim.
 
Method Summary
 City getCity()
          Returns a reference to this sim's city.
 Color getColor()
          Get this sim's color.
 Icon getIcon()
          Return the icon used to display the visible characteristics of this sim, based on the sim's current state.
protected abstract  Intersection getIntersection()
          Return the intersection where this Sim is located.
protected  void keyTyped(char key)
          This method is called when a key is typed and keyboard input is directed to karel's world (the map, as opposed to a different window or the controls for karel's world).
 void notifyObservers()
          Notify any observers of this Sim (for instance, the user interface) that it has changed.
protected  void notifyObservers(Object changeInfo)
          Notify any observers of this Sim (for instance, the user interface) that it has changed.
 void setColor(Color color)
          Set this sim's color.
 void setIcon(Icon theIcon)
          Set the icon used to display this sim.
 String toString()
          Print this object represented as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sim

public Sim(City aCity,
           int aStreet,
           int anAvenue,
           Direction orientation,
           Icon anIcon)
Construct a new Sim.

Parameters:
aCity - The city in which the Sim will exist.
aStreet - The Sim's initial street within the city.
anAvenue - The Sim's initial avenue within the city.
orientation - The Sim's initial orientation. One of {Direction.NORTH, EAST, SOUTH, WEST, NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST}.
anIcon - The icon to use to display this Sim.
Method Detail

setColor

public void setColor(Color color)
Set this sim's color.

Parameters:
color - The new color for this Sim.

getColor

public Color getColor()
Get this sim's color.

Returns:
this sim's color.

getIcon

public Icon getIcon()
Return the icon used to display the visible characteristics of this sim, based on the sim's current state.

Returns:
The icon used to display this sim.

setIcon

public void setIcon(Icon theIcon)
Set the icon used to display this sim.

Parameters:
theIcon - The new icon to use in displaying this Sim.

notifyObservers

public void notifyObservers()
Notify any observers of this Sim (for instance, the user interface) that it has changed.


notifyObservers

protected void notifyObservers(Object changeInfo)
Notify any observers of this Sim (for instance, the user interface) that it has changed.

Parameters:
changeInfo - Any extra information required by the observer.

getIntersection

protected abstract Intersection getIntersection()
Return the intersection where this Sim is located.

Returns:
The intersection where this Sim is located.

keyTyped

protected void keyTyped(char key)
This method is called when a key is typed and keyboard input is directed to karel's world (the map, as opposed to a different window or the controls for karel's world). Override the method to add behavior.

Parameters:
key - The key that was typed.

toString

public String toString()
Print this object represented as a string.

Overrides:
toString in class Object

getCity

public City getCity()
Returns a reference to this sim's city.