コード例 #1
0
ファイル: Prototype.cs プロジェクト: Eldoir/DesignPatterns
        public void DisplayExample()
        {
            Monster ghost = new Ghost(5, 2);

            var ghostSpawner = new MonsterSpawner(ghost);

            ghostSpawner.Clone();
            ghostSpawner.Clone();

            // You can make use of a registry to add and get ready-to-use prototypes.
            var monsterRegistry = new MonsterRegistry();

            monsterRegistry["BabySkeleton"]  = new Skeleton(2, 3);
            monsterRegistry["AdultSkeleton"] = new Skeleton(6, 4);

            var adultSkeleton = (Monster)monsterRegistry["AdultSkeleton"].Clone();

            var skeletonSpawner = new MonsterSpawner(adultSkeleton);

            skeletonSpawner.Clone();
            skeletonSpawner.Clone();
        }