예제코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CSharp_Prototype
{
    abstract class Prototype
    {
        private string _id;
 
        public Prototype(string id)
        {
            this._id = id;
        }
        public string Id
        {
            get { return _id; }
        }
 
        public abstract Prototype Clone();
    }
 
    class ConcretePrototype1 : Prototype
    {
        public ConcretePrototype1(string id) : base(id)
        {
        }
 
        public override Prototype Clone()
        {
            return (Prototype)this.MemberwiseClone();
        }
    }
 
    class ConcretePrototype2 : Prototype
    {
        public ConcretePrototype2(string id) : base(id)
        {
        }
 
        public override Prototype Clone() {
            return (Prototype)this.MemberwiseClone();
        }
    }
 
    class Program {
        static void Main()
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);
 
            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);
 
            Console.ReadKey();
        }
    }   
}
 
 
cs






예제코드


namespace 대장간시스템
{
    class 장비
    {
        string 가루;
        string 정수;
        int 공격력;
        int 방어력;        

        public 장비() { }

        public void Set가루(string d) { 가루 = d; }
        public void Set정수(string s) { 정수 = s; }        
    }

    abstract class 생산슬롯
    {
        protected 장비 장비객체;

        public 생산슬롯() { }
        public 장비 Get장비() { return 장비객체; }
        public void 장비객체생성() { 장비객체 = new 장비(); }

        public abstract void Build가루();
        public abstract void Build정수();
        public abstract void Build옵션();
    }

    class 무기생산슬롯 : 생산슬롯
    {
        public override void Build가루()
        {
            장비객체.Set가루("붉은 영혼의 가루");
        }

        public override void Build정수()
        {
            장비객체.Set정수("못된 보스의 정수");
        }

        public override void Build옵션()
        {
            // 장비객체.공격력 = 랜덤생성;
        }
    }

    class 방어구생산슬롯 : 생산슬롯
    {
        public override void Build가루()
        {
            장비객체.Set가루("푸른 영혼의 가루");
        }

        public override void Build정수()
        {
            장비객체.Set정수("무지센 보스의 정수");
        }

        public override void Build옵션()
        {
            // 장비객체.방어력 = 랜덤생성;
        }
    }

    class 대장장이
    {
        private 생산슬롯 선택된생산슬롯;

        public void Set생산슬롯(생산슬롯 slot) { 선택된생산슬롯 = slot; }
        public 장비 Get장비() { return 선택된생산슬롯.Get장비(); }

        public void Construct장비()
        {
            선택된생산슬롯.장비객체생성();
            선택된생산슬롯.Build가루();
            선택된생산슬롯.Build정수();
            선택된생산슬롯.Build옵션();
        }        
    }


    class Program
    {
        static void Main(string[] args)
        {
            대장장이 히드리그 = new 대장장이();
            생산슬롯[] 생산슬롯들 =
            {
                new 무기생산슬롯(),
                new 방어구생산슬롯()
            };

            히드리그.Set생산슬롯(생산슬롯들[0]);
            히드리그.Construct장비();

            장비 제작한장비 = 히드리그.Get장비();
        }
    }
}








예제코드


namespace 스타크래프트II
{
    abstract class 유닛1
    {
    }

    class 마린 : 유닛1
    {

    }

    class 바이킹 : 유닛1
    {

    }

    abstract class 유닛2
    {
    }

    class 불곰 : 유닛2
    {

    }

    class 의료선 : 유닛2
    {

    }

    abstract class 건물
    {
        public abstract 유닛1 유닛생산1();
        public abstract 유닛2 유닛생산2();
    }

    class 병영 : 건물
    {
        public override 유닛1 유닛생산1()
        {
            return new 마린();            
        }

        public override 유닛2 유닛생산2()
        {
            return new 불곰();
        }
    }

    class 우주공항 : 건물
    {
        public override 유닛1 유닛생산1()
        {
            return new 바이킹();
        }

        public override 유닛2 유닛생산2()
        {
            return new 의료선();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}


+ Recent posts