コード例 #1
0
        public static void Main()
        {
            ModifiedDictionary armyMembers = new ModifiedDictionary();

            string kingName = Console.ReadLine();

            King king = new King(kingName);

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

            foreach (var name in royalGuardNames)
            {
                armyMembers.Add(name, new RoyalGuard(name));
                armyMembers[name].ArmyMemberDeath += armyMembers.HandlerArmyMemberDeath;
                armyMembers[name].ArmyMemberDeath += king.OnArmyMemberDeath;
                king.KingAttacked += armyMembers[name].OnKingAtacked;
            }
            foreach (var name in footmanNames)
            {
                armyMembers.Add(name, new Footman(name));
                armyMembers[name].ArmyMemberDeath += armyMembers.HandlerArmyMemberDeath;
                armyMembers[name].ArmyMemberDeath += king.OnArmyMemberDeath;
                king.KingAttacked += armyMembers[name].OnKingAtacked;
            }

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

            while (commandInput[0] != "End")
            {
                string command = commandInput[0];

                switch (command)
                {
                case "Kill":
                {
                    string       name          = commandInput[1];
                    RoyalRetinue memberRemoved = armyMembers[name];
                    memberRemoved.ReactionKingAttaked();
                }
                break;

                case "Attack":
                {
                    king.KingMessage();
                }
                break;
                }

                commandInput = Console.ReadLine().Split();
            }
        }
コード例 #2
0
    public static void Main()
    {
        var soldiers = new ModifiedDictionary();


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

        var royalGuardsNames = Console.ReadLine().Split().ToList();

        foreach (var rgName in royalGuardsNames)
        {
            var royalGuard = new RoyalGuard(rgName);
            soldiers.Add(rgName, royalGuard);
            royalGuard.SoliderDeath += soldiers.HandleSoliderDeath;
            royalGuard.SoliderDeath += king.OnSoliderDeath;
            king.UnderAttack        += royalGuard.KingUnderAttack;
        }

        var footmansNames = Console.ReadLine().Split().ToList();

        foreach (var fmName in footmansNames)
        {
            var footman = new Footman(fmName);
            soldiers.Add(fmName, footman);
            footman.SoliderDeath += soldiers.HandleSoliderDeath;
            footman.SoliderDeath += king.OnSoliderDeath;
            king.UnderAttack     += footman.KingUnderAttack;
        }

        var inputCommands = string.Empty;

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

            switch (command)
            {
            case "Attack":
                king.OnUnderAttack();
                break;

            case "Kill":
                var soliderToRemove = soldiers[commands[1]];
                soliderToRemove.RespondToAttack();
                break;
            }
        }
    }
コード例 #3
0
    public static void Main()
    {
        var king = new King(Console.ReadLine());
        ModifiedDictionary soldiersByName = new ModifiedDictionary();

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

        foreach (var guardName in royalGuards)
        {
            RoyalGuard newGuard = new RoyalGuard(guardName);
            soldiersByName.Add(guardName, newGuard);
            newGuard.SoldierDeath += soldiersByName.HandleSoldierDeath;
            newGuard.SoldierDeath += king.OnSoldierDeath;
            king.UnderAttack      += newGuard.OnKingUnderAttack;
        }

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

        foreach (var footmanName in footmen)
        {
            Footman newFootman = new Footman(footmanName);
            soldiersByName.Add(footmanName, newFootman);
            newFootman.SoldierDeath += soldiersByName.HandleSoldierDeath;
            newFootman.SoldierDeath += king.OnSoldierDeath;
            king.UnderAttack        += newFootman.OnKingUnderAttack;
        }

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

        while (!line[0].Equals("End"))
        {
            var command = line[0];
            var name    = line[1];

            switch (command)
            {
            case "Kill":
                Soldier soldierToRemove = soldiersByName[name];
                soldierToRemove.RespondToAttack();
                break;

            case "Attack":
                king.RespondToAttack();
                break;
            }
            line = Console.ReadLine().Split();
        }
    }