Exemple #1
0
        public string PerformASingleAttack(Hero heroA, Hero heroB)
        {
            System.Threading.Thread.Sleep(mInterval);

            double heroAAttackAmount = heroA.GetAttack();
            double heroBDefAmount    = heroB.GetDeffence();
            double damage2HeroB      = heroAAttackAmount - heroBDefAmount;

            if (damage2HeroB > 0)
            {
                heroB.HealthPoints -= (int)damage2HeroB;
            }
            else
            {
                damage2HeroB = 0;
            }

            Console.WriteLine("{0} attacks {1} and causes {2} damage.", heroA.Name, heroB.Name, (int)damage2HeroB);
            // prints the attack pts., defence pts. and actual damage of the current attack
            //Console.WriteLine("atk: "+heroAAttackAmount+"| def: "+heroBDefAmount+"| dmg: "+damage2HeroB);
            OnHealthPointsChanged(heroB);

            if (heroB.HealthPoints <= 0)
            {
                Console.WriteLine("{0} has died. {1} is victorious.", heroB.Name, heroA.Name);
                return("Game Over!");
            }
            else
            {
                return("");
            }
        }