uwcse.sim
Class OilThing

java.lang.Object
  |
  +--uwcse.sim.OilThing
All Implemented Interfaces:
Thing
Direct Known Subclasses:
Algae, Fish, OilBlob, Tanker

abstract class OilThing
extends java.lang.Object
implements Thing

The fundamental basis for objects in the OilSpill simulation. Knows its x,y position and the world it lives in.


Field Summary
protected  boolean alive
           
static java.util.Random rand
           
protected  WorldModel world
           
protected  int x
           
protected  int y
           
 
Constructor Summary
OilThing(WorldModel wm, int x, int y)
          Create a new OilThing with the given properties.
 
Method Summary
abstract  void action()
          Leave this to the subclasses.
 void checkNeighbors()
          Asks the world for the things in the same cell, and then calls interact() on each of those things.
abstract  void displayOn(uwcse.graphics.GWindow g)
          Leave this to the subclasses.
 int getX()
          Answer the x position.
 int getY()
          Answer the y position.
 void interact(OilThing t)
          Interact with another OilThing.
 boolean isAlive()
          Answer the flag value.
 void kill()
          Sets the alive flag to false.
 java.lang.String toString()
          Answer the name and location.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rand

public static java.util.Random rand

x

protected int x

y

protected int y

world

protected WorldModel world

alive

protected boolean alive
Constructor Detail

OilThing

public OilThing(WorldModel wm,
                int x,
                int y)
Create a new OilThing with the given properties.
Method Detail

getX

public int getX()
Answer the x position.
Specified by:
getX in interface Thing

getY

public int getY()
Answer the y position.
Specified by:
getY in interface Thing

action

public abstract void action()
Leave this to the subclasses.
Specified by:
action in interface Thing

displayOn

public abstract void displayOn(uwcse.graphics.GWindow g)
Leave this to the subclasses.
Specified by:
displayOn in interface Thing

isAlive

public boolean isAlive()
Answer the flag value.
Specified by:
isAlive in interface Thing

kill

public void kill()
Sets the alive flag to false.

interact

public void interact(OilThing t)
Interact with another OilThing. Is called during checkNeighbors()

checkNeighbors

public void checkNeighbors()
Asks the world for the things in the same cell, and then calls interact() on each of those things.

toString

public java.lang.String toString()
Answer the name and location.
Overrides:
toString in class java.lang.Object