Add a way for a disease to kill rabbits in warrens

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 1  private void KillByOtherFactors(bool ShowDetail)
 2         {
 3             int DeathCount = 0;
 4             float DiseaseProb = RabbitCount * 0.25f;//the larger the rabbit population the greater the chance of disease
 5             for (int r = 0; r < RabbitCount; r++)
 6             {
 7                 if (Rabbits[r].CheckIfKilledByOtherFactor() || Rnd.Next(0, 100) < DiseaseProb)//adds a probability to die from disease
 8                 {
 9                     Rabbits[r] = null;
10                     DeathCount++;
11                 }
12             }
13             CompressRabbitList(DeathCount);
14             if (ShowDetail)
15             {
16                 Console.WriteLine("  " + DeathCount + " rabbits killed by other factors.");
17             }
18         }
  • L4 Adds a new variable called DiseaseProb that increases with the rabbit population
  • L7 Generates a random number and compares it to the probability of disease.

So for example if there were 100 rabbits there would be a 25% chance for one to die from disease