示例#1
0
        public void Attack(Trooper enemy)
        {
            int damage = weapon.Damage / enemy.armor.ArmorPoints;

            enemy.health = enemy.health - damage;

            AttackResult(enemy, damage);
        }
示例#2
0
 private void AttackResult(Trooper enemy, int damage)
 {
     if (enemy.health <= 0)
     {
         enemy.isAlive = false;
         Tools.ColorfulWriteLine($"{enemy.name} is dead!", System.ConsoleColor.Red);
         Tools.ColorfulWriteLine($"{name} is victorious", System.ConsoleColor.Green);
     }
     else
     {
         System.Console.WriteLine($"{name} attacked {enemy.name}.{damage} damage was inflicted to {enemy.name}, remaining health of {enemy.name} is {enemy.health}");
     }
 }
示例#3
0
        static void Main()
        {
            Trooper goodGuy = new Trooper("Bob", Faction.GoodGuy);
            Trooper badGuy  = new Trooper("Bill", Faction.BadGuy);

            while (goodGuy.IsAlive && badGuy.IsAlive)
            {
                if (rng.Next(0, 10) < 5)
                {
                    goodGuy.Attack(badGuy);
                }
                else
                {
                    badGuy.Attack(goodGuy);
                }

                Thread.Sleep(100);
            }
        }