Beispiel #1
0
        private static void ReadRoyalGuards()
        {
            string[] guards = Console.ReadLine().Split();

            foreach (var guardName in guards)
            {
                RoyalGuard rg = new RoyalGuard(guardName);
                king.KingAttacked += rg.ProtectKing;
                soldiers.Add(rg);
            }
        }
        public static void Main()
        {
            SoldierList soldiers = new SoldierList();
            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] != "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();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var soldiers         = new SoldiersList();
            var king             = new King(Console.ReadLine());
            var royalGuardsNames = Console.ReadLine().Split();

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

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

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

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

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

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

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

                case "Attack":

                    king.TakeAttack();
                    break;
                }

                command = Console.ReadLine().Split();
            }
        }
        private static void Main()
        {
            SoldierList soldiers = new SoldierList();
            King        king     = new King(Console.ReadLine());

            string[] royalGuardNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in royalGuardNames)
            {
                RoyalGuard rg = new RoyalGuard(name);
                rg.SoldierDead += soldiers.HandleDeadSoldier;
                rg.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(rg);
                king.KingAttacked += rg.OnKingAttack;
            }

            string[] footmanNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in footmanNames)
            {
                Footman fm = new Footman(name);
                fm.SoldierDead += soldiers.HandleDeadSoldier;
                fm.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(fm);
                king.KingAttacked += fm.OnKingAttack;
            }

            string command = string.Empty;

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

                if (tokens[0] == "Attack")
                {
                    king.RespondToAttack();
                }
                else if (tokens[0] == "Kill")
                {
                    string    name    = tokens[1];
                    IDefender soldier = soldiers.First(x => x.Name == name);
                    soldier.TakeAttack();
                }
            }
        }
        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;
            }
        }