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

public abstract class PlagueVictim extends RandomWalker {
  // OVERVIEW: A PlagueVictim is a person who is within the vicinity of an
  //           ongoing virus.

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

  public PlagueVictim() {//default
    inTurn = false;
    state = "uninfected";
  }

  public PlagueVictim(String s) {
    inTurn = false;
    state = s;
  }

  public abstract void becomeInfected();

  public void infect(){
    //@assume state != null
    if (state.equals("uninfected")){
      return;
    }
    else {
      Enumeration neighbors = getNeighbors ();
      while (neighbors.hasMoreElements ()) {
        SimObject neighbor = (SimObject) neighbors.nextElement ();

        if (neighbor instanceof PlagueVictim) {
          double num = Math.random();
          if (num <= PlagueSimulator.plagueStrength){
            if (this.hashCode()> neighbor.hashCode()){
              synchronized (neighbor) {
                synchronized (this) {
                  ((PlagueVictim)neighbor).becomeInfected();
                }
              }
            }
            else {
              synchronized (this) {
                synchronized (neighbor) {
                  ((PlagueVictim)neighbor).becomeInfected();
                }
              }
            }
          }
        }
      }
    }
  }
}