장검 착용 해제 코드 입니다. 코드를 긁어 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
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
|
//Enum열거형 예제 아이템 착용 해제.
bool isEquiped = false;
bool isDroped = false;
string inventory = "장검";
string equipedItem = "";
while (true)
{
Console.WriteLine("\n----------------\n소지중인 아이템 : {0} ||||| 착용중인 아이템 : {1}\n", inventory, equipedItem);
Console.WriteLine("\"아이템명 착용\", \"아이템명 해제\", \"아이템명 드랍\", \"아이템명 획득\"\n");
Console.Write("명령어를 입력 해주세요. ");
string[] splitedCommand = Console.ReadLine().Split(' ');
string targetItem = splitedCommand[0];
string targetCommand = splitedCommand[1];
{
Console.WriteLine("입력값이 잘못 됐습니다.");
continue;
}
Console.Write("\n실행 결과 ======> ");
if(targetItem == "장검")
{
//획득
if(targetCommand == "획득")
{
if (isDroped)
{
isDroped = false;
Console.WriteLine("{0}을 획득 했습니다.", targetItem);
inventory += targetItem;
}
else
{
Console.WriteLine("{0}이 이미 있습니다.", targetItem);
}
}
//없는 무기일 경우
else if (isDroped)
{
Console.WriteLine("{0}이 없습니다.", targetItem);
continue;
}
else if(targetCommand == "드랍")
{
if (!isDroped)
{
Console.WriteLine("{0}이 드랍되었습니다.", targetItem);
isDroped = true;
isEquiped = false;
inventory = "";
equipedItem = "";
}
}
//착용
else if (targetCommand == "착용")
{
if (isEquiped)
Console.WriteLine("이미 {0}은 착용되었습니다. ", targetItem);
else
{
Console.WriteLine("{0}을 착용했습니다. ", targetItem);
isEquiped = true;
equipedItem = targetItem;
}
}
//해제
else if (targetCommand == "해제")
{
if (isEquiped)
{
isEquiped = false;
Console.WriteLine("{0}을 해제 했습니다.", targetItem);
equipedItem = "";
}
else
{
Console.WriteLine("{0}을 해제 할 수 없습니다. ", targetItem);
}
}
else
{
Console.WriteLine("{0}을 할 수 없습니다.", targetItem);
}
}
else
{
Console.WriteLine("없는 아이템 입니다.");
}
}
|
Study_009 - 1 유닛, 배럭, 아카데미 (0) | 2020.04.14 |
---|---|
Study_008 클래스 예제 (0) | 2020.04.13 |
Study_005 (0) | 2020.04.08 |
Study004 (0) | 2020.04.08 |
Study003-01 (0) | 2020.04.06 |