コード例 #1
0
        static void CreateMartian()
        {
            Console.Write("Enter new Martian: ");
            var objMartian = new Martian();

            objMartian.HealthPoints = Convert.ToInt32(Console.ReadLine());
            if (objMartian.HealthPoints <= 0)
            {
                throw new ArgumentOutOfRangeException("Value entered is below 1.");
            }
            Console.WriteLine();
            objMartian.AttackChk = DefaultMartian_AttackVal;
            ArrMartians.Add(objMartian);
        }
コード例 #2
0
 static void CreatureAttacks()
 {
     Console.WriteLine("Creature Attacks!");
     MartianAliveCount = ArrMartians.Count - 1;
     for (int index = 0; index < ArrMartians.Count; index++)
     {
         Martian martian = ArrMartians[index];
         martian.HealthPoints -= 10;
         if (martian.HealthPoints <= 0)
         {
             MartianAliveCount -= 1;
             continue;
         }
         else
         {
             Console.WriteLine($"{index + 1} Martian Health: {martian.HealthPoints} ");
         }
     }
     Console.WriteLine();
 }
コード例 #3
0
 static void MartianAttacks()
 {
     if (ArrMartians.Count >= 5)
     {
         Console.WriteLine("Martians Attack!");
         for (int index = 0; index < ArrMartians.Count; index++)
         {
             Martian martian = ArrMartians[index];
             if (martian.HealthPoints <= 0)
             {
                 continue;
             }
             spaceCreature_Health.HealthPoints -= martian.AttackChk;
             if (spaceCreature_Health.HealthPoints <= 0)
             {
                 Console.WriteLine("Creature is dead!");
                 break;
             }
             Console.WriteLine($"Creature Health:  {spaceCreature_Health.HealthPoints}");
             martian.AttackChk += 1;
         }
         Console.WriteLine();
     }
 }