Let me know when I can upload another version to show you.
I have some image issues that I am working on.
OK! Got the image problem taken care of!
public void act() // In 'Person.class'
{
age++;
int actualAge = (age - (age % InfectWorld.ageRate) ) / InfectWorld.ageRate; // Computes actual age
if (age % InfectWorld.ageRate == 0 && actualAge % 13 == 0) // On every 13th Birthday
// The first part asks if it is a birthday, the second part asks if actualAge is a multiple of 13
{
infectChance += 10;
deathChance += 5;
}
if (actualAge< 15) { procreateChance = 0; }
if (actualAge > 14) { procreateChance = 10; }
if (actualAge > 20) { procreateChance = 30; }
if (actualAge > 35) { procreateChance = 10; }
if (actualAge > 40) { procreateChange = 5; }
if (actualAge > 50) { procreateChange = 1; }
// This next part adjust the image size for growth
GreenfootImage myImage = getImage(); // full size = 43 x 51
int myWidth = (actualAge + 1) * 43 / 18;
if (myWidth > 43) { myWidth = 43; }
int myHeight = (actualAge + 1) * 51 / 18;
if (myHeight > 51) { myHeight = 51; }
myImage.scale(myWidth, myHeight);
setImage(myImage);
// Check for death
if (Greenfoot.getRandomNumber(100) < deathChance)
{
die(); // Need to create method 'private void die() { ... }' to do what needs done when death occurs
}
... // Check for near infecteds, and if so:
if (Greenfoot.getRandomNumber(100) < infectChance)
{
infect();
}
// Check for couterpart Person adjacent, and if so:
if (Greenfoot.getRandomNumber(100) < procreateChance)
{
procreate(); // add Person: age, procreateChance, infectChance = 0; sex = Greenfoot.getRandomNumber(2); etc.
}
... // other code you MIGHT already have
}if (age % InfectWorld.ageRate == 0) // asking if is an actual birthday
{
switch (actualAge)
{
case 13:
infectChance = 10;
deathChance = 1;
procreateChance = 2;
break;
case 18:
infectChance = 15;
deathChance = 5;
procreateChance = 10;
break;
case 21:
deathChance = 3;
procreateChance = 15 - 5 * infectionLevel;
break;
case 26:
procreateChance = 20 - 5 * infectionLevel;
case 35:
procreateChance = 5 - infectionLevel;
case 50:
procreateChance = 0;
infectChance = 20;
deathChance = 5;
case 60:
infectChance = 25;
deathChance = 8;
case 75:
infectChance = 30;
deathChance = 12;
}
}if (isPregnant)
{
howLongTillDue--;
if (howLongTillDue == 0)
{
getWorld().addObject(new Person(0, 0), getX(), getY());
isPregnant = false;
}
}private void procreate(Person female)
{
isPregnant = true;
howLongTillDue = InfectWorld.ageRate * 3 / 4;
}public void Person(int myAge, int stageOfInfection)
{
age = myAge;
infectionStage = stageOfInfection;
sex = Greenfoot.getRandomNumber(2);
direction = Greenfoot.getRandomNumber(4);
setRotation(90 * direction);
// set image and set other variables here
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
public class Person extends Actor
{
private int direction;
private int infectionStage;
private int actCycle = 0;
// Each instance of Person has these variables and the values are independent from each other
// The new variables go right along with those above
private int age;
private int sex;
private int infectChance;
private int procreateChance;
private int deathChance;
private boolean isPregnant = false;
private int howLongTillDue = 0;
public Person()
{
direction = Greenfoot.getRandomNumber(4);
setRotation(90 * direction);
age = Greenfoot.getRandomNumber(100);
sex = Greenfoot.getRandomNumber(2);
infectionStage = 0;
// set other variables and image dependent on age/infectionStage
}
public Person(int myAge, int stageOfInfection)
{
age = myAge;
infectionStage = stageOfInfection;
sex = Greenfoot.getRandomNumber(2);
// set other variables and image
}
public void act()
{
// act code
}
}