static void Main(string[] args)
        {
            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);
            }
        }
예제 #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));

                    if (unitToKill.HitTimesToDeath - 1 == 0)
                    {
                        theKing.KingIsDefinitelyUnderAttack -= unitToKill.OnKingAttack;
                        warriors.Remove(unitToKill);
                    }
                    else
                    {
                        unitToKill.HitTimesToDeath--;
                    }
                    break;

                default:
                    break;
                }
            }
        }
예제 #3
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);
            }

            foreach (var soldier in soldiers)
            {
                soldier.SoldierDeath += (obj, args) =>
                {
                    Soldier killed = (Soldier)obj;

                    king.KingAttack -= killed.OnKingAttack;
                    soldiers.Remove(killed);
                };
            }

            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);

                    soldier.TakeDamage();
                }
            }
        }
        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);

            foreach (var name in royalGuardsNames)
            {
                var guard = new RoyalGuard(name);
                king.AddWarrior(guard);
            }

            foreach (var name in footmenNames)
            {
                var footman = new Footman(name);
                king.AddWarrior(footman);
            }

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

                switch (command)
                {
                case "Kill":
                    string name    = input[1];
                    var    warrior = king.Warriors.FirstOrDefault(s => s.Name == name);
                    warrior.TakeAttack();
                    break;

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

                case "End":
                    return;
                }
            }
        }
        public static void Main()
        {
            SoldierList soldiers = new SoldierList();
            King        king     = new King(Console.ReadLine());

            string[] royalGuardNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in royalGuardNames)
            {
                RoyalGuard rg = new RoyalGuard(name);
                rg.SoldierDead += soldiers.HandleDeadSoldier;
                rg.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(rg);
                king.KingAttacked += rg.OnKingAttack;
            }

            string[] footmanNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in footmanNames)
            {
                Footman fm = new Footman(name);
                fm.SoldierDead += soldiers.HandleDeadSoldier;
                fm.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(fm);
                king.KingAttacked += fm.OnKingAttack;
            }

            string command = string.Empty;

            while ((command = Console.ReadLine()) != "End")
            {
                var tokens = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (tokens[0] == "Attack")
                {
                    king.RespondToAttack();
                }
                else if (tokens[0] == "Kill")
                {
                    string    name    = tokens[1];
                    IDefender soldier = soldiers.First(x => x.Name == name);
                    soldier.TakeAttack();
                }
            }
        }