Difference between revisions of "Implementing weather changes that affect animals"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 1: Line 1:
Check for which season you are in
+
==Setup Simulation Class==
 +
Within the Simulation class, declare a new int to store the current season:
 +
 
 +
<syntaxhighlight lang="csharp">
 +
private int Season = 0;
 +
</syntaxhighlight>
 +
 
 +
==Give Season a value==
 +
Now within the Constructor method for Simulation you need to work out the season. This can be done using % to get the remainder. Add this Check for which season you are in to option 1 and option 2:
 
<syntaxhighlight lang="csharp">  
 
<syntaxhighlight lang="csharp">  
 
                 if (menuOption == 1)
 
                 if (menuOption == 1)
Line 17: Line 25:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Winter Effects
+
==Use the Season Variable==
 +
===Winter Effects===
 +
within the simulation class, a method called DistanceBetween is used to calculate the distance between 2 objects. This can be altered so that in the winter season the distance are larger than normal:
 
<syntaxhighlight lang="csharp">  
 
<syntaxhighlight lang="csharp">  
  

Revision as of 11:43, 25 May 2017

Setup Simulation Class

Within the Simulation class, declare a new int to store the current season:

 
private int Season = 0;

Give Season a value

Now within the Constructor method for Simulation you need to work out the season. This can be done using % to get the remainder. Add this Check for which season you are in to option 1 and option 2:

 
                if (menuOption == 1)
                {
                    TimePeriod++;
                    Season = TimePeriod % 4;
                    ShowDetail = true;
                    AdvanceTimePeriod();
                }
                if (menuOption == 2)
                {
                    TimePeriod++;
                    Season = TimePeriod % 4;
                    ShowDetail = false;
                    AdvanceTimePeriod();
                }

Use the Season Variable

Winter Effects

within the simulation class, a method called DistanceBetween is used to calculate the distance between 2 objects. This can be altered so that in the winter season the distance are larger than normal:

 

        private double DistanceBetween(int x1, int y1, int x2, int y2)
        {
            if (Season==0)
            {
                return (Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2))+3);
            }
            else
            return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
        }