Exemplo n.º 1
0
        public static void Main()
        {
            string kingsName = Console.ReadLine();
            King   king      = new King(kingsName);

            var royalGuardsNames = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var footmenNames = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var defenders = new List <Person>();

            foreach (var name in royalGuardsNames)
            {
                RoyalGuard guard = new RoyalGuard(name);
                defenders.Add(guard);
                king.IsAttacked += guard.DefendTheKing;
            }

            foreach (var name in footmenNames)
            {
                Footman footman = new Footman(name);
                defenders.Add(footman);
                king.IsAttacked += footman.DefendTheKing;
            }

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

                switch (command)
                {
                case "Kill":
                    string name     = input[1];
                    Person defender = defenders.First(s => s.Name == name);
                    defenders.Remove(defender);
                    king.IsAttacked -= ((IDefender)defender).DefendTheKing;
                    break;

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

                case "End":
                    return;
                }
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            IList <Soldier> soldiers = new List <Soldier>();


            King king = new King(Console.ReadLine());

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

            foreach (var royalGuard in royalGuards)
            {
                RoyalGuard guard = new RoyalGuard(royalGuard);

                soldiers.Add(guard);

                king.BeingAttacked += guard.Attack;
            }
            var footmans = Console.ReadLine().Split();

            foreach (var footman in footmans)
            {
                Footman guard = new Footman(footman);

                soldiers.Add(guard);

                king.BeingAttacked += guard.Attack;
            }

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                var splitCommand = command.Split();

                switch (splitCommand[0])
                {
                case "Attack":
                    king.TakeAttack();
                    break;

                case "Kill":
                    Soldier soldier = soldiers.First(n => n.Name.Equals(splitCommand[1]));
                    king.BeingAttacked -= soldier.Attack;
                    soldiers.Remove(soldier);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            var king     = new King(Console.ReadLine());
            var soldiers = new List <Soldier>();

            var guardsNames  = ParseInput(Console.ReadLine());
            var footmenNames = ParseInput(Console.ReadLine());

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

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                var commandArgs = ParseInput(input);
                var command     = commandArgs[0];

                switch (command)
                {
                case "Kill":
                    var soldierName = commandArgs[1];
                    var soldier     = soldiers.FirstOrDefault(s => s.Name == soldierName);
                    king.UnderAttack -= soldier.KingUnderAttack;
                    soldiers.Remove(soldier);
                    break;

                case "Attack":
                    king.OnAttack();
                    break;
                }
            }
        }
Exemplo n.º 4
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.º 5
0
        public static void Main()
        {
            var king     = new King(Console.ReadLine());
            var soldiers = new List <Soldier>();

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

            foreach (var royalGuard in royalGuards)
            {
                var guard = new RoyalGuard(royalGuard);
                king.UnderAttack += guard.KingUnderAttack;
                soldiers.Add(guard);
            }

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

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

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

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

                case "Attack":
                    king.OnUnderAttack();
                    break;
                }

                command = Console.ReadLine().Split();
            }
        }
        private void BuildKingdom()
        {
            var kingName = Console.ReadLine();

            this.king = new King(kingName);

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

            foreach (var name in royalGuardNames)
            {
                var royalGuard = new RoyalGuard(name);
                this.soldiers.Add(royalGuard);
                this.king.UnderAttack += royalGuard.KindUnderAttack;
            }

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

            foreach (var name in footmanNames)
            {
                var footman = new Footman(name);
                this.soldiers.Add(footman);
                this.king.UnderAttack += footman.KindUnderAttack;
            }
        }