示例#1
0
        public static void Main()
        {
            List <Soldier> army = new List <Soldier>();
            King           king = new King(Console.ReadLine());

            string[] royalGuards = Console.ReadLine().Split().ToArray();
            foreach (var royalGuard in royalGuards)
            {
                var guard = new RoyalGuard(royalGuard);
                army.Add(guard);
                king.UnderAttack  += guard.KingUnderAttack;
                guard.UnderAttack += guard.OnUnderAttack;
            }

            string[] footmans = Console.ReadLine().Split().ToArray();
            foreach (var footman in footmans)
            {
                var footm = new Footman(footman);
                army.Add(footm);
                king.UnderAttack  += footm.KingUnderAttack;
                footm.UnderAttack += footm.OnUnderAttack;
            }

            string[] command = Console.ReadLine().Split();
            while (command[0] != "End")
            {
                switch (command[0])
                {
                case "Kill":
                    var soldier = army.FirstOrDefault(s => s.Name == command[1]);

                    soldier.OnUnderAttack();

                    if (soldier.IsDead)
                    {
                        king.UnderAttack -= soldier.KingUnderAttack;
                        army.Remove(soldier);
                    }
                    break;

                case "Attack":
                    king.OnUnderAttack();

                    break;
                }

                command = Console.ReadLine().Split();
            }
        }
示例#2
0
        public static void Main()
        {
            SoldiersList soldiers = new SoldiersList();
            King         king     = new King(Console.ReadLine());

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

            foreach (string guardName in royalGuardsNames)
            {
                RoyalGuard currentRoyalGuard = new RoyalGuard(guardName, king);
                soldiers.Add(currentRoyalGuard);
                king.BeingAttacked += currentRoyalGuard.OnKingBeingAttacked;
            }

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

            foreach (string footManName in footmenNames)
            {
                Footman footMan = new Footman(footManName, king);
                soldiers.Add(footMan);
                king.BeingAttacked += footMan.OnKingBeingAttacked;
            }

            soldiers.ForEach(s => s.SoldierKilled += soldiers.OnSoldierKilled);

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

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

                    Soldier attackedSoldier = soldiers.FirstOrDefault(s => s.Name.Equals(command[1]));
                    attackedSoldier.TakeAttack();
                    break;

                case "Attack":

                    king.TakeAttack();
                    break;
                }

                command = Console.ReadLine().Split();
            }
        }
        public static void Main()
        {
            string kingName = Console.ReadLine();

            string[] guardsNames  = Console.ReadLine().Split();
            string[] footmenNames = Console.ReadLine().Split();

            King           king     = new King(kingName);
            List <Soldier> soldiers = new List <Soldier>();

            foreach (var name in guardsNames)
            {
                RoyalGuard guard = new RoyalGuard(name);
                king.AddSoldier(guard);
            }

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

            while (true)
            {
                string[] input = Console.ReadLine().Split();

                if (input[0] == "End")
                {
                    break;
                }
                else if (input[0] == "Kill")
                {
                    Soldier soldier = king.Soldiers.FirstOrDefault(s => s.Name == input[1]);
                    soldier.TakeAttack();
                }
                else if (input[0] == "Attack")
                {
                    king.OnAttack();
                }
            }
        }