예제 #1
0
  /** Draws graphics to the image */
  public void draw() {

    Graphics graphics = image.getGraphics();

    // 1. blank the previous image
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, IMAGE_SIZE, IMAGE_SIZE);

    // 2. move then draw each critter.
    for (Critter critter : critterList) {
      critter.move();
      critter.draw(graphics);
    }
  }
예제 #2
0
파일: Follower.java 프로젝트: bohuim/Harker
 /**
  * Method: makeMove() Usage: last step in act() of Critter
  * ------------------------------------------- Follower faces the same way target is and steps are
  * incremented, if target is null, it faces the direction it just moved in then calls Critters
  * makeMove to go to the new location @Postcondition: (1) <code>getLocation() == loc</code>. (2)
  * The state of all actors other than those at the old and new locations is unchanged.
  *
  * @param loc the location to move to
  */
 public void makeMove(Location loc) {
   if (target != null) {
     setDirection(target.getDirection());
     steps++;
   } else setDirection(getLocation().getDirectionToward(loc));
   super.makeMove(loc);
 }
예제 #3
0
  /** Starts the game object */
  public void start() {
    // 1. put the game in the state that it is not over.
    isOver = false;
    lastClick = true;

    // 2. construct an ArrayList of new Critters.
    //    For each Critter that you create, use the critterFactory to randomly select a subclass of
    // Critter to instantiate.
    critterList = new LinkedList<>();

    for (int i = 0; i < 3; i++) {
      critterList.add(critterFactory.makeCritter());
    }
  }