Exemplo n.º 1
0
    public static void main(string[] args)
    {
        HeroBuilder builder = new HeroBuilder();

        builder.SetName("Batman")
        .SetAlterEgo("Bruce Wayne")
        .SetBaseOfOperations("Gotham City")
        .SetNemesis("The Joker, Ra's-al-Ghul, The Court of Owls")
        .WearsCape(true);

        // Breaking it up for readability:
        builder.AddStrength("Genius-level intellect")
        .AddStrength("Expert in forensics")
        .AddStrength("Trained to physical perfection")
        .AddStrength("The World's Greatest Detective")
        .AddStrength("Lives by a code of honor to never kill");

        builder.AddWeakness("Can be prey to his own anger")
        .AddWeakness("Often refuses help from others");

        // Create the character:
        SuperHero theDarkKnight = builder.BuildHero();

        // Get to know the character!
        theDarkKnight.PrintProfile();
    }
Exemplo n.º 2
0
        private static Hero MakeCustomHero()
        {
            var  builder   = new HeroBuilder();
            bool isFlyHero = false;

            do
            {
                Console.Clear();
                Console.WriteLine("0 - Set\\Unset fly mode");
                Console.WriteLine("1 - Set name");
                Console.WriteLine("2 - Set armor");
                Console.WriteLine("3 - Set weapon");
                Console.WriteLine("4 - Build hero");
                switch (GetCommand())
                {
                case 0:
                    isFlyHero = !isFlyHero;
                    break;

                case 1:
                    Console.Write("Name: ");
                    builder.SetName(Console.ReadLine());
                    break;

                case 2:
                    Console.Write("Armor: ");
                    builder.SetArmor(Console.ReadLine());
                    break;

                case 3:
                    Console.Write("Weapon: ");
                    builder.SetWeapon(Console.ReadLine());
                    break;

                case 4:
                    if (isFlyHero)
                    {
                        return(new FlyHeroDecorator(builder.Build()));
                    }
                    else
                    {
                        return(builder.Build());
                    }
                }
            } while (true);
        }