// Helene Martin, CSE 142 // Hister critters congregate at a cheap bar. The bar's location is randomly initialized by the // first Hipster created. // Hipsters move north until reaching the y coordinate of the bar and then east until // reaching the x coordinate of the bar. import java.util.*; public class Hipster extends Critter { // static makes this a shared location private static int cheapBarX = -1; private static int cheapBarY = -1; public Hipster() { if (cheapBarX < 0 && cheapBarY < 0) { // if the location hasn't been chosen yet, this // is the first Hipster and needs to choose a location. Random r = new Random(); cheapBarX = r.nextInt(60); cheapBarY = r.nextInt(50); } } // Move N then E until the bar is reached public Direction getMove() { if (getY() != cheapBarY) { return Direction.NORTH; } else if (getX() != cheapBarX) { return Direction.EAST; } else { // reached the bar return Direction.CENTER; } } }