Exemplo n.º 1
0
        private static IKing SetUpKing()
        {
            string kingName = Console.ReadLine();

            IKing king = new King(kingName);

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

            foreach (string name in royalGuardsNames)
            {
                var royalGuard = new RoyalGuard(name);

                king.AddSubordinate(royalGuard);
            }

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

            foreach (string name in footmenNames)
            {
                var footman = new Footman(name);

                king.AddSubordinate(footman);
            }

            return(king);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            string kingName = Console.ReadLine();

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

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

            foreach (var name in royalGuardsNames)
            {
                var royalGuard = new RoyalGuard(name);
                soldiers.Add(royalGuard);

                king.KingUnderAttack += royalGuard.ReactToKingAttack;
            }

            foreach (var name in footmenNames)
            {
                var footman = new Footman(name);
                soldiers.Add(footman);

                king.KingUnderAttack += footman.ReactToKingAttack;
            }

            while (true)
            {
                string command = Console.ReadLine();

                if (command == "End")
                {
                    return;
                }
                else if (command == "Attack King")
                {
                    king.GetAttacked();
                }
                else if (command.StartsWith("Kill"))
                {
                    var soldierName = command.Split().Skip(1).Take(1).First();
                    soldiers.FirstOrDefault(s => s.Name == soldierName)?.Kill();
                }
            }
        }
        static void Main(string[] args)
        {
            var kingName        = Console.ReadLine();
            var king            = new King(kingName);
            var royalGuardNames = Console.ReadLine().Split();
            var royalGuards     = new List <Person>();
            var footmen         = new List <Person>();

            for (int i = 0; i < royalGuardNames.Length; i++)
            {
                var royalGuard = new RoyalGuard(royalGuardNames[i]);
                royalGuards.Add(royalGuard);
            }

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

            for (int i = 0; i < footmenNames.Length; i++)
            {
                var footman = new Footman(footmenNames[i]);
                footmen.Add(footman);
            }


            var input = Console.ReadLine();

            while (input != "End")
            {
                if (input == "Attack King")
                {
                    Console.WriteLine(king.ProtectTheKing());

                    foreach (var guard in royalGuards)
                    {
                        Console.WriteLine(guard.ProtectTheKing());
                    }

                    foreach (var footman in footmen)
                    {
                        Console.WriteLine(footman.ProtectTheKing());
                    }
                }
                else
                {
                    var name = input.Split()[1];

                    if (royalGuards.Any(x => x.Name == name))
                    {
                        var deadGuard = royalGuards.FirstOrDefault(x => x.Name == name);

                        royalGuards.Remove(deadGuard);
                    }
                    else
                    {
                        var deadFootman = footmen.FirstOrDefault(x => x.Name == name);

                        footmen.Remove(deadFootman);
                    }
                }

                input = Console.ReadLine();
            }
        }