示例#1
0
  private void reproduction(
      int x,
      int y,
      ArrayList<Life> life,
      int minx,
      int maxx,
      int miny,
      int maxy) // Make another dino that is the same and set age to baby
      {
    // Make a dino
    Dino d = makeCopy(this);
    d.age = Age.BABY;
    d.setCoord(x, y);
    d.turns = 0; // Set the turns the creature has taken to
    diseaseCnt = 30; // Reset diseaseCnt for new dinos
    if (Math.random() < 0.8)
      d.disease = false; // 80% chance to not get the disease if original dino has disease

    // Add to life
    life.add(d);
  }
示例#2
0
  public Life interact(ArrayList<Life> life, int minx, int maxx, int miny, int maxy) {
    // Survival chance is calculated using the dino's age, size, and speed
    double survival = 1;
    // Make a copy of the current dino
    Dino cur = makeCopy(this);

    for (int i = 0; i < life.size(); i++) { // Go through the arraylist
      Life d = life.get(i);
      int dist =
          (int)
              Math.sqrt(
                  Math.pow(x - d.x, 2) + Math.pow(z - d.z, 2)); // Get the distance between the two
      if (d.code != Name.TREE && d != this && dist <= 1) { // Make sure it's a dino and not itself
        if (((Dino) d).code == code
            && dist <= 1) { // Same dino -> reproduction, make sure they are not baby or juvenile
          if (((Dino) d).age.getValue() > Age.JUVENILE.getValue()
              && age.getValue() > Age.JUVENILE.getValue()
              && Math.random() < reprod)
            reproduction((int) x, (int) z, life, minx, maxx, miny, maxy);
        } else if ((carnivore || ((Dino) d).carnivore)
            && ((Dino) d).age != Age.BABY) { // May die if one fo them is a carnivore
          survival =
              (1.0 * size * spd * age.ageMulti())
                  / (2.0 * ((Dino) d).size * ((Dino) d).spd * ((Dino) d).age.ageMulti());
          if (Math.random()
              > survival) { // If creature dies all food levels of nearby dinos are replenished
            cur.alive = false;
            feed(life);
          }
        }
        if (((Dino) d).disease && Math.random() < 0.3) infect(); // 30% chance to spread disease
      }
      if (!carnivore && d.code == Name.TREE && dist <= 1) food = 200; // Max out food
    }

    if (food <= 0 || diseaseCnt <= 0) cur.alive = false;

    return cur;
  }