Exemple #1
0
        /// <summary>
        /// Calculates the resistance or weakness of a given type combination to a move of a given type. With the advanced options set, 
        /// this will calculate the minimum and maximum possible damage values, then get a possible damage value.
        /// </summary>
        private void calculateButton_Click(object sender, EventArgs e)
        {
            var bonus = 1.0;

            var attack = new Attack() {
                AttackType = mvType.SelectedItem.ToString(),
                DefenderType1 = defType1.SelectedItem.ToString(),
                DefenderType2 = defType2.SelectedItem.ToString() == "(none)" ? null : defType2.SelectedItem.ToString()
            };

            if (advancedCheck.Checked)
            {
                attack.AttackValue = Convert.ToInt32(atkValBox.Value);
                attack.DefenceValue = Convert.ToInt32(defValBox.Value);
                attack.AttackerLevel = Convert.ToInt32(atkLvlBox.Value);
                attack.BaseDamage = Convert.ToInt32(mvPowBox.Value);
                attack.AttackerType1 = atkType1.SelectedItem.ToString();
                attack.AttackerType2 = atkType2.SelectedItem.ToString() == "(none)" ? null : atkType2.SelectedItem.ToString();
                attack.GetSTAB();
            }

            // Basic mode
            bonus = Pokemon.CalculateBonus(attack);

            if (bonus == 0)
                resultText.Text = "It doesn't affect the enemy Pokémon.";
            else if (bonus == 0.5 || bonus == 0.25)
                resultText.Text = "It's not very effective (x" + bonus + ")...";
            else if (bonus == 2 || bonus == 4)
                resultText.Text = "It's super effective (x" + bonus + ")!";
            else
                resultText.Text = "It hit.";

            // Advanced mode
            var range = new int[4];
            if (advancedCheck.Checked)
            {
                if (bonus == 0)
                {
                    damageText.Text = "No damage dealt - immune.";
                }
                else
                {
                    range = Calculator.calculateDamageRange(bonus, attack);

                    string damage = String.Empty;
                    if (range[0] == 1)
                        damage = "A critical hit! ";

                    damage += "Damage done between " + range[1] + " and " + range[3] + " (dealt: " + range[2] + ")";
                    damageText.Text = damage;
                }
            }
        }