import processing.core.*; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; import javax.sound.midi.*; import javax.sound.midi.spi.*; import javax.sound.sampled.*; import javax.sound.sampled.spi.*; import java.util.regex.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.sax.*; import javax.xml.transform.stream.*; import org.xml.sax.*; import org.xml.sax.ext.*; import org.xml.sax.helpers.*; public class updatedcode4 extends PApplet {PImage myPerson;
PImage redPerson;
PImage deadPerson;
PImage city;
PImage title;
boolean preGameFlag;      //true=preGame (wait for mouseclick) , false=game in play

Person[] People;//This describes what kimd of data the array contains.
Animal[] Animal;
Doctor[] Doctor;
Undertaker[] Undertaker;

int n = 100; //Number of people.
int na = 100; //Number of animals.
int nd = 10; //number of doctors
int nu = 30; //number of undertakers
int computeDelay = 0;
int healthyCount = 0;
int sickCount = 0;
int deadCount = 0;

public void setup()
{
  title = loadImage("title.gif");
  city = loadImage("map.gif");
  /*myPerson = loadImage("personwhite.gif");
   redPerson = loadImage("redperson.gif");
   deadPerson = loadImage("deadghost.gif");*/
  preGameFlag = true;                 //starts with preGame text and waits for mouseclick

  size(800, 600, P3D);//Processing's 3 mode is being used to make it run faster.
  frameRate(30);
  noStroke();
  //smooth();
  PFont statusFont;

  statusFont = loadFont("Univers-Bold-48.vlw");
  textFont(statusFont);
  People = new Person[n];//This is how large the array is.
  Animal = new Animal[na];
  Doctor = new Doctor[nd];
  Undertaker = new Undertaker[nu];

  for(int J = 0;J<n;J++){ //Populates array with people
    People[J] = new Person(PApplet.parseInt(random(width)),PApplet.parseInt(random(height)));//This assigns a random location for each person.
  }
  for(int I = 0;I<na;I++){ //Populates array with animals
    Animal[I] = new Animal(PApplet.parseInt(random(width)),PApplet.parseInt(random(height)));//This assigns a random location for each person.
  }

  for(int I = 0;I<nu;I++){ //Populates array with animals
    Undertaker[I] = new Undertaker(PApplet.parseInt(random(width)),PApplet.parseInt(random(height)));//This assigns a random location for each person.
  }

  for(int J = 0;J<10;J++){//this defines how many people start off sick.
    People[J].health = 1;  
  }
  for(int I = 0;I<10;I++){//this defines how many people start off sick.
    Animal[I].health = 1;  

  }

  for(int U = 0;U<10;U++){//this defines how many people start off sick.
    Undertaker[U].health = 1;  

  }
}

public void draw() {
  if (preGameFlag){        //if this is true then the game is not in play
    preGame();
  } 
  else { 

    /*    if (keyPressed){
     if (key == 'D' || key == 'd'){  
     for(int I = 0;I<nd;I++){ //Populates array with doctors
     Doctor[I] = new Doctor((mouseX),(mouseY));//This assigns a random location for each person.
     }
     }
     
     } */

    if (mousePressed){
      for(int I = 0;I<nd;I++){ //Populates array with doctors
        Doctor[I] = new Doctor((mouseX),(mouseY));//This assigns a random location for each person.
      }
    }

    background(city);
    fill(255);
    textSize(18);
    text("People (" + checkHealth() + ")", 100, 100, 100);
    //  text("Living = " + checkHealth(), 100, 400, 100);
    fill(0, 255, 0);
    textSize(15);
    text("Sick : " + checkSick(), 100, 120, 100);
    fill(211,9,9);
    text("Dead : " + checkDead(), 100, 140, 100);

    textSize(18);
    fill(227,196,158);
    text("Animals (" + checkHealthAnimal() + ")", 100, 450, 100); //text shows living animals
    fill(0, 255, 0);
    textSize(15);
    text("Sick : " + checkSickAnimal(), 100, 470, 100); //text shows sick animal
    fill(211,9,9);
    text("Dead : " + checkDeadAnimal(), 100, 490, 100); //text shows dead animal

    for(int J = 0;J<n;J++){
      People[J].Draw();
      People[J].Move();
      People[J].checkHit();
      People[J].disease();

      /*  if(computeDelay < 5)
       {
       computeDelay++;
       }
       else if(computeDelay == 5)
       {*/

      // }
    }

    for(int I = 0;I<na;I++){
      Animal[I].Draw();
      Animal[I].Move();
      Animal[I].checkHit();
      Animal[I].disease();
    }


    for(int I = 0;I<nd;I++){
      Doctor[I].Draw();
      Doctor[I].Move();
      Doctor[I].checkHit();
      Doctor[I].disease();
    }

    for(int U = 0;U<nd;U++){
      Undertaker[U].Draw();
      Undertaker[U].Move();
      Undertaker[U].checkHit();

    }


    //print(checkHealth());
    //print(checkHealthAnimal());
  }
}

public int checkSick(){
  //Returns number of sick people.
  int S = 0;
  for(int J = 0;J<n;J++){ 
    if(People[J].health == 1){
      S++;//H returns the number of sick people.
    }
  }
  return S;
}

public int checkSickAnimal(){
  //Returns number of sick people.
  int Sa = 0;
  for(int I = 0;I<na;I++){ 
    if(Animal[I].health == 1){
      Sa++;//H returns the number of sick people.
    }
  }
  return Sa;
}

public int checkHealth(){
  //Returns number of sick people.
  int H = 0;
  for(int J = 0;J<n;J++){ 
    if(People[J].health == 0){
      H++;//H returns the number of sick people.
    }
  }
  return H;
}

public int checkHealthAnimal(){
  //Returns number of sick people.
  int Ha = 0;
  for(int I = 0;I<na;I++){ 
    if(Animal[I].health == 0){
      Ha++;//H returns the number of sick people.
    }
  }
  return Ha;
}

public int checkDead(){
  //Returns number of sick people.
  int De = 0;
  for(int J = 0;J<n;J++){ 
    if(People[J].health == 2){
      De++;//De returns the number of sick people.
    }
  }
  return De;
}

public int checkDeadAnimal(){
  //Returns number of sick people.
  int Da = 0;
  for(int I = 0;I<na;I++){ 
    if(Animal[I].health == 2){
      Da++;//De returns the number of sick people.
    }
  }
  return Da;
}
/*     preGame - freezes last game, prints title info and waits for a mouse click to start game */
public void preGame (){
  fill(255,0,0);                              //red font

  text ("Click Game to Begin", 110, 100);
  background(title);

  if (mousePressed == true) {                //checks for mouseclick from player
    preGameFlag = false;                     //starts gameplay

  }

}

class Person {
  int x = 0;
  int y = 0;
  int mortality = 100;
  boolean move = true;
  float z = 0;
  int index;
  int health = 0;
  int seed = PApplet.parseInt(random(200));
  boolean quarantinePeople = false;


  Person(int X,int Y){
    x = X;
    y = Y;

  }


  /*
   The conditions for health are as follows, 0 = healthy, 1 = sick, 2 = dead.
   */
  public void Draw(){
    if(health == 0){
      stroke(2);
      fill(255);
      //  image(myPerson, x, y);
      ellipse(x,y,13,13);//The healthy are white and fat circles.
    }
    else if(health == 1){
      stroke(1);
      fill(0,255,0);
      //    image(redPerson, x, y);
      ellipse(x,y,10,10);//The sick are green and emaciated. They also move slower
    }
    else{
      move = false;
      fill(211,9,9);
      //  image(deadPerson, x, y);
      ellipse(x,y,8,8);//the dead are red and immobile.
    }

    //QUARANTINE BOTTOM RIGHT CORNER
    if ((mouseX > 400) && (mouseX < 800) && (mouseY > 300 ) && (mouseY < 600)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (People[I].health == 1 && People[I].x > 400 && People[I].x < 800 && People[I].y > 300 && People[I].y < 600) {
              quarantinePeople=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(400, 300, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 460, 450);
              People[I].move = false;
            }
          }
        }
      }
    }
    //QUARANTINE TOP RIGHT CORNER
    if ((mouseX > 400) && (mouseX < 800) && (mouseY > 0 ) && (mouseY < 300)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (People[I].health == 1 && People[I].x > 400 && People[I].x < 800 && People[I].y > 0 && People[I].y < 300) {
              quarantinePeople=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(400, 1, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 450, 150);
              People[I].move = false;
            } 
          }
        }
      }
    }
    //QUARANTINE TOP LEFT CORNER
    if ((mouseX > 0) && (mouseX < 400) && (mouseY > 0 ) && (mouseY < 300)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (People[I].health == 1 && People[I].x > 0 && People[I].x < 400 && People[I].y > 0 && People[I].y < 300) {
              quarantinePeople=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(1, 1, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 140, 150);
              People[I].move = false;
            }

          }
        }
      }
    }

    //QUARANTINE BOTTOM LEFT CORNER
    if ((mouseX > 0) && (mouseX < 400) && (mouseY > 300 ) && (mouseY < 600)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (People[I].health == 1 && People[I].x > 0 && People[I].x < 400 && People[I].y > 300 && People[I].y < 600) {
              quarantinePeople=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(1, 300, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 50, 450);
              People[I].move = false;
            }
          }
        }
      }
    }
  }

  public void Move(){
    if(move == true){
      noiseSeed(seed);
      x+=PApplet.parseInt(noise(z)*20-10);
      y+=PApplet.parseInt(noise(z-200)*20-10);
      z+=.1f;
    }
  }

  public void checkHit(){//This is collision detction, the sick will transmit the disease by touch.
    for(int J = 0;J<n;J++){
      float D = dist(People[J].x,People[J].y,x,y);
      if((D<10)&&(People[J].health == 1)&&(health != 2)){
        health = 1; 
      }
    }
    for(int J = 0;J<n;J++){
      float D = dist(People[J].x,People[J].y,x,y);
      if((D<10)&&(People[J].health == 2)&&(health < 1)){
        health = 1; 
      }
    }
    for(int J = 0;J<n;J++){
      for(int I = 0;I<n;I++){
        float D = dist(People[J].x,People[J].y,Animal[I].x,Animal[I].y);
        if((D<10)&&(People[J].health == 2)&&(Animal[I].health < 1)){
          Animal[I].health = 1; 
        }
      }
    }

    for(int J = 0;J<n;J++){
      for(int I = 0;I<na;I++){
        float D = dist(People[J].x,People[J].y,Animal[I].x,Animal[I].y);
        if((D<10)&&(People[J].health == 2)&&(Animal[I].health < 1)){
          Animal[I].health = 1; 
        }
      }
    }

    for(int J = 0;J<n;J++){
      for(int I = 0;I<na;I++){
        float D = dist(People[J].x,People[J].y,Animal[I].x,Animal[I].y);
        if((D<10)&&(Animal[I].health == 2)&&(People[J].health < 1)){
          People[J].health = 1; 
        }
      }
    }


      for(int I = 0;I<na;I++){
        float D = dist(Animal[I].x,Animal[I].y,x,y);
        if((D<10)&&(Animal[I].health == 2)&&(Animal[I].health < 1)){
          Animal[I].health = 1; 
        }
      }
    


    // SICK ANIMALS MAKE HEALTHY PEOPLE SICK
    for(int I = 0;I<na;I++){ 
      for (int J = 0;J<n;J++) {
        float A = dist(Animal[I].x,Animal[I].y,People[J].x,People[J].y);
        if((A<10)&&(Animal[I].health == 1)&&(People[J].health == 0)&&(health != 2)){
          People[J].health = 1; 
        }
      }

    }

    /*  for(int I = 0;I<n;I++){
     float A = dist(People[I].x,Animal[I].y,x,y);
     if((A<10)&&(People[I].health == 1)&&(health != 2)){
     health = 2; 
     }
     
     
     
     }
     */
  }


  public void disease(){//This sets the paramaters for the disease.
    if(health == 1){
      mortality--;
    }
    if(mortality==0){
      health = 2;
      move = false;
      sickCount--;
      deadCount++;
    }
  }
  /*
return sickCount;
   return deadCount;
   return healthyCount;
   */
}


class Animal {
  int x = 0;
  int y = 0;
  int mortality = PApplet.parseInt(random(50)+20);
  boolean move = true;
  float z = 0;
  int index;
  int health = 0;
  int seed = PApplet.parseInt(random(200));
  boolean quarantineAnimal = false;

  Animal(int X,int Y){
    x = X+3;
    y = Y+3;

  }


  /*
   The conditions for health are as follows, 0 = healthy, 1 = sick, 2 = dead.
   */
  public void Draw(){
    ellipseMode(CORNER);

    if(health == 0){
      stroke(1);
      fill(227,196,158);
      // image(myPerson, x, y);
      rect(x,y,8,8);//The healthy are white rectangles
    }
    else if(health == 1){
      fill(0,255,0);
      //   image(redPerson, x, y);
      rect(x,y,6,6);//The sick are green and emaciated. They also move slower - RECTANGLE!
    }
    else{
      move = false;
      fill(211,9,9);
      //  image(deadPerson, x, y);
      rect(x,y,4,4);//the dead are red and immobile.
    }   


    //QUARANTINE BOTTOM RIGHT CORNER
    if ((mouseX > 400) && (mouseX < 800) && (mouseY > 300 ) && (mouseY < 600)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (Animal[I].health == 1 && Animal[I].x > 400 && Animal[I].x < 800 && Animal[I].y > 300 && Animal[I].y < 600) {
              quarantineAnimal=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(400, 300, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 460, 450);
              Animal[I].health = 0;
              Animal[I].move = false;
            }
          }
        }
      }
    }
    //QUARANTINE TOP RIGHT CORNER
    if ((mouseX > 400) && (mouseX < 800) && (mouseY > 0 ) && (mouseY < 300)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (Animal[I].health == 1 && Animal[I].x > 400 && Animal[I].x < 800 && Animal[I].y > 0 && Animal[I].y < 300) {
              quarantineAnimal=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(400, 1, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 450, 150);
              Animal[I].move = false;
            }
          }
        }
      }
    }
    //QUARANTINE TOP LEFT CORNER
    if ((mouseX > 0) && (mouseX < 400) && (mouseY > 0 ) && (mouseY < 300)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (Animal[I].health == 1 && Animal[I].x > 0 && Animal[I].x < 400 && Animal[I].y > 0 && Animal[I].y < 300) {
              quarantineAnimal=true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(1, 1, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 140, 150);
              Animal[I].move = false;
            }
          }
        }
      }
    }

    //QUARANTINE BOTTOM LEFT CORNER
    if ((mouseX > 0) && (mouseX < 400) && (mouseY > 300 ) && (mouseY < 600)){
      // this basically says "if up is pressed, do the following (play
      //radar left to right)
      for(int I = 0;I<na;I++){
        if(keyPressed == true) {
          if(key == 'q'){ 
            if (Animal[I].health == 1 && Animal[I].x > 0 && Animal[I].x < 400 && Animal[I].y > 300 && Animal[I].y < 600){   
              quarantineAnimal = true;
              noFill();
              strokeWeight(3);
              stroke(255);
              rect(1, 300, 399, 299);
              fill(255);
              textSize(35);
              text("QUARANTINED", 50, 450);
              Animal[I].move = false;

            }
          }
        }
      }
    }
  }




  public void Move(){
    if(move == true){
      noiseSeed(seed);
      x+=PApplet.parseInt(noise(z)*20-10);
      y+=PApplet.parseInt(noise(z-200)*20-10);
      z+=.1f;
    }
  }

  public void checkHit(){//This is collision detction, the sick will transmit the disease by touch.
    for(int I = 0;I<na;I++){
      float D = dist(Animal[I].x,Animal[I].y,x,y);
      if((D<10)&&(Animal[I].health == 1)&&(health != 2)){
        health = 1; 
      }


    }

    for(int I = 0;I<na;I++){ 
      for (int J = 0;J<n;J++) {
        float A = dist(Animal[I].x,Animal[I].y,People[J].x,People[J].y);
        if((A<10)&&(People[J].health == 1)&&(Animal[I].health == 0)&&(health != 2)){
          Animal[I].health = 1; 
        }
      }

    }
  }
  public void disease(){//This sets the paramaters for the disease.
    if(health == 1){
      mortality--;
    }
    if(mortality==0){
      health = 2;
      move = false;
      sickCount--;
      deadCount++;
    }
  }
  /*
return sickCount;
   return deadCount;
   return healthyCount;
   */
}



class Doctor {
  int x = 0;
  int y = 0;
  int mortality = PApplet.parseInt(random(50)+2);
  boolean move = true;
  float z = 0;
  int index;
  int health = 0;
  int seed = PApplet.parseInt(random(200));


  Doctor(int X,int Y){
    x = X+3;
    y = Y+3;

  }


  /*
   The conditions for health are as follows, 0 = healthy, 1 = sick, 2 = dead.
   */
  public void Draw(){
    if(health == 0){
      stroke(1);
      fill(15,25,255);
      // image(myPerson, x, y);
      rect(x,y,8,8);//The healthy are white rectangles
    }
    else if(health == 1){
      fill(15,25,25);
      //   image(redPerson, x, y);
      rect(x,y,6,6);//The sick are green and emaciated. They also move slower - RECTANGLE!
    }
    else{
      move = false;
      fill(211,9,9);
      //  image(deadPerson, x, y);
      rect(x,y,4,4);//the dead are red and immobile.
    }

  }

  public void Move(){
    if(move == true){
      noiseSeed(seed);
      x+=PApplet.parseInt(noise(z)*20-10);
      y+=PApplet.parseInt(noise(z-200)*20-10);
      z+=.1f;
    }
  }

  public void checkHit(){//This is collision detction, the doctor will heal people if they are sick.
    for(int I = 0;I<nd;I++){
      for(int J = 0;J<n;J++){
        float D = dist(Doctor[I].x,Doctor[I].y,People[J].x,People[J].y);
        if((D<10)&&(People[J].health == 1)){
          People[J].health = 0; 
        }

      }
    }
  }
  public void disease(){//This sets the paramaters for the disease.
    if(health == 1){
      mortality--;
    }
    if(mortality==0){
      health = 2;
      move = false;
      sickCount--;
      deadCount++;
    }
  }
  /*
return sickCount;
   return deadCount;
   return healthyCount;
   */
}



class Undertaker {
  int x = 0;
  int y = 0;
  int mortality = PApplet.parseInt(random(50)+2);
  boolean move = true;
  float z = 0;
  int index;
  int health = 0;
  int seed = PApplet.parseInt(random(200));


  Undertaker(int X,int Y){
    x = X+3;
    y = Y+3;

  }


  /*
   The conditions for health are as follows, 0 = healthy, 1 = sick, 2 = dead.
   */
  public void Draw(){
    if(health == 0){
      stroke(1);
      fill(140,18,140);
      // image(myPerson, x, y);
      rect(x,y,8,8);//The healthy are white rectangles
    }
    else if(health == 1){
      fill(140,20,140);
      //   image(redPerson, x, y);
      rect(x,y,8,8);//The sick are green and emaciated. They also move slower - RECTANGLE!
    }
    else{
      move = false;
      fill(211,9,9);
      //  image(deadPerson, x, y);
      rect(x,y,4,4);//the dead are red and immobile.
    }

  }

  public void Move(){
    if(move == true){
      noiseSeed(seed);
      x+=PApplet.parseInt(noise(z)*20-10);
      y+=PApplet.parseInt(noise(z-200)*20-10);
      z+=.1f;
    }
  }

  public void checkHit(){//This is collision detction, the doctor will heal people if they are sick.
    for(int U = 0;U<nd;U++){
      for(int J = 0;J<n;J++){
        float D = dist(Undertaker[U].x,Undertaker[U].y,People[J].x,People[J].y);
        if((D<10)&&(People[J].health == 2)){
          People[J].x = 1000;
          People[J].y = 1000; 
        }

      }
    }

    for(int U = 0;U<nd;U++){
      for(int I = 0;I<na;I++){
        float D = dist(Undertaker[U].x,Undertaker[U].y,Animal[I].x,Animal[I].y);
        if((D<10)&&(Animal[I].health == 2)){
          Animal[I].x = 1000;
          Animal[I].y = 1000; 
        }

      }
    }
  }

  /*
return sickCount;
   return deadCount;
   return healthyCount;
   */
}



  static public void main(String args[]) {     PApplet.main(new String[] { "updatedcode4" });  }}