C#/수업내용
2020.04.13. 수업내용 - Barracks, Unit class(enum)
dev_sr
2020. 4. 13. 22:30
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);
}
}
}
|