public void processTime() { for (FarmObject obj : list) { if (obj instanceof Cow) { trace("Cow!"); Cow temp = (Cow) obj; // dead if (obj.doStuffInAHour(WorldObject.currentHour)) { obj.removeObjectFromFarm(this); } trace("Cow! pass"); if (temp.awake() && obj.generateNewLocation(grid.length)) { if (grid[obj.getNewX()][obj.getNewY()] == null) { move(obj); temp.UpdateToNewLocation(); } else if (grid[obj.getNewX()][obj.getNewY()] instanceof Grass) { Grass grass = (Grass) grid[obj.getNewX()][obj.getNewY()]; if (grid[obj.getNewX()][obj.getNewY()] instanceof PoisonedGrass) { temp.setSicknessLevel(temp.getSicknessLevel() + grass.getAmount()); } temp.setHungriness(temp.getHungriness() - grass.getAmount()); grass.removeObjectFromFarm(this); move(obj); temp.UpdateToNewLocation(); } } } if (obj instanceof Grass) { Grass grass = (Grass) obj; if (grass.doStuffInAHour(WorldObject.currentHour)) { if (grass.generateNewLocation(grid.length)) { Grass newGrass = new Grass(grass.getNewX(), grass.getNewY()); addFarmObjectToGrid(newGrass); addFarmObjectToList(newGrass); } } } } }
private void move(FarmObject obj) { grid[obj.getX()][obj.getY()] = null; grid[obj.getNewX()][obj.getNewY()] = obj; }