Guest User

Travian Calculator

a guest
Jul 17th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.69 KB | None | 0 0
  1. private void btnCalc_Click(object sender, EventArgs e)
  2.         {
  3.             // Initialize variables
  4.             int baseWood = 0;
  5.             int baseClay = 0;
  6.             int baseIron = 0;
  7.             int baseCrop = 0;
  8.             int missingWood = 0;
  9.             int missingClay = 0;
  10.             int missingIron = 0;
  11.             int missingCrop = 0;
  12.             int i = 0; // Counter
  13.             int tempWood = 0;
  14.             int tempClay = 0;
  15.             int tempIron = 0;
  16.             int tempCrop = 0;
  17.  
  18.             // Check if all fields are filled out
  19.             foreach (TextBox tb in this.Controls.OfType<TextBox>())
  20.             {
  21.                 if (tb.Text == string.Empty)
  22.                 {
  23.                     // Textbox empty
  24.                     MessageBox.Show("Please fill out all fields.", "Missing number");
  25.                     return;
  26.                 }
  27.             }
  28.  
  29.             if (rbWood.Checked)
  30.             {
  31.                 baseWood = Convert.ToInt32(txtWoodHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
  32.             }
  33.             else if (rbClay.Checked)
  34.             {
  35.                 baseClay = Convert.ToInt32(txtClayHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
  36.             }
  37.             else if (rbIron.Checked)
  38.             {
  39.                 baseIron = Convert.ToInt32(txtIronHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
  40.             }
  41.             else if (rbCrop.Checked)
  42.             {
  43.                 baseCrop = Convert.ToInt32(txtCropHour.Text) - (Convert.ToInt32(txtRes.Text) * 10);
  44.             }
  45.             else if (rbAll.Checked)
  46.             {
  47.                 baseWood = Convert.ToInt32(txtWoodHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
  48.                 baseClay = Convert.ToInt32(txtClayHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
  49.                 baseIron = Convert.ToInt32(txtIronHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
  50.                 baseCrop = Convert.ToInt32(txtCropHour.Text) - (Convert.ToInt32(txtRes.Text) * 3);
  51.             }
  52.             else
  53.             {
  54.                 // No radio buttons selected.
  55.                 MessageBox.Show("Please select which resource your hero produces.", "Missing selection.");
  56.                 return;
  57.             }
  58.  
  59.             // Calculate how many resources are needed
  60.             missingWood = Convert.ToInt32(txtTargetWood.Text) - Convert.ToInt32(txtWood.Text);
  61.             missingClay = Convert.ToInt32(txtTargetClay.Text) - Convert.ToInt32(txtClay.Text);
  62.             missingIron = Convert.ToInt32(txtTargetIron.Text) - Convert.ToInt32(txtIron.Text);
  63.             missingCrop = Convert.ToInt32(txtTargetCrop.Text) - Convert.ToInt32(txtCrop.Text);
  64.  
  65.             // Calculate fastest way to target
  66.             if ((missingWood > 0) && (missingClay > 0) && (missingIron > 0) && (missingCrop > 0))
  67.             {
  68.                 while (missingWood < (Convert.ToInt32(txtTargetWood.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
  69.                 {
  70.                     missingWood = missingWood * (Convert.ToInt32(txtRes.Text) * 3);
  71.                     tempWood = ++i;
  72.                 }
  73.                 while (missingClay < (Convert.ToInt32(txtTargetClay.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
  74.                 {
  75.                     missingClay = missingClay * (Convert.ToInt32(txtRes.Text) * 3);
  76.                     tempClay = ++i;
  77.                 }
  78.                 while (missingIron < (Convert.ToInt32(txtTargetIron.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
  79.                 {
  80.                     missingIron = missingIron * (Convert.ToInt32(txtRes.Text) * 3);
  81.                     tempIron = ++i;
  82.                 }
  83.                 while (missingCrop < (Convert.ToInt32(txtTargetCrop.Text) + (Convert.ToInt32(txtRes.Text) * 3)))
  84.                 {
  85.                     missingCrop = missingCrop * (Convert.ToInt32(txtRes.Text) * 3);
  86.                     tempCrop = ++i;
  87.                 }
  88.  
  89.                 if ((tempWood > tempClay) && (tempWood > tempIron) && (tempWood > tempCrop))
  90.                 {
  91.                     // Produce all resources for "tempWood" hours
  92.                 }
  93.                 if ((tempClay > tempWood) && (tempClay > tempIron) && (tempClay > tempCrop))
  94.                 {
  95.                     // Produce all resources for "tempClay" hours
  96.                 }
  97.                 if ((tempIron > tempWood) && (tempIron > tempClay) && (tempIron > tempCrop))
  98.                 {
  99.                     // Produce all resources for "tempIron" hours
  100.                 }
  101.                 if ((tempCrop > tempWood) && (tempCrop > tempClay) && (tempCrop > tempIron))
  102.                 {
  103.                     // Produce all resources for "tempClay" hours
  104.                 }
  105.             }
  106.         }
Advertisement
Add Comment
Please, Sign In to add comment