Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // variables
- int year = 1;
- int arrivals = 0;
- int population = 100;
- int acres = 1000;
- int harvested = 0;
- int rats = 5;
- int trading = 18;
- int ratsAte = 0;
- int bushels = 2800;
- int bushelsHarvested = 0;
- int bushelsTrading = 0;
- int plague = 0;
- int died = 0;
- double averageStarved = 0;
- double averageAcres = 0;
- double totalStarved = 0;
- int plagueDeaths = 0;
- int starved = 0;
- Series peopleSeries;
- Series bushelSeries;
- private void btnAllocate_Click(object sender, EventArgs e)
- {
- // moves the game forward a year every time the allocate button is clicked
- year = year + 1;
- // random amount of people come to the city
- Random random = new Random();
- arrivals = random.Next(1, 16);
- // plague that halfs the population
- Random random4 = new Random();
- plague = random.Next(1, 21);
- if (plague == 1)
- {
- plagueDeaths = population / 2;
- MessageBox.Show("You were hit by a plague, half your population died", "Plague", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- pnlPlague.Visible = true;
- lblPlague.Text = plagueDeaths + " Died";
- }
- else
- {
- plagueDeaths = 0;
- }
- // new population tota
- population = population + arrivals - plagueDeaths - died;
- // randomised number for trading
- Random random3 = new Random();
- trading = random.Next(17, 27);
- //randomised number of bushels harvested per acre
- Random random1 = new Random();
- harvested = random.Next(1, 6);
- // possibilty of rats
- Random random2 = new Random();
- rats = random.Next(1, 11);
- // calculates the amount of bushels harvested and stores it in a variable
- bushelsHarvested = harvested * int.Parse(txtSeed.Text);
- // adds the bushels harvested to the users bushels
- bushels = bushels + bushelsHarvested;
- // works out how much rats have eaten
- if (rats == 5)
- {
- ratsAte = bushels * 10 / 100;
- lblRats.Text = "Rats ate " + ratsAte + " bushels.";
- MessageBox.Show("Rats ate " + ratsAte + " bushels");
- }
- else
- {
- ratsAte = 0;
- lblRats.Text = "Rats ate 0 bushels";
- }
- // takes the amount of bushels that the rats ate away fromthe remaining bushels
- bushels = bushels - ratsAte;
- // adds the amount died from starvation each year to a variable
- averageStarved = died + averageStarved;
- totalStarved = averageStarved;
- pbBushels.Value = bushels;
- pbPeople.Value = population;
- // array
- int[] starved = new int[10];
- int average, sum = 0;
- for (int i = 0; i<10; i++)
- {
- sum = sum + starved[i];
- }
- if (year == 11)
- {
- average = sum / 10;
- label11.Text = average + " people died on average each year";
- }
- // end of year evaluation
- if (year == 11)
- { pnlEvaluation.Visible = true;
- pnlResults.Visible = true;
- lblResultsTitle.Visible = true;
- averageAcres = acres / population;
- averageStarved = averageStarved / 10;
- lblAverageAcres.Text = "You started with an average of 10 acres per person and ";
- lblAverageAcres2.Text = "ended with an average of " + averageAcres + " per person.";
- lblAverageStarved.Text = averageStarved + " people starved on average every year, ";
- lblAverageStarved2.Text = totalStarved + " in total died during your reign.";
- //
- if (averageAcres <= 7 && averageStarved > 0)
- {
- lblEvaluation.Text = "Due to your reckless missmanagement of resources the people ";
- LBLEvaluation2.Text = "find you a horrible and disgusting ruler and want you beheaded.";
- }
- if (averageAcres >= 13 && averageStarved < 1)
- {
- lblEvaluation.Text = "You have managed to keep every fed and happy over the years, ";
- LBLEvaluation2.Text = "your people are looking forward to your next reign.";
- }
- if ((averageAcres > 7 && averageAcres < 13 ) && (averageStarved == 0))
- {
- lblEvaluation.Text = "You have had a very average reign and your people expected more, ";
- LBLEvaluation2.Text = "Improvement need or yoou may be overthrown.";
- }
- return;
- }
- // resets the textboxes
- txtBuySell.Text = "";
- txtFeeding.Text = "";
- txtSeed.Text = "";
- // changing the lables to show the new information remaining labels
- lblNewPeople.Text = arrivals + " people came to the city.";
- lblHarvest.Text = "You harvested " + harvested + " bushels per acre.";
- lblPopulation.Text = "The city population is now " + population;
- lblTrading.Text = "land is trading at " + trading + " bushels per acre.";
- lblYear.Text = "In Year " + year + ", " + died + " people starved.";
- lblBushels.Text = "You now have " + bushels;
- lblRemaining.Text = bushels + " Bushels";
- lblPeople.Text = population + " people";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement