Can some one please help me finish the rest of the beginning of this zombie apocalypse simulator

I have started making my class but I don't know where to go from there, any help would would be appreciated. Thank You!

Create a Survivor class; a survivor will have a name, a location on the screen, an "infected" boolean, an "injured" boolean, and a number of bullets carried (0.5 marks). Add more data if you think it is warranted. Create an array of survivors and draw them on the screen (ellipses with names as labels are sufficient); draw them color coded to indicate whether they are healthy, infected, or injured

You want to know how viable your population of survivors is. Write two functions that take the array of survivors as arguments: ● one that returns a percentage, the proportion of survivors who are completely healthy vs. being sick or injured  ● one that returns the number of bullets in the possession of healthy survivors (1 mark) Write code that calls both of these functions and draws the numbers with appropriate labels along with the survivors 

class Survivor {
  static final int DIAM = 050, RAD = DIAM>>1;

  static final color HEALTHY  = #0000FF;
  static final color INFECTED = #A08000;
  static final color INJURED  = #FF0000;

  static final color LABEL = 0300;

  final String name;

  boolean isInfected = random(1) < .1? true:false;
  boolean isInjured  = random(1) < .3? true:false;

  byte bullets = (byte) random(11);

  short x  = (short) random(RAD, width  - RAD);
  short y  = (short) random(RAD, height - RAD);

  short vx = (short) (random(1, 6)*(random(1) < .5? -1:1));
  short vy = (short) (random(1, 6)*(random(1) < .5? -1:1));

  Survivor(String nick) {
    name = nick;
  }

  void update() {
    if ((x += vx) > width  - RAD | x < RAD)   vx *= -1;
    if ((y += vy) > height - RAD | y < RAD)   vy *= -1;
  }

  void display() {
    fill(whichColor());
    ellipse(x, y, DIAM, DIAM);

    fill(LABEL);
    text(name, x, y);
  }

  private color whichColor() {
    if (isInjured)   return INJURED;
    if (isInfected)  return INFECTED;

    return HEALTHY;
  }
}

void setup() {

  size(500,400);
  background(255);
}

Answers

  • edited December 2013

    Do you need a code which generates the survivors? or do you simply need ideas? I'd make different scenarios with different starting points for survivors. Where do you need help with? Name generation? Additional Attributes?

    This should generate your survivors (not tested)

    int amountOfPeoples = 5;
    Survivor[] peoples;
    
    void setup() {
    
      size(500, 400);
      background(255);
      peoples = new Survivor[amountOfPeoples];
      for (int i = 0; i < amountOfPeoples; i++)
      {
        remakeSurvivors(i);
      }
    }
    
    void display()
    {
      for (int i = 0; i < 5; i++)
      {
        peoples[i].display();
        peoples[i].update();
      }
    }
    
    void remakeSurvivors(int numberOfSurvivor)
    {
      //This is my attempt at making a very poor name generator
      String name = "";
      int lengthOfName = int(random(3, 10)); //Create a name with length 3 - 10
      for (int i = 0; i < lengthOfName; i++) {
        name += char(int(random(97, 122)));
      }
      peoples[numberOfSurvivor] = new Survivor(name);
    }
    
Sign In or Register to comment.