스타크래프트 테란 종족을 이용한 클래스 메서드 연습
-----------------------------------------------------------------------------------------------------------------------------------
App Class
-----------------------------------------------------------------------------------------------------------------------------------
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class App
{
public App()
{
CommandCenter commandCenter = new CommandCenter();
Barracks barracks = new Barracks();
//이미 유닛테이블에 정의가 다 되어있음.
//실제로 값을 넣지않고, 테이블파일값을 받아 자동으로 초기화되게함.
//만약에 LiffOff버튼을 누르면
//LiftOff메서드 호출
//Land버튼을 누르면
//Land메서드 호출
//내 코드를 사용하는 사람이 사용하기 편하게 만들어야 잘만든 코드
//사용자가 배럭을 보자마자 생각하는건 띄우고 내리고이기 때문에, 메서드를 추가해 준다.
//barracks.CurrentBarracksStatus = eBarracksStatusType.LiftOff
//프로젝트가 길어져 클래스수가 많아질 경우, 값을 바꾸면 안되는 변수를 바꾸는 경우도 생긴다.
//이를 방지하기위해 public을 지우거나, 따로 값을 반환하는 메서드를 이용한다.
eBarracksStatusType status = barracks.GetCurrentBarracksStatus();
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@현재 상태 : {0}", status);
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@배럭 모드 변경");
Console.WriteLine("--------------------------------------------------");
if (status == eBarracksStatusType.LiftOff)
{
}
{
barracks.LiftOff();
}
status = barracks.GetCurrentBarracksStatus();
Console.WriteLine("@@@@@@@@@@현재 상태 : {0}", status);
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@배럭 이동");
Console.WriteLine("--------------------------------------------------");
barracks.CurrentBarrackLocation();
barracks.CurrentBarrackLocation();
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@유닛생성 [아카데미X]");
Console.WriteLine("--------------------------------------------------");
Unit firebat = barracks.CreateUnit(eUnitType.Firebat, null, null, null);
Console.WriteLine("\n 현재 만들어진 유닛 {0} {1} {2} {3}",marine.ShowName(),medic.ShowName(),firebat,Ghost);
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@공격 하기");
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@아카데미 생성");
Console.WriteLine("--------------------------------------------------");
Academy academy = new Academy();
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@유닛생성 [아카데미 O]");
Console.WriteLine("--------------------------------------------------");
firebat = barracks.CreateUnit(eUnitType.Firebat, academy, null, null);
Console.WriteLine("\n 현재 만들어진 유닛 {0} {1} {2} {3}", marine.ShowName(), medic.ShowName(), firebat.ShowName(), Ghost);
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@사이언스 팩실리티, 코버트옵스 생성");
Console.WriteLine("--------------------------------------------------");
ScienceFacility scienceFacility = new ScienceFacility();
CovertOps covertOps = scienceFacility.CreateCovertOps();
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@유닛생성 [사이언스 팩실리티 O, 코버트 옵스 O]");
Console.WriteLine("--------------------------------------------------");
marine = barracks.CreateUnit(eUnitType.Marine, academy, scienceFacility, covertOps);
medic = barracks.CreateUnit(eUnitType.Medic, academy, scienceFacility, covertOps);
firebat = barracks.CreateUnit(eUnitType.Firebat, academy, scienceFacility, covertOps);
Ghost = barracks.CreateUnit(eUnitType.Ghost, academy, scienceFacility, covertOps);
Console.WriteLine("\n 현재 만들어진 유닛 {0} {1} {2} {3}", marine.ShowName(), medic.ShowName(), firebat.ShowName(), Ghost.ShowName());
Console.WriteLine("--------------------------------------------------");
Console.WriteLine("@@@@@@@@@@커맨드센터에 NewClearSilo건설");
Console.WriteLine("--------------------------------------------------");
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
CommandCenter Class
-----------------------------------------------------------------------------------------------------------------------------------
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class CommandCenter
{
public string name; //이름
public int hp; //체력
public int maxHp; //최대체력
public int X = 0;
public int Y = 0;
int id;
public CommandCenter()
{
Console.WriteLine("커맨드센터가 생성되었습니다.");
}
public NewClearSilo CreateNewClearSilo()
{
return new NewClearSilo();
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
NewClearSilo Class
-----------------------------------------------------------------------------------------------------------------------------------
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 NewClearSilo
{
public string name; //이름
public int hp; //체력
public int maxHp; //최대체력
int id;
bool newclearisReady = false;
public NewClearSilo()
{
Console.WriteLine("NewClearSilo가 생성되었습니다.");
}
public void CreateNewClear()
{
this.newclearisReady = true;
Console.WriteLine("핵미사일이 준비되었습니다.");
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
Barracks Class
-----------------------------------------------------------------------------------------------------------------------------------
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
public enum eBarracksStatusType
{
//None, 건설과 동시에 기본값이 Land기 때문에 None이 필요없음.
LiftOff,
Land,
}
class Barracks
{
//데이터
public string name; //이름
public int hp; //체력
public int maxHp; //최대체력
public int X=0;
public int Y=0;
int id;
Unit unit;
eBarracksStatusType CurrentBarracksStatus; //배럭의 상태
public Barracks()
{
this.name = "Barracks";
Console.WriteLine("배럭이 생성되었습니다.");
}
//메서드
//상태를 변경할 수 있다.
public void Init(int id, int hp)
{
this.id = id;
this.hp = hp;
this.maxHp = this.hp;
}
public eBarracksStatusType GetCurrentBarracksStatus()
{
return this.CurrentBarracksStatus;
}
public void ChangeBarracksStatus()
{
}
//이동할 수 있다.
public void LiftOff()
{
this.CurrentBarracksStatus = eBarracksStatusType.LiftOff;
}
public void CurrentBarrackLocation()
{
Console.WriteLine("배럭의 현재 위치 : ({0} , {1})", this.X, this.Y);
}
public void Move(int X, int Y)
{
{
Console.WriteLine("Land 상태에서는 이동할 수 없습니다.");
}
else if (this.CurrentBarracksStatus == eBarracksStatusType.LiftOff)
{
this.X += X;
this.Y += Y;
Console.WriteLine("배럭이 ({0}, {1}) 로 이동했습니다.",X,Y);
}
}
//정지할 수 있다.
public void Stop()
{
Console.WriteLine("배럭이 멈췄습니다. ({0} , {1})", this.X, this.Y);
}
//유닛생성 한다.
public void Land()
{
}
public Unit CreateUnit(eUnitType unitType, Academy exist1, ScienceFacility exist2, CovertOps exist3)
{
if (exist1 == null && exist2 == null && exist3 == null)
{
{
this.unit = new Unit(unitType, 6, 100);
}
{
this.unit = new Unit(unitType, 0, 100);
}
else if (unitType == eUnitType.Firebat)
{
Console.WriteLine("[{0}]는 아카데미가 필요합니다.", eUnitType.Firebat);
this.unit = null;
}
{
this.unit = null;
}
}
else if (exist1 != null && exist2 == null && exist3 == null)
{
{
this.unit = new Unit(unitType, 6, 100);
}
{
this.unit = new Unit(unitType, 0, 100);
}
else if (unitType == eUnitType.Firebat)
{
this.unit = new Unit(unitType, 8, 150);
}
{
this.unit = null;
}
}
else if (exist1 != null && exist2 != null && exist3 != null)
{
{
this.unit = new Unit(unitType, 6, 100);
}
{
this.unit = new Unit(unitType, 0, 100);
}
else if (unitType == eUnitType.Firebat)
{
this.unit = new Unit(unitType, 8, 150);
}
{
this.unit = new Unit(unitType, 10, 75);
}
}
return this.unit;
}
//유닛으로부터 피해를 받을 수 있다.
public void Hit(Unit target)
{
if (this.hp <= 0)
{
this.hp = 0;
}
Console.WriteLine("[{0}]으로부터 [{1}]가 공격받았습니다.", target.ShowName(), this.name);
Console.WriteLine("현재 [{0}] 의 체력: [{1} / {2}]", this.name, this.hp,this.maxHp);
this.Destory(this.hp);
}
//파괴될 수 있다.
public void Destory(int hp)
{
if (hp <= 0)
{
Console.WriteLine("유저의 [{0}]가 폭파 되었습니다.", this.name);
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
Academy Class
-----------------------------------------------------------------------------------------------------------------------------------
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class Academy
{
string name ="Academy"; //이름
public int hp; //체력
public int maxHp; //최대체력
int id;
public Academy()
{
Console.WriteLine("아카데미가 생성되었습니다.");
}
public void Init(int id, int hp)
{
this.id = id;
this.hp = hp;
this.maxHp = this.hp;
}
public string ShowName()
{
return this.name;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
ScienceFacility Class
-----------------------------------------------------------------------------------------------------------------------------------
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class ScienceFacility
{
public string name; //이름
public int hp; //체력
public int maxHp; //최대체력
public int X = 0;
public int Y = 0;
int id;
public ScienceFacility()
{
Console.WriteLine("ScienceFacility가 생성되었습니다.");
}
public CovertOps CreateCovertOps()
{
return new CovertOps();
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
CovertOps Class
-----------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
class CovertOps
{
public string name; //이름
public int hp; //체력
public int maxHp; //최대체력
int id;
public CovertOps()
{
Console.WriteLine("CovertOps가 생성되었습니다.");
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
-----------------------------------------------------------------------------------------------------------------------------------
Unit Class
-----------------------------------------------------------------------------------------------------------------------------------
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_009
{
public enum eUnitType
{
Marine,
Medic,
Firebat,
Ghost,
}
class Unit
{
eUnitType unitType;
int damage; // public으로 해야할 것과 하지말아야 할것을 판단해서 설정
int hp;
public Unit(eUnitType unitType, int damage, int hp)
{
this.unitType = unitType;
this.damage = damage;
this.hp = hp;
Console.WriteLine("{0} 가 생성되었습니다. ", this.ShowName());
}
public eUnitType ShowName()
{
return this.unitType;
}
public void Attack(Barracks target)
{
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'C# > 수업내용' 카테고리의 다른 글
2020-04-22 업적시스템 만들기(파일입출력) (0) | 2020.04.22 |
---|---|
2020-04-16 수업내용 Source (0) | 2020.04.16 |
2020-04-13 수업내용 (0) | 2020.04.13 |
2020-04-09 수업내용 Source (0) | 2020.04.09 |
2020-04-08 수업내용 Source (0) | 2020.04.08 |