스타크래프트 - 배럭
2020. 4. 14. 18:00ㆍC#/수업내용
1) 배럭 기능 구현
a) 유닛 생산 : 클래스로 구현 및 관리
- 유닛 생산 조건 : TechnicalTree 클래스를 이용하여 Static 변수로 조건 개별 관리
-> 플레이어마다 단 하나의 트리만 있으면 됨. 또한 모든 클래스에서 조건을 확인하기 때문에 어디서든 접근이 용이해야함.
b) 자체 기능 : 메소드로 구현
<TechnicalTree.cs>
- 유닛 생산 조건에 따른 종족 테크트리 조건을 정리해놓은 클래스
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class TechnicalTree
{
static bool isbarracks;
static bool isAcademy;
static bool isFactory;
static bool isStarport;
static bool isScienceFacility;
static bool isConvertOps;
public TechnicalTree()
{
isbarracks = false;
isAcademy = false;
isFactory = false;
isStarport = false;
isScienceFacility = false;
isConvertOps = false;
}
static public bool GetBarracks()
{
return isbarracks;
}
static public void SetBarracksOn()
{
isbarracks = true;
}
static public void SetBarracksOff()
{
isbarracks = false;
}
static public bool GetAcademy()
{
return isAcademy;
}
static public void SetAcademyOn()
{
isAcademy = true;
}
static public void SetAcademyOff()
{
isAcademy = false;
}
static public bool GetFactory()
{
return isFactory;
}
static public void SetFactoryOn()
{
isFactory = true;
}
static public void SetFactoryOff()
{
isFactory = false;
}
static public bool GetStarport()
{
return isStarport;
}
static public void SetStarportOn()
{
isStarport = true;
}
static public void SetStarportOff()
{
isStarport = false;
}
static public bool GetScienceFacility()
{
return isScienceFacility;
}
static public void SetScienceFacilityOn()
{
isScienceFacility = true;
}
static public void SeScienceFacilityOff()
{
isScienceFacility = false;
}
static public bool GetConvertOps()
{
return isConvertOps;
}
static public void SetConvertOpsOn()
{
isConvertOps = true;
}
static public void SetConvertOpsOff()
{
isConvertOps = false;
}
}
}
|
<Barracks.cs>
- 유닛 생산 클래스
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class Barracks
{
string name;
int hp;
bool isLand;
public Barracks()
{
this.name = "Terran Barracks";
this.hp = 1000;
this.isLand = true;
TechnicalTree.SetBarracksOn();
}
// 건물 착지
public void Land()
{
if (this.isLand == false)
{
this.isLand = true;
}
else
{
}
}
// 건물 띄움
public void LiftOff()
{
if (this.isLand == true)
{
this.isLand = false;
}
else
{
}
}
// 생산 후 위치 이동
public void SetRellyPoint(int x, int y)
{
Console.WriteLine($"Relly Point를 ({x},{y})로 지정했습니다. ");
}
public Unit CreateMarine()
{
return marine;
}
public Unit CreateMedic()
{
if (TechnicalTree.GetAcademy() == true)
{
return medic;
}
else
{
Console.WriteLine($"Academy를 먼저 건설해야 합니다. ");
return null;
}
}
public Unit CreateFireBat()
{
if (TechnicalTree.GetAcademy() == true)
{
Unit fireBat = new Unit(UnitType.FireBat);
return fireBat;
}
else
{
Console.WriteLine($"Academy를 먼저 건설해야 합니다. ");
return null;
}
}
public Unit CreateGhost()
{
if (TechnicalTree.GetAcademy() == true)
{
if(TechnicalTree.GetConvertOps() == true)
{
return ghost;
}
else
{
Console.WriteLine($"ConvertOps를 먼저 건설해야 합니다. ");
return null;
}
}
else
{
Console.WriteLine($"Academy를 먼저 건설해야 합니다. ");
return null;
}
}
}
}
|
<Academy.cs>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class Academy
{
string name;
int hp;
public Academy()
{
if (TechnicalTree.GetBarracks() == true)
{
this.name = "Terran Academy";
this.hp = 600;
TechnicalTree.SetAcademyOn();
}
else
Console.WriteLine("Barracks를 먼저 건설해야 합니다. ");
}
}
}
|
<Factory.cs>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class Factory
{
string name;
int hp;
bool isLand;
public Factory()
{
if(TechnicalTree.GetBarracks() == true)
{
this.name = "Terran Factory";
this.hp = 1250;
this.isLand = true;
TechnicalTree.SetFactoryOn();
}
else
Console.WriteLine("Barracks를 먼저 건설해야 합니다. ");
}
// 건물 착지
public void Land()
{
if (this.isLand == false)
{
this.isLand = true;
}
else
{
}
}
// 건물 띄움
public void LiftOff()
{
if (this.isLand == true)
{
this.isLand = false;
}
else
{
}
}
// 생산 후 위치 이동
public void SetRellyPoint(int x, int y)
{
Console.WriteLine($"Relly Point를 ({x},{y})로 지정했습니다. ");
}
}
}
|
<Starport.cs>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class Starport
{
string name;
int hp;
bool isLand;
public Starport()
{
if (TechnicalTree.GetFactory() == true)
{
this.name = "Terran Starport";
this.hp = 1300;
this.isLand = true;
TechnicalTree.SetStarportOn();
}
else
Console.WriteLine("Factory를 먼저 건설해야 합니다. ");
}
// 건물 착지
public void Land()
{
if (this.isLand == false)
{
this.isLand = true;
}
else
{
}
}
// 건물 띄움
public void LiftOff()
{
if (this.isLand == true)
{
this.isLand = false;
}
else
{
}
}
// 생산 후 위치 이동
public void SetRellyPoint(int x, int y)
{
Console.WriteLine($"Relly Point를 ({x},{y})로 지정했습니다. ");
}
}
}
|
<ScienceFacility.cs>
- Ghost를 생산하기 위한 조건인 [ConvertOps]는 별도의 건물이 아닌, ScienceFacility의 부속 건물이므로
클래스를 따로 생성하지 않고 ScienceFacility 클래스 내의 멤버함수로써 관리하도록 구성
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
65
66
67
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class ScienceFacility
{
string name;
int hp;
bool isLand;
public ScienceFacility()
{
if (TechnicalTree.GetStarport() == true)
{
this.name = "Terran Science Facility";
this.hp = 1300;
this.isLand = true;
TechnicalTree.SetScienceFacilityOn();
}
else
Console.WriteLine("Starpot를 먼저 건설해야 합니다. ");
}
public void BuildConvertOps()
{
TechnicalTree.SetConvertOpsOn();
Console.WriteLine("ConvertOps를 건설했습니다.");
}
// 건물 착지
public void Land()
{
if (this.isLand == false)
{
this.isLand = true;
}
else
{
}
}
// 건물 띄움
public void LiftOff()
{
if (this.isLand == true)
{
this.isLand = false;
}
else
{
}
}
// 생산 후 위치 이동
public void SetRellyPoint(int x, int y)
{
Console.WriteLine($"Relly Point를 ({x},{y})로 지정했습니다. ");
}
}
}
|
'C# > 수업내용' 카테고리의 다른 글
배열 - 캐릭터의 무기 습득 및 장착 (0) | 2020.04.20 |
---|---|
배열의 복사(Deep/Shallow) (0) | 2020.04.16 |
인벤토리에 아이템 넣기 (0) | 2020.04.14 |
아이템 선택 및 강화 (0) | 2020.04.09 |
#Enum - 캐릭터 생성 시 직업 및 종족 선택 (0) | 2020.04.08 |