import java.util.*; import java.awt.*; /** An OilBlob is a blob of oil. It drifts around the world and consumes Fish and Algae. @author Ben Dugan, Hal Perkins CSE 142 Summer 2001, Homework 6 */ public class OilBlob implements Thing { private static Random rand = new Random(); private int x, y; /** Create a new oil blob at the given location. */ public OilBlob(int x, int y) { this.x = x; this.y = y; } /** Display the oil blob (a black oval) onto the graphics window. */ public void display(GWindow g) { g.display(new Oval(this.x, this.y, 6, 6, Color.black, true)); } /** Oil blobs move more or less at random. */ public void move() { int dx = rand.nextInt(7) - 3; int dy = rand.nextInt(7) - 3; this.x = this.x + dx; this.y = this.y + dy; } /** Oil blobs consume Algae and Fish. */ public boolean consumes(String kindOfThing) { return kindOfThing.equals("Algae") || kindOfThing.equals("Fish"); } /** OilBlob doesn't do anything interesting when it consumes things. */ public void consume(String kindOfThing) {} /** Answer "OilBlob". */ public String kindOfThing() { return "OilBlob"; } /** OilBlobs don't spawn (luckily). */ public void spawn(ArrayList c) {} /** Answer the x position. */ public int getX() { return this.x; } /** Answer the y position. */ public int getY() { return this.y; } /** Answer the name and location. */ public String toString() { return "OilBlob: (" + this.x + "," + this.y + ")"; } }