예제 #1
0
파일: Farm.java 프로젝트: anitayen423/APCS
 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);
         }
       }
     }
   }
 }
예제 #2
0
파일: Farm.java 프로젝트: anitayen423/APCS
 private void move(FarmObject obj) {
   grid[obj.getX()][obj.getY()] = null;
   grid[obj.getNewX()][obj.getNewY()] = obj;
 }