public bool Attack(Pokemon attackingPokemon, Pokemon defendingPokemon, OwnedPokemonAttack attack)
        {
            Random accuracy = new Random();

            //check accuracy
            if (accuracy.Next(0, 101) <= attack.Attack.Accuracy)
            {
                Random randomAttackDamage = new Random();

                //random attack modifier
                double modifier = Convert.ToDouble(randomAttackDamage.Next(85, 101)) / 100;

                //type modifier
                if (attack.Attack.Type.TypeEffectiveId == defendingPokemon.Pokedex.TypeId)
                {
                    modifier            *= 2;
                    txtInformation.Text += ", it was very effective";
                }
                else if (attack.Attack.Type.TypeNotEffectiveId == defendingPokemon.Pokedex.TypeId)
                {
                    modifier            *= 0.5;
                    txtInformation.Text += ", it was not very effective";
                }

                //attack type is hetzelfde als pokemon type
                if (attack.Attack.TypeId == attackingPokemon.Pokedex.TypeId)
                {
                    modifier *= 1.5;
                }


                double damage;

                if (attack.Attack.Type.Name.ToLower() == "normal")
                {
                    //normal attack
                    damage = (((((2 * attackingPokemon.Level) / 5) + 2) * attack.Attack.BaseDamage * (attackingPokemon.CalculatedAttack / defendingPokemon.CalculatedDefense) / 50) + 2) * modifier;
                }
                else
                {
                    //special attack
                    damage = (((((2 * attackingPokemon.Level) / 5) + 2) * attack.Attack.BaseDamage * (attackingPokemon.CalculatedSpecialAttack / defendingPokemon.CalculatedSpecialDefense) / 50) + 2) * modifier;
                }

                txtInformation.Text += Environment.NewLine + "it did " + Convert.ToInt32(Math.Round(damage)) + " damage" + Environment.NewLine;

                defendingPokemon.CurrentHp -= Convert.ToInt32(Math.Round(damage));
            }
            else if (attack.Attack.Name.ToLower() == "splash")
            {
                txtInformation.Text += Environment.NewLine + "But nothing happened...";
            }
            else
            {
                txtInformation.Text += Environment.NewLine + "It missed...";
            }


            return(defendingPokemon.CheckHp());
        }
예제 #2
0
        public void CheckHp_CurrentHpIsHigherThanCalculatedMaxHp_CurrentHpEqualsCalculatedMaxHp()
        {
            //Arrange
            Pokemon pokemon = new Pokemon();

            pokemon.CurrentHp       = 59;
            pokemon.CalculatedMaxHP = 48;
            bool dead;

            //Act
            dead = pokemon.CheckHp();

            //Assert
            Assert.AreEqual(pokemon.CalculatedMaxHP, pokemon.CurrentHp);
            Assert.AreEqual(pokemon.Fainted, "Alive");
            Assert.IsTrue(!dead);
        }
예제 #3
0
        public void CheckHp_CurrentHpIsLowerThan0_HpIs0AndReturnsIsTrueAndFaintedValueIsFainted()
        {
            //Arrange
            Pokemon pokemon = new Pokemon();

            pokemon.CurrentHp       = -4;
            pokemon.CalculatedMaxHP = 34;
            bool dead;

            //Act
            dead = pokemon.CheckHp();

            //Assert
            Assert.AreEqual(0, pokemon.CurrentHp);
            Assert.AreEqual("Fainted", pokemon.Fainted);
            Assert.IsTrue(dead);
        }