Beginning part of a zombie apocalypse simulator

edited November 2013 in How To...

Hi guys I am really stuck on this question. My teacher has done nothing like this in class and its really confusing me. Any help 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. 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.

Answers

  • edited November 2013

    You shoulda at least provided your attempt! >:P
    Anyways, I did the framework for the Survivor class, so you got something to start with: [..]

    // forum.processing.org/two/discussion/1621/
    // beginning-part-of-a-zombie-apocalypse-simulator
    
    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;
      }
    }
    
  • SAme problem faced, now solved thank you :)

  • Thank You! Is there anyways you could help me out with the ellipses? I'm honestly just really not understanding the question. I'm not sure what the end result is supposed to look like. Thanks!

Sign In or Register to comment.