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);
        }
Example #2
0
        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);
                        deadGuard.Lifesleft--;

                        if (deadGuard.Lifesleft <= 0)
                        {
                            royalGuards.Remove(deadGuard);
                        }
                    }
                    else
                    {
                        var deadFootman = footmen.FirstOrDefault(x => x.Name == name);
                        deadFootman.Lifesleft--;

                        if (deadFootman.Lifesleft <= 0)
                        {
                            footmen.Remove(deadFootman);
                        }
                    }
                }

                input = Console.ReadLine();
            }
        }