Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var  kingName = Console.ReadLine();
            King king     = new King(kingName);

            var guards = Console.ReadLine().Split(new[] { ' ' },
                                                  StringSplitOptions.RemoveEmptyEntries);

            foreach (var guard in guards)
            {
                RoyalGuard royalGuard = new RoyalGuard(guard);
                king.AddToList(royalGuard);
            }

            var footmans = Console.ReadLine().Split(new[] { ' ' },
                                                    StringSplitOptions.RemoveEmptyEntries);

            foreach (var footman in footmans)
            {
                Footman man = new Footman(footman);
                king.AddToList(man);
            }
            // SetUpKingsAnturaje();



            var input = Console.ReadLine();

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


                switch (command[0])
                {
                case "Attack":
                    if (command[1] == "King")
                    {
                        king.KingIsUnderAttack();
                    }
                    break;

                case "Kill":
                    foreach (var deadSoldier in king.List.Where
                                 (s => s.Name.Equals(command[1])))
                    {
                        deadSoldier.Kill(command[1]);
                        //king.List.Remove(deadSoldier);
                    }
                    break;
                }
                input = Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <ISoldier> soldiers = new List <ISoldier>();

            string kingName = Console.ReadLine();

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

            var king = new King(kingName);

            for (int i = 0; i < royalGuardsNames.Length; i++)
            {
                var royalGuard = new RoyalGuard(royalGuardsNames[i]);
                soldiers.Add(royalGuard);
                king.UnderAttack += royalGuard.RespondToKingUnderAttack;
            }

            for (int i = 0; i < footmanNames.Length; i++)
            {
                var footman = new Footman(footmanNames[i]);
                soldiers.Add(footman);
                king.UnderAttack += footman.RespondToKingUnderAttack;
            }

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                var tokens = command.Split();
                var action = tokens[0];

                switch (action)
                {
                case "Attack":
                    king.RespondUnderAttack();
                    break;

                case "Kill":
                    var nameToKill = tokens[1];
                    var soldier    = soldiers.FirstOrDefault(x => x.Name == nameToKill);
                    soldier.HitPoints--;
                    if (soldier.HitPoints == 0)
                    {
                        king.UnderAttack -= soldier.RespondToKingUnderAttack;
                        soldiers.Remove(soldier);
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            IList <Soldier> soldiers = new List <Soldier>();
            King            king     = new King(Console.ReadLine());

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

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

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

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

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

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

                    Soldier deadSoldier = soldiers.FirstOrDefault(s => s.Name.Equals(command[1]));
                    king.BeingAttacked -= deadSoldier.OnKingBeingAttacked;
                    soldiers.Remove(deadSoldier);
                    break;

                case "Attack":

                    king.TakeAttack();
                    break;
                }

                command = Console.ReadLine().Split();
            }
        }
Exemplo n.º 4
0
        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);
                soldiers.Add(guard);
                king.UnderAttack += guard.KingUnderAttack;
            }

            foreach (var name in footmenNames)
            {
                Footman footman = new Footman(name);
                soldiers.Add(footman);
                king.UnderAttack += footman.KingUnderAttack;
            }

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

                if (input[0] == "End")
                {
                    break;
                }
                else if (input[0] == "Kill")
                {
                    Soldier soldier = soldiers.Find(s => s.Name == input[1]);
                    soldiers.Remove(soldier);
                    king.UnderAttack -= soldier.KingUnderAttack;
                }
                else if (input[0] == "Attack")
                {
                    king.OnAttack();
                }
            }
        }
Exemplo n.º 5
0
        private static void GetSoldiers(King king, string soldierType)
        {
            string[] soldiersNames = Console.ReadLine().Split();

            foreach (var name in soldiersNames)
            {
                Soldier soldier = null;
                switch (soldierType)
                {
                case "Royal":
                    soldier = new RoyalGuard(name);
                    break;

                case "Footman":
                    soldier = new Footman(name);
                    break;
                }

                king.AddSoldier(soldier);
            }
        }
Exemplo n.º 6
0
        public static void Main()
        {
            List <Soldier> army = new List <Soldier>();
            King           king = new King(Console.ReadLine());

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

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


            string[] command = Console.ReadLine().Split();
            while (command[0] != "End")
            {
                switch (command[0])
                {
                case "Kill":
                    Soldier soldier = army.FirstOrDefault(s => s.Name == command[1]);
                    king.UnderAttack -= soldier.KingUnderAttack;
                    army.Remove(soldier);
                    break;

                case "Attack":
                    king.OnUnderAttack();
                    break;
                }
                command = Console.ReadLine().Split();
            }
        }
Exemplo n.º 7
0
        private static void SetUpKingsAnturaje()
        {
            var  kingName = Console.ReadLine();
            King king     = new King(kingName);

            var guards = Console.ReadLine().Split(new[] { ' ' },
                                                  StringSplitOptions.RemoveEmptyEntries);

            foreach (var guard in guards)
            {
                RoyalGuard royalGuard = new RoyalGuard(guard);
                king.AddToList(royalGuard);
            }

            var footmans = Console.ReadLine().Split(new[] { ' ' },
                                                    StringSplitOptions.RemoveEmptyEntries);

            foreach (var footman in footmans)
            {
                Footman man = new Footman(footman);
                king.AddToList(man);
            }
        }