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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
public class App
{
public App()
{
Console.WriteLine("2020-04-13\n=======================================================\n");
/*
//비행기 게임
AirPlane hero = new AirPlane("드래곤", 3);
Monster monster = new Monster();
Bullet bullet = null;
Console.WriteLine("게임의 좌표 : (-10 ~ 10, -10 ~ 10)까지.");
while (true)
{
int inputCommand;
{
//입력 받는 부분.
Console.Write("\n명령어를 입력해 주세요. 1 : 왼쪽 이동, 2 : 오른쪽 이동, 3 : 미사일 발사. 나머지 수 : 턴 넘기기. 입력 : ");
inputCommand = int.Parse(Console.ReadLine());
}
{
//입력 받고 업데이트 하는 부분.
monster.MoveVertical();
if (bullet != null)
{
if (bullet.MoveVertical())
bullet = null;
}
switch (inputCommand)
{
case 1:
hero.MoveHorizontal(-1);
break;
case 2:
hero.MoveHorizontal(+1);
break;
case 3:
bullet = hero.ShootBullet();
break;
default:
Console.WriteLine("턴을 넘깁니다.");
break;
}
//몬스터 또는 히어로가 죽는 경우.
if (bullet != null && monster.isHit(bullet))
break;
else if (hero.isHit(monster))
break;
}
{
//결과 출력하는 부분.
Console.WriteLine("\n정보 출력==================================");
hero.PrintInfo();
monster.PrintInfo();
if (bullet == null)
Console.WriteLine("총알이 없습니다.");
else
bullet.PrintInfo();
}
}
*/
/*
//또다시 홍길동 임꺽정 class 예제.
Character hong = new Character("홍길동");
Character lim = new Character("임꺽정", 120, 8);
Console.WriteLine("");
*/
/*
//스타크래프트 배럭스 클래스 예제.
Building barr = new Building("배럭");
Unit marine = barr.CreateUnit(1);
Unit medic = barr.CreateUnit(2);
marine = barr.CreateUnit("Marine");
medic = barr.CreateUnit("Medic");
marine = barr.CreateUnit();
medic = barr.CreateUnit();
for(int i = 0; i < 9; i++)
{
marine = barr.CreateUnit(1);
}
*/
/*
//스타크래프트 라바 클래스 예제.
Hatchery hatchery = new Hatchery();
Larva larva = hatchery.SpawnLarva();
Drone drone = larva.BecomeDrone();
larva = null;
Hatchery hatchery2 = drone.BecomeHatchery();
drone = null;
drone = new Drone();
Hatchery h = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery();
Hatchery h2 = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery();
Hatchery h3 = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery();
*/
//스타크래프트 팩토리 탱크 클래스 예제.
Factory factory = new Factory();
Tank tank1 = factory.SpawnTank();
tank1.ChangeMode();
tank1.ChangeMode();
Console.WriteLine("");
Tank tank2 = factory.SpawnTank();
tank2.ChangeMode();
tank2.ChangeMode();
}
}
}
|
public App()의 내용입니다. 주석을 풀어가며 실행하시면 되겠습니다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
public class AirPlane
{
public string Name;
public int XPos;
public int YPos;
public int Damage;
public AirPlane()
{
this.XPos = 0;
this.YPos = -3;
this.Damage = 3;
}
public AirPlane(string name)
{
this.Name = name;
this.XPos = 0;
this.YPos = -3;
this.Damage = 3;
}
public AirPlane(string name, int damage)
{
this.Name = name;
this.XPos = 0;
this.YPos = -3;
this.Damage = damage;
}
public void PrintInfo()
{
Console.WriteLine("기체 이름 : {0}, X위치 : {1}, Y위치 : {2}, 데미지 : {3}", this.Name, this.XPos, this.YPos, this.Damage);
}
public void MoveHorizontal() => this.MoveHorizontal(1);
public void MoveHorizontal(int xDistance)
{
if (this.XPos <= -10 || this.XPos >= 10)
Console.WriteLine("범위를 넘어갔습니다.");
else
{
this.XPos += xDistance;
}
}
public Bullet ShootBullet()
{
return new Bullet(this);
}
public bool isHit(Monster monster)
{
if (temp)
this.Die();
return temp;
}
public void Die()
{
Console.WriteLine("{0} 영웅이 죽었습니다.", this.Name);
}
}
}
|
|
1-1 비행기 클래스 내용 입니다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
public class Bullet
{
public int Damage;
public int XPos;
public int YPos;
public Bullet(AirPlane hero)
{
}
public Bullet(AirPlane hero, int damage)
{
this.Damage = damage;
}
public void PrintInfo()
{
Console.WriteLine("총알 데미지 : {0}, 총알 X좌표 : {1}, 총알 Y좌표 : {2}", this.Damage, this.XPos, this.YPos);
}
public bool MoveVertical()
{
return MoveVertical(1);
}
public bool MoveVertical(int yDistance)
{
this.YPos += yDistance;
return this.YPos > 10;
}
}
}
|
1- 2 불릿 클래스 입니다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
public class Monster
{
public string Name;
public int XPos;
public int YPos;
public int Hp;
public Monster()
{
this.XPos = 0;
this.YPos = 10;
}
public Monster(int xPos, int yPos)
{
this.XPos = xPos;
this.YPos = yPos;
}
public bool MoveVertical()
{
return this.MoveVertical(1);
}
public bool MoveVertical(int yDistance)
{
this.YPos -= yDistance;
return this.YPos < -10;
}
public bool isHit(Bullet bullet)
{
if (temp)
this.Die();
return temp;
}
public void Die() => Console.WriteLine("몬스터가 죽었습니다. ");
public void PrintInfo()
{
Console.WriteLine("몬스터 이름 : {0}, X좌표 : {1}, Y좌표 : {2}, 체력 : {3}", this.Name, this.XPos, this.YPos, this.Hp);
}
}
}
|
|
1 - 3 몬스터 클래스 입니다.
세개를 모두 넣으시면 간단한 비행기 게임을 할 수 있습니다.
Hatchery h = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery();
Hatchery h2 = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery();
Hatchery h3 = hatchery.SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery().SpawnLarva().BecomeDrone().BecomeHatchery();
Study_009 -2 아이템 인벤토리 배열 (0) | 2020.04.14 |
---|---|
Study_009 - 1 유닛, 배럭, 아카데미 (0) | 2020.04.14 |
Study_006-1 (0) | 2020.04.09 |
Study_005 (0) | 2020.04.08 |
Study004 (0) | 2020.04.08 |