Create a giant warren which allows 200 rabbits

From TRCCompSci - AQA Computer Science
Revision as of 09:54, 24 May 2017 by Admin (talk | contribs)
Jump to: navigation, search

Before you can use the Warren class as the parent of the SuperWarren class you may need to create another constructor class. You will need to create one which doesn't accept any values, the other 2 constructor must have parameters passed:

</syntaxhighlight>

   public Warren()
   {
       this.Variability = 45;
       Rabbits = new Rabbit[MaxRabbitsInWarren];
       RabbitCount = (int)(CalculateRandomValue((int)(MaxRabbitsInWarren / 4), this.Variability));
       for (int r = 0; r < RabbitCount; r++)
       {
           Rabbits[r] = new Rabbit(Variability);
       }
   }

</syntaxhighlight>

Because we want to override the inspect method in the new class, you need to change the Inspect method to virtual:

</syntaxhighlight>

   public virtual void Inspect()
   {
     Console.WriteLine("Periods Run " + PeriodsRun + " Size " + RabbitCount);
   }

</syntaxhighlight>