// CSE 142, Autumn 2009, Marty Stepp // A FratGuy goes to a "party" at a given randomly chosen location. // The class uses static data so that all the frat guys share the // same party location and go to it together. import java.util.*; public class FratGuy extends Critter { // "shared" - one copy shared by all of the frat guys private static int partyX = -1; private static int partyY = -1; public FratGuy() { if (partyX == -1 && partyY == -1) { // choose a new party location every 10 frat guys Random r = new Random(); partyX = r.nextInt(60); partyY = r.nextInt(50); // System.out.println("Party is at " + partyX + ", " + partyY); } } public Direction getMove() { if (getY() != partyY) { return Direction.NORTH; } else if (getX() != partyX) { return Direction.EAST; } else { // at the party return Direction.CENTER; } } }