Difference between revisions of "Add an option on the menu to find the largest warren"
(→Finding the largest warren) |
(→Finding the largest warren) |
||
Line 1: | Line 1: | ||
== Finding the largest warren == | == Finding the largest warren == | ||
− | + | <syntaxhighlight lang="csharp"> | |
+ | Console.WriteLine("5. Find largest warren");//added this to the menu selection and changed exit to 6. | ||
+ | </syntaxhighlight> | ||
<syntaxhighlight lang="csharp" line> | <syntaxhighlight lang="csharp" line> | ||
if (menuOption == 5) | if (menuOption == 5) |
Latest revision as of 14:13, 14 March 2017
Finding the largest warren
Console.WriteLine("5. Find largest warren");//added this to the menu selection and changed exit to 6.
1
2 if (menuOption == 5)
3 {
4 int maxWarrenCheck = 0;
5 int currentX = 0;
6 int currentY = 0;
7 for (int a = 0; a < LandscapeSize; a++)
8 {
9 for (int b = 0; b < LandscapeSize; b++)
10 {
11 if (Landscape[a, b].Warren != null && Landscape[a, b].Warren.GetRabbitCount() > maxWarrenCheck)
12 {
13 maxWarrenCheck = Landscape[a, b].Warren.GetRabbitCount();
14 currentX = a;
15 currentY = b;
16 }
17 }
18 }
19 Console.WriteLine("Max warren is at {0},{1} and is {2} rabbits large", currentX, currentY, maxWarrenCheck);
- The two for loops on L7 and L9 loop through each square on the grid.
- L11 Checks if there is a warren there and if the warren is larger than the max found so far.
- L13 - L15 Stores the new maximum warren size and its location.
- L19 Outputs the maximum warren position and its size.