Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnCalc_Click(object sender, EventArgs e)
- {
- // Initialize variables
- int baseWood = 0;
- int baseClay = 0;
- int baseIron = 0;
- int baseCrop = 0;
- int missingWood = 0;
- int missingClay = 0;
- int missingIron = 0;
- int missingCrop = 0;
- int i = 0; // Counter
- int tempWood = 0;
- int tempClay = 0;
- int tempIron = 0;
- int tempCrop = 0;
- // Check if all fields are filled out
- foreach (TextBox tb in this.Controls.OfType<TextBox>())
- {
- if (tb.Text == string.Empty)
- {
- // Textbox empty
- MessageBox.Show("Please fill out all fields.", "Missing number");
- return;
- }
- }
- if (rbWood.Checked)
- {
- baseWood = Convert.ToInt32(txtWoodHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
- }
- else if (rbClay.Checked)
- {
- baseClay = Convert.ToInt32(txtClayHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
- }
- else if (rbIron.Checked)
- {
- baseIron = Convert.ToInt32(txtIronHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
- }
- else if (rbCrop.Checked)
- {
- baseCrop = Convert.ToInt32(txtCropHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
- }
- else if (rbAll.Checked)
- {
- baseWood = Convert.ToInt32(txtWoodHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
- baseClay = Convert.ToInt32(txtClayHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
- baseIron = Convert.ToInt32(txtIronHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
- baseCrop = Convert.ToInt32(txtCropHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
- }
- else
- {
- // No radio buttons selected.
- MessageBox.Show("Please select which resource your hero produces.", "Missing selection.");
- return;
- }
- // Calculate how many resources are needed
- missingWood = Convert.ToInt32(txtTargetWood.Text) - Convert.ToInt32(txtWood.Text);
- missingClay = Convert.ToInt32(txtTargetClay.Text) - Convert.ToInt32(txtClay.Text);
- missingIron = Convert.ToInt32(txtTargetIron.Text) - Convert.ToInt32(txtIron.Text);
- missingCrop = Convert.ToInt32(txtTargetCrop.Text) - Convert.ToInt32(txtCrop.Text);
- // Calculate fastest way to target
- if ((missingWood > 0) && (missingClay > 0) && (missingIron > 0) && (missingCrop > 0))
- {
- while (missingWood < (Convert.ToInt32(txtTargetWood.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
- {
- missingWood = missingWood * (Convert.ToInt32(txtRes.Text) * 3);
- tempWood = ++i;
- }
- while (missingClay < (Convert.ToInt32(txtTargetClay.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
- {
- missingClay = missingClay * (Convert.ToInt32(txtRes.Text) * 3);
- tempClay = ++i;
- }
- while (missingIron < (Convert.ToInt32(txtTargetIron.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
- {
- missingIron = missingIron * (Convert.ToInt32(txtRes.Text) * 3);
- tempIron = ++i;
- }
- while (missingCrop < (Convert.ToInt32(txtTargetCrop.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
- {
- missingCrop = missingCrop * (Convert.ToInt32(txtRes.Text) * 3);
- tempCrop = ++i;
- }
- if ((tempWood > tempClay) && (tempWood > tempIron) && (tempWood > tempCrop))
- {
- // Produce all resources for "tempWood" hours
- }
- if ((tempClay > tempWood) && (tempClay > tempIron) && (tempClay > tempCrop))
- {
- // Produce all resources for "tempClay" hours
- }
- if ((tempIron > tempWood) && (tempIron > tempClay) && (tempIron > tempCrop))
- {
- // Produce all resources for "tempIron" hours
- }
- if ((tempCrop > tempWood) && (tempCrop > tempClay) && (tempCrop > tempIron))
- {
- // Produce all resources for "tempClay" hours
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment