import java.awt.Color;
import java.util.Enumeration;

public class ImmuneWalker extends PlagueVictim {
  // OVERVIEW: An ImmuneWalker is a healthy person who is immune to the virus.
  //           He walks around randomly.  When he meets a person carrying the
  //           virus he becomes a carrier and will spread the virus to every
  //           healthy person he meets.

  private boolean inTurn; // Currently in the middle of a turn used for coloring.

  public ImmuneWalker () {
    super();//used only for constructors
    inTurn = false;
    PlagueSimulator.setImmuneCount(PlagueSimulator.immuneCount + 1);
  }

  public Color getColor()
  {
   //@assume state != null
    if (!inTurn && state.equals("uninfected")){
      //@assume Color.yellow !=null
      return Color.yellow.darker();
    }
    else if (inTurn && state.equals("uninfected")){
      return Color.yellow;
    }
    else if (!inTurn && state.equals("carrier")){
      //@assume Color.green !=null
      return Color.green.darker();
    }
    else if (inTurn && state.equals("carrier")){
      return Color.green;
    }
    else
      return null;
    } //@nowarn NonNullResult // ESC/Java doesn't know Color constants are not null

  public synchronized void becomeInfected() {
    //@assume state != null
    if (state.equals("uninfected")){
      state= "carrier";
      PlagueSimulator.setCarrierCount(PlagueSimulator.carrierCount + 1);
      PlagueSimulator.setImmuneCount(PlagueSimulator.immuneCount - 1);
    }
  }

   public void executeTurn () throws RuntimeException
    // Note: requires isInitialized is inherited from SimObject
    // EFFECTS: Picks a random direction and tries to move that way.
    //          If the move is successful, return true. If the move fails
    //          because the spot being attempted to move into is already
    //          occupied then return false.
    {
      inTurn=true;
      super.executeTurn();
      infect();
      inTurn=false;
    }
}