static void Main()
        {
            List <Soldier> defenders = new List <Soldier>();

            King king = new King(Console.ReadLine());

            string[] royalGuards = Console.ReadLine().Split();

            foreach (var royalGuardName in royalGuards)
            {
                RoyalGuard royalGuard = new RoyalGuard(royalGuardName);
                defenders.Add(royalGuard);
                king.UnderAttack += royalGuard.KingIsUnderAttack;
            }
            string[] footmen = Console.ReadLine().Split();

            foreach (var footmanName in footmen)
            {
                Footman footman = new Footman(footmanName);
                defenders.Add(footman);
                king.UnderAttack += footman.KingIsUnderAttack;
            }

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] commandArgs = input.Split();
                string   command     = commandArgs[0];
                commandArgs = commandArgs.Skip(1).ToArray();
                InterpretCommand(defenders, king, commandArgs, command);
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            HashSet <AbstractMan> warriors = new HashSet <AbstractMan>();
            Kingman theKing = new Kingman(Console.ReadLine());

            string[] royalGuards = Console.ReadLine().Split();
            string[] footmen     = Console.ReadLine().Split();

            foreach (var royalGuard in royalGuards)
            {
                RoyalGuard currentRoyalGuard = new RoyalGuard(royalGuard);

                warriors.Add(currentRoyalGuard);
                theKing.KingIsDefinitelyUnderAttack += currentRoyalGuard.OnKingAttack;
            }

            foreach (var footman in footmen)
            {
                Footman currentFootman = new Footman(footman);

                warriors.Add(currentFootman);
                theKing.KingIsDefinitelyUnderAttack += currentFootman.OnKingAttack;
            }

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                string[] commTokens = command.Split();

                string currentCommand = commTokens[0];

                switch (currentCommand)
                {
                case "Attack":
                    theKing.OnKingAttack();
                    break;

                case "Kill":
                    string nameToKill = commTokens[1];

                    var unitToKill = warriors.FirstOrDefault(x => x.Name.Equals(nameToKill));

                    theKing.KingIsDefinitelyUnderAttack -= unitToKill.OnKingAttack;
                    warriors.Remove(unitToKill);
                    break;

                default:
                    break;
                }
            }
        }
        public static void Main()
        {
            string kingsName = Console.ReadLine();
            var    king      = new King(kingsName);

            var royalGuardsNames = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var footmenNames = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var warriors = new List <Warrior>();

            foreach (var name in royalGuardsNames)
            {
                var guard = new RoyalGuard(name);
                warriors.Add(guard);
                king.IsAttacked += guard.RespondToAttack;
            }

            foreach (var name in footmenNames)
            {
                var footman = new Footman(name);
                warriors.Add(footman);
                king.IsAttacked += footman.RespondToAttack;
            }

            while (true)
            {
                var input   = Console.ReadLine().Split();
                var command = input[0];

                switch (command)
                {
                case "Kill":
                    string name    = input[1];
                    var    warrior = warriors.First(s => s.Name == name);
                    warriors.Remove(warrior);
                    king.IsAttacked -= warrior.RespondToAttack;
                    break;

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

                case "End":
                    return;
                }
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            King king = new King(Console.ReadLine());

            List <Soldier> soldiers = new List <Soldier>();

            foreach (var name in Console.ReadLine().Split())
            {
                RoyalGuard guard = new RoyalGuard(name);
                king.KingAttack += guard.OnKingAttack;
                soldiers.Add(guard);
            }

            foreach (var name in Console.ReadLine().Split())
            {
                Footman footman = new Footman(name);
                king.KingAttack += footman.OnKingAttack;
                soldiers.Add(footman);
            }

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                if (input == "Attack King")
                {
                    king.Attack();
                }
                else if (input.StartsWith("Kill "))
                {
                    string name = input.Split()[1];

                    Soldier soldier = soldiers.FirstOrDefault(s => s.Name == name);

                    king.KingAttack -= soldier.OnKingAttack;

                    soldiers.Remove(soldier);
                }
            }
        }