import java.util.*; import java.awt.*; /** A Fish swims around the world eating Algae. @author Ben Dugan, Hal Perkins CSE 142 Summer 2001, Homework 6 */ public class Fish implements Thing { private static Random rand = new Random(); private int x, y, algaeEaten; /** Create a new fish at this location. */ public Fish(int x, int y) { this.x = x; this.y = y; this.algaeEaten = 0; } /** Display a yellow oval. */ public void display(GWindow g) { g.display(new Oval(this.x, this.y, 6, 6, Color.yellow, true)); } /** Move around at random. */ public void move() { int dx = rand.nextInt(5) - 2; int dy = rand.nextInt(5) - 2; this.x = this.x + dx; this.y = this.y + dy; } /** Spawn every time we eat 5 algae. */ public void spawn(ArrayList v) { // unimplemented right now. } /** Fish consume only Algae. */ public boolean consumes(String kindOfThing) { return kindOfThing.equals("Algae"); } /** If we're presented with an Aglae, we eat it, and remember it. */ public void consume(String kindOfThing) { if (kindOfThing.equals("Algae")) { this.algaeEaten = this.algaeEaten + 1; } } /** Answer "Fish". */ public String kindOfThing() { return "Fish"; } /** Answer the x position. */ public int getX() { return this.x; } /** Answer the y position. */ public int getY() { return this.y; } /** Answer the name and position. */ public String toString() { return "Fish: (" + this.x + "," + this.y + ")"; } }