Class World

java.lang.Object
  extended by World

public class World
extends Object

World is a class representing an environment for Turtles. The world is visualized as a window, and its size can be selected upon construction. As the turtles move around, they are redrawn and they leave tracks on the background in the form of their linear path.


Constructor Summary
World()
          Constructs a world with default size of 400 by 400 pixels.
World(int width, int height)
          Constructs a world with a specified width and height.
 
Method Summary
(package private)  void add(Turtle t)
          Package local method which adds a turtle to this world.
 void disableUpdateOnChange()
          Disables update on change.
(package private)  void drawPath(Turtle t, int xOld, int yOld, int xNew, int yNew)
          Package local method which draws a line from an old position to the new for a given turtle.
 void enableUpdateOnChange()
          Enables update on change.
 int getHeight()
          Returns the height of the world in pixels.
 boolean getUpdateOnChange()
          Returns the current update on change flag.
 int getWidth()
          Returns the width of the world in pixels.
 void remove(Turtle t)
          Removes a turtle from the world.
 String toString()
          Generates a string representation of the world and all the turtles in it.
(package private)  void turtleUpdate()
          Signals that a Turtle has been updated.
 void update()
          Forces a repaint of the world.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

World

public World()
Constructs a world with default size of 400 by 400 pixels.


World

public World(int width,
             int height)
Constructs a world with a specified width and height.

Parameters:
width - The width of the world in pixels.
height - The height of the world in pixels.
Method Detail

remove

public void remove(Turtle t)
Removes a turtle from the world.

Parameters:
t - A reference to the turtle to remove.

getWidth

public int getWidth()
Returns the width of the world in pixels.

Returns:
The width of the world in pixels.

getHeight

public int getHeight()
Returns the height of the world in pixels.

Returns:
The height of the world in pixels.

getUpdateOnChange

public boolean getUpdateOnChange()
Returns the current update on change flag.

Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.

Returns:
The update on change flag.

enableUpdateOnChange

public void enableUpdateOnChange()
Enables update on change.

Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.


disableUpdateOnChange

public void disableUpdateOnChange()
Disables update on change.

Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.


update

public void update()
Forces a repaint of the world.


toString

public String toString()
Generates a string representation of the world and all the turtles in it.

Overrides:
toString in class Object
Returns:
The string representation.

add

void add(Turtle t)
Package local method which adds a turtle to this world.

Parameters:
t - Turtle to be added to the world.

turtleUpdate

void turtleUpdate()
Signals that a Turtle has been updated.


drawPath

void drawPath(Turtle t,
              int xOld,
              int yOld,
              int xNew,
              int yNew)
Package local method which draws a line from an old position to the new for a given turtle.