C#/수업내용
2020.04.09. 수업내용 - 물약 먹기(enum, switch)
dev_sr
2020. 4. 9. 22:39
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
|
class App
{
enum ePortion
{
HpPortion,
MpPortion
}
public App()
{
Console.WriteLine("2020-04-09\n");
//enum, switch 물약
string heroName = "홍길동";
int maxHp = 100;
int hp = 95;
int maxMp = 100;
int mp = 85;
for(; ; )
{
Console.WriteLine("name : {0}", heroName);
Console.WriteLine("hp : {0}/{1}", hp, maxHp);
Console.WriteLine("name : {0}/{1}", mp, maxMp);
Console.WriteLine("0: 체력물약 , 1: 마나물약");
Console.Write("사용할 아이템을 입력하세요. ");
string strInput = Console.ReadLine();
int input = int.Parse(strInput);
ePortion portion = (ePortion)input;
Console.WriteLine("----------------------------");
switch(portion)
{
case ePortion.HpPortion:
Console.WriteLine("체력물약을 사용했습니다.");
hp++;
break;
case ePortion.MpPortion:
Console.WriteLine("마나물약을 사용했습니다.");
mp++;
break;
}
}
}
}
|