1. 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
class App
{
public App()
{
Barracks barracks=new Barracks();
Unit marine = barracks.CreateUnit(1);
Unit marine2 = barracks.CreateUnit(1);
Unit medic = barracks.CreateUnit(2);
}
}
}
|
2. 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
class Barracks
{
public int id = 0;
public Barracks()
{
Console.WriteLine("배럭이 생성되었습니다.");
}
public Unit CreateUnit(int selectedNum)
{
eUnitType unitType = (eUnitType)selectedNum;
Unit unit = new Unit(unitType,id);
this.id++;
return unit;
}
}
}
|
3. 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
44
45
46
47
48
49
50
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_008
{
public enum eUnitType
{
None,
Marine,
Medic
}
class Unit
{
public eUnitType unitType;
public int id;
public Unit(eUnitType unitType,int id)
{
this.unitType = unitType;
this.id = id;
Console.WriteLine("{0}({1})이 생성되었습니다.",this.unitType,this.id);
}
public void Attack(Unit target)
{
{
}
{
target.Hit(this);
}
}
public void Hit(Unit target)
{
Console.WriteLine("{0}({1})이 {2}({3})에게 공격 당했습니다", this.unitType, this.id, target.unitType, target.id);
}
}
}
|
'C# > 수업내용' 카테고리의 다른 글
2020.04.16. 수업내용 - 문자열 배열 출력, 배열값 거꾸로 출력하기(foreach) (0) | 2020.04.16 |
---|---|
2020.04.14. 수업내용 - Barracks, Unit, Academy 클래스 (0) | 2020.04.14 |
2020.04.13. 수업내용 - SiegeTank 클래스(enum), Factory 클래스 (0) | 2020.04.13 |
2020.04.09. 수업내용 - 물약 먹기(enum, switch) (0) | 2020.04.09 |
2020.04.09. 수업내용 - 요일 영어로 출력하기(enum,switch) (0) | 2020.04.09 |