Difference between revisions of "A predator for foxes - eagles"
(→Create a new method within the Eagle class called AdvanceGeneration – this will take ShowDetail as a parameter) |
(→Study the AdvanceTimePeriod in the Simulation Class) |
||
Line 45: | Line 45: | ||
You will notice that there is a nested For Loop to go through each Warren and there is a nested For Loop to look for each Fox. | You will notice that there is a nested For Loop to go through each Warren and there is a nested For Loop to look for each Fox. | ||
− | Create a new Nested For Loop that looks for each Eagle | + | *Create a new Nested For Loop that looks for each Eagle |
− | + | *If an Eagle is present then: | |
− | If an Eagle is present then: | ||
If ShowDetail then display: | If ShowDetail then display: | ||
Line 53: | Line 52: | ||
Advance a generation for the Eagle | Advance a generation for the Eagle | ||
− | If The Eagle at that position in the landscape is Dead then set the location Eagle aspect to Nothing and decrement EagleCount | + | *If The Eagle at that position in the landscape is Dead then set the location Eagle aspect to Nothing and decrement EagleCount |
− | + | *If the Eagle is not killed then call the procedure: EaglesKillFoxes with the X & Y co-ordinates | |
− | If the Eagle is not killed then call the procedure: EaglesKillFoxes with the X & Y co-ordinates | + | *The If Show Detail is True inspect the Eagle |
− | |||
− | The If Show Detail is True inspect the Eagle | ||
Test this out showing detail and using pre-set values in order to check that the Eagle kills a fox | Test this out showing detail and using pre-set values in order to check that the Eagle kills a fox | ||
==In the Simulation class create a new Method: MoveEagle== | ==In the Simulation class create a new Method: MoveEagle== |
Revision as of 21:49, 27 February 2017
Contents
- 1 Create the outline class for an Eagle Class
- 2 Create a new method within the Eagle class called AdvanceGeneration – this will take ShowDetail as a parameter
- 3 Adapt the Location Class to include an Eagle
- 4 In the Simulation class
- 5 Create a new procedure called EaglesKillFoxes that accepts the parameters of the EaglesX and EaglesY co-ordinate.
- 6 Study the AdvanceTimePeriod in the Simulation Class
- 7 In the Simulation class create a new Method: MoveEagle
Create the outline class for an Eagle Class
- The class will inherit from the Animal class
- This will have two Constants:
- DefaultLifeSpan which will be of 6
- Probability of Death of value 0.05
- There will be a constructor class that makes use of the base class.
Create a new method within the Eagle class called AdvanceGeneration – this will take ShowDetail as a parameter
- The procedure will check if the Eagle has been killed by other factors
- if it has then it will state that the Eagle has been killed.
- If it does not get killed by other factors – the Age will be calculated and again it will check to see if the Eagle has died.
- If the Eagle has dies it will state “Eagle died of Old Age”
Adapt the Location Class to include an Eagle
In the Simulation class
- Create a new Private attribute called EagleCount and set as zero
- Create a new Sub Routine called CreateNewEagle() – this will work in the same way as CreateNewFox() but based on Eagle rather than Fox.
- In the Simulation after the final iteration structure:
If the timeperiod is a multiple of 3 then call the newly created CreateNewEagle method.
- In the Simulation class – adapt the draw landscape so that if there is an Eagle in a location then an E is placed on the board.
- Test the program to check that an Eagle appears after 2 time periods
Create a new procedure called EaglesKillFoxes that accepts the parameters of the EaglesX and EaglesY co-ordinate.
Create a new variable called FoxKilled and set to False
The procedure will search through every position on the Landscape and as long as FoxKilled = False the Eagle will attempt to Kill a fox.
The Eagle has a 30% chance of killing a fox – if it is unsuccessful it will then attempt to kill the next fox (and so on).
If the Eagle has not killed a Fox and the chance of killing the fox is within 20% then the FoxKilled variable is set to True. A message is displayed to the user: Eagle killed Fox at positon (X, Y)
FoxCount is decremented by 1
The Landscape Fox is set to Nothing.
Study the AdvanceTimePeriod in the Simulation Class
You will notice that there is a nested For Loop to go through each Warren and there is a nested For Loop to look for each Fox.
- Create a new Nested For Loop that looks for each Eagle
- If an Eagle is present then:
If ShowDetail then display: Eagle at (X,Y) Advance a generation for the Eagle
- If The Eagle at that position in the landscape is Dead then set the location Eagle aspect to Nothing and decrement EagleCount
- If the Eagle is not killed then call the procedure: EaglesKillFoxes with the X & Y co-ordinates
- The If Show Detail is True inspect the Eagle
Test this out showing detail and using pre-set values in order to check that the Eagle kills a fox