Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. // variables
  2. int year = 1;
  3. int arrivals = 0;
  4. int population = 100;
  5. int acres = 1000;
  6. int harvested = 0;
  7. int rats = 5;
  8. int trading = 18;
  9. int ratsAte = 0;
  10. int bushels = 2800;
  11. int bushelsHarvested = 0;
  12. int bushelsTrading = 0;
  13. int plague = 0;
  14. int died = 0;
  15. double averageStarved = 0;
  16. double averageAcres = 0;
  17. double totalStarved = 0;
  18. int plagueDeaths = 0;
  19. int starved = 0;
  20.  
  21.  
  22.  
  23.  
  24. Series peopleSeries;
  25. Series bushelSeries;
  26.  
  27.  
  28.  
  29. private void btnAllocate_Click(object sender, EventArgs e)
  30.  
  31. {
  32.  
  33. // moves the game forward a year every time the allocate button is clicked
  34. year = year + 1;
  35.  
  36. // random amount of people come to the city
  37. Random random = new Random();
  38. arrivals = random.Next(1, 16);
  39.  
  40. // plague that halfs the population
  41. Random random4 = new Random();
  42. plague = random.Next(1, 21);
  43. if (plague == 1)
  44. {
  45. plagueDeaths = population / 2;
  46. MessageBox.Show("You were hit by a plague, half your population died", "Plague", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  47. pnlPlague.Visible = true;
  48. lblPlague.Text = plagueDeaths + " Died";
  49. }
  50. else
  51. {
  52. plagueDeaths = 0;
  53.  
  54. }
  55.  
  56. // new population tota
  57. population = population + arrivals - plagueDeaths - died;
  58.  
  59. // randomised number for trading
  60. Random random3 = new Random();
  61. trading = random.Next(17, 27);
  62.  
  63.  
  64.  
  65. //randomised number of bushels harvested per acre
  66. Random random1 = new Random();
  67. harvested = random.Next(1, 6);
  68.  
  69. // possibilty of rats
  70. Random random2 = new Random();
  71. rats = random.Next(1, 11);
  72.  
  73.  
  74.  
  75. // calculates the amount of bushels harvested and stores it in a variable
  76.  
  77. bushelsHarvested = harvested * int.Parse(txtSeed.Text);
  78.  
  79. // adds the bushels harvested to the users bushels
  80. bushels = bushels + bushelsHarvested;
  81.  
  82. // works out how much rats have eaten
  83. if (rats == 5)
  84. {
  85. ratsAte = bushels * 10 / 100;
  86. lblRats.Text = "Rats ate " + ratsAte + " bushels.";
  87. MessageBox.Show("Rats ate " + ratsAte + " bushels");
  88.  
  89. }
  90. else
  91. {
  92. ratsAte = 0;
  93. lblRats.Text = "Rats ate 0 bushels";
  94.  
  95. }
  96.  
  97. // takes the amount of bushels that the rats ate away fromthe remaining bushels
  98. bushels = bushels - ratsAte;
  99.  
  100. // adds the amount died from starvation each year to a variable
  101. averageStarved = died + averageStarved;
  102. totalStarved = averageStarved;
  103.  
  104.  
  105. pbBushels.Value = bushels;
  106. pbPeople.Value = population;
  107.  
  108. // array
  109. int[] starved = new int[10];
  110. int average, sum = 0;
  111.  
  112. for (int i = 0; i<10; i++)
  113. {
  114. sum = sum + starved[i];
  115. }
  116.  
  117. if (year == 11)
  118. {
  119. average = sum / 10;
  120. label11.Text = average + " people died on average each year";
  121. }
  122.  
  123. // end of year evaluation
  124. if (year == 11)
  125. { pnlEvaluation.Visible = true;
  126. pnlResults.Visible = true;
  127. lblResultsTitle.Visible = true;
  128. averageAcres = acres / population;
  129. averageStarved = averageStarved / 10;
  130. lblAverageAcres.Text = "You started with an average of 10 acres per person and ";
  131. lblAverageAcres2.Text = "ended with an average of " + averageAcres + " per person.";
  132. lblAverageStarved.Text = averageStarved + " people starved on average every year, ";
  133. lblAverageStarved2.Text = totalStarved + " in total died during your reign.";
  134.  
  135. //
  136. if (averageAcres <= 7 && averageStarved > 0)
  137. {
  138. lblEvaluation.Text = "Due to your reckless missmanagement of resources the people ";
  139. LBLEvaluation2.Text = "find you a horrible and disgusting ruler and want you beheaded.";
  140. }
  141. if (averageAcres >= 13 && averageStarved < 1)
  142. {
  143. lblEvaluation.Text = "You have managed to keep every fed and happy over the years, ";
  144. LBLEvaluation2.Text = "your people are looking forward to your next reign.";
  145. }
  146. if ((averageAcres > 7 && averageAcres < 13 ) && (averageStarved == 0))
  147. {
  148. lblEvaluation.Text = "You have had a very average reign and your people expected more, ";
  149. LBLEvaluation2.Text = "Improvement need or yoou may be overthrown.";
  150. }
  151.  
  152. return;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159. // resets the textboxes
  160. txtBuySell.Text = "";
  161. txtFeeding.Text = "";
  162. txtSeed.Text = "";
  163.  
  164. // changing the lables to show the new information remaining labels
  165. lblNewPeople.Text = arrivals + " people came to the city.";
  166. lblHarvest.Text = "You harvested " + harvested + " bushels per acre.";
  167. lblPopulation.Text = "The city population is now " + population;
  168. lblTrading.Text = "land is trading at " + trading + " bushels per acre.";
  169. lblYear.Text = "In Year " + year + ", " + died + " people starved.";
  170. lblBushels.Text = "You now have " + bushels;
  171. lblRemaining.Text = bushels + " Bushels";
  172. lblPeople.Text = population + " people";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement