Пример #1
0
        public static void Main()
        {
            var king     = new King(Console.ReadLine());
            var soldiers = new List <Soldier>();

            var guardsNames  = ParseInput(Console.ReadLine());
            var footmenNames = ParseInput(Console.ReadLine());

            foreach (var name in guardsNames)
            {
                var royalGuard = new RoyalGuard(name);
                soldiers.Add(royalGuard);
                king.UnderAttack += royalGuard.KingUnderAttack;
            }
            foreach (var name in footmenNames)
            {
                var footman = new Footman(name);
                soldiers.Add(footman);
                king.UnderAttack += footman.KingUnderAttack;
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                var commandArgs = ParseInput(input);
                var command     = commandArgs[0];

                switch (command)
                {
                case "Kill":
                    var soldierName = commandArgs[1];
                    var soldier     = soldiers.FirstOrDefault(s => s.Name == soldierName);
                    king.UnderAttack -= soldier.KingUnderAttack;
                    soldiers.Remove(soldier);
                    break;

                case "Attack":
                    king.OnAttack();
                    break;

                default: break;
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var soldiers = new List <Soldier>();
            var king     = new King(Console.ReadLine());

            var royal_guard_name = Console.ReadLine().Split();

            foreach (string royal_Guard_Name in royal_guard_name)
            {
                var current_royal_guard = new Royal_Guard(royal_Guard_Name);
                soldiers.Add(current_royal_guard);
                king.Attacked += current_royal_guard.OnKingAttacked;
            }

            var footmen_name = Console.ReadLine().Split();

            foreach (string footMen_Name in footmen_name)
            {
                var current_footmen = new Footman(footMen_Name);
                soldiers.Add(current_footmen);
                king.Attacked += current_footmen.OnKingAttacked;
            }

            var command = Console.ReadLine().Split();

            while (command[0] != "End")
            {
                switch (command[0])
                {
                case "Kill":

                    Soldier deadSoldier = soldiers.FirstOrDefault(s => s.Name.Equals(command[1]));
                    king.Attacked -= deadSoldier.OnKingAttacked;
                    soldiers.Remove(deadSoldier);
                    break;

                case "Attack":

                    king.TakeAttack();
                    break;
                }
                command = Console.ReadLine().Split();
            }
        }