Implementing weather changes that affect animals

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

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));
        }