예제 #1
0
        static void Main(string[] args)
        {
            bool isWorking = true;

            while (isWorking)
            {
                Platoon platoon1 = new Platoon(101);
                Platoon platoon2 = new Platoon(100);
                Console.WriteLine("Генерал, отдайте приказ! (Атака - начать бой! Побег - отступить!)");
                switch (Console.ReadLine())
                {
                case "Атака":
                    while (platoon1.GetCount() > 0 && platoon2.GetCount() > 0)
                    {
                        Console.WriteLine("Наш взвод:");
                        platoon1.ShowInfo();
                        Console.WriteLine("\nВзвод врага:");
                        platoon2.ShowInfo();
                        Console.WriteLine();
                        platoon1.TakeDammage(platoon2);
                        platoon2.TakeDammage(platoon1);
                        Thread.Sleep(500);
                        Console.Clear();
                    }
                    if (platoon1.GetCount() == 0 && platoon2.GetCount() == 0)
                    {
                        Console.WriteLine("Ничья");
                    }
                    else if (platoon1.GetCount() == 0)
                    {
                        Console.WriteLine("Поражение");
                        Console.WriteLine("У врага осталось:");
                        platoon2.ShowInfo();
                    }
                    else
                    {
                        Console.WriteLine("Мы победили");
                        Console.WriteLine("У нас остались:");
                        platoon1.ShowInfo();
                    }

                    break;

                case "Побег":
                    isWorking = false;
                    break;

                default:
                    Console.WriteLine("Такого приказа нет в уставе!");
                    break;
                }
            }
        }
예제 #2
0
        public Troop GetRandomTroop(Platoon platoon)
        {
            Random random   = new Random();
            int    randomId = random.Next(0, platoon.GetCount() - 1);
            int    count    = platoon.GetTroops().Count;

            if (count > 0)
            {
                return(platoon.GetTroops()[randomId]);
            }
            return(null);
        }
예제 #3
0
        public void TakeDammage(Platoon enemyPlatoon)
        {
            Random random = new Random();

            for (int i = 0; i < enemyPlatoon.GetCount(); i++)
            {
                int randomTroopId = random.Next(0, _allTroops.Count - 1);
                if (enemyPlatoon.GetCount() < 0)
                {
                    Troop enemyTroop = GetRandomTroop(enemyPlatoon);
                    if (enemyTroop != null)
                    {
                        _allTroops[randomTroopId].TakeDammage(enemyTroop.Dammage, enemyTroop.DammageType);
                    }
                }
                else
                {
                    _allTroops[randomTroopId].TakeDammage(enemyPlatoon.GetTroops()[enemyPlatoon.GetTroops().Count - 1].Dammage, enemyPlatoon.GetTroops()[enemyPlatoon.GetTroops().Count - 1].DammageType);
                }
            }
            RemoveDeadTroops();
        }