-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
339 lines (314 loc) · 16.1 KB
/
Program.cs
File metadata and controls
339 lines (314 loc) · 16.1 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
namespace TextAdventure
{
internal class Program
{
public class Player
{
public virtual string Name { get; set; }//이름
public int Level { get; set; }//레벨
public string Chad { get; set; }//직업
public virtual int AttackPower { get; set; }//공격력
public virtual int Defense{ get; set; }//방어력
public virtual int Health { get; set; }//체력
public virtual int Gold { get; set; }//골드
public void PrintInfo()
{
Console.WriteLine("이름:" + Name);
Console.WriteLine("Lv." + Level);
Console.WriteLine("Chad(" + Chad+")");
Console.WriteLine("공격력:" + AttackPower);
Console.WriteLine("방어력:" + Defense);
Console.WriteLine("체력:" + Health);
Console.WriteLine("Gold:" + Gold+ "G");
}
}
public class Item
{
public int ItemIndex { get; set; }
public string Name { get; set; }
public string StatName { get; set; }
public int Stat { get; set; }
public string Manual { get; set; }
public int Gold { get; set; }
public string CheckItem { get; set; }
public string CheckBuyItem { get; set; }
public void MakeItem(int index,string name,string statName,int stat,string manual,int gold)
{
ItemIndex = index;
Name = name;
StatName = statName;
Stat = stat;
Manual = manual;
Gold = gold;
}
public void HaveItem()
{
CheckItem = "[E]";
}
public void UnItem()
{
CheckItem = null;
}
public void Unbuy()
{
CheckBuyItem = $"{Gold} G";
}
public void Buy()
{
CheckBuyItem = "구매완료";
}
public void ItemStats()
{
Console.WriteLine($"-{CheckItem}{ItemIndex+1} {Name} |{StatName}+{Stat} | {Manual} ");
}
public void ShopItem()
{
Console.WriteLine($"-{Name} |{StatName}+{Stat} | {Manual} | {CheckBuyItem} ");
}
public void BuyItem()
{
Console.WriteLine($"-{ItemIndex + 1} {Name} |{StatName}+{Stat} | {Manual} | {CheckBuyItem}");
}
}
public static List<Item> items = new List<Item>();
static void StartText()
{
Console.WriteLine("스파르타 마을에 오신 여러분 환영합니다");
Console.WriteLine("이곳에서 던전으로 들어가기전 활동을 할 수 있습니다.");
Console.WriteLine("\n1.상태 보기");
Console.WriteLine("2.인벤토리");
Console.WriteLine("3.상점");
}
static void Exit(int outNumber)
{
Console.WriteLine("\n0.나가기");
Console.WriteLine("\n원하시는 행동을 입력해주세요.\n>>");
while (outNumber != 0)
{
outNumber = int.Parse(Console.ReadLine());
if (outNumber != 0)
{
Console.WriteLine("잘못된 숫자를 입력했습니다. 다시 입력해주세요");
}
}
}
static void Main(string[] args)
{
Player player = new Player(); //불러와서 정보를 입력한 것
Item item1 = new Item();
Item item2= new Item();
item1.MakeItem(0,"무쇠갑옷","방어력",5,"무쇠로 만들어져 튼튼한 갑옷입니다.",1000);
item2.MakeItem(1, "스파르타의 창", "공격력", 7, "스파르타의 전사들이 사용했다는 전설의 창입니다", 800);
items.Add(item1);
items.Add(item2);
player.Level = 1;
player.Chad = "전사";
player.AttackPower = 10;
player.Defense = 5;
player.Health = 100;
player.Gold = 2000;
Console.WriteLine("플레이어의 이름을 입력하세요");
player.Name = Console.ReadLine();
int inputNumber; //진행 숫자
while (true)
{
StartText();
Console.WriteLine("\n원하시는 행동을 입력해주세요.\n>>");
inputNumber = int.Parse(Console.ReadLine());
switch (inputNumber)
{
case 1:
Console.WriteLine("상태보기입니다!");
player.PrintInfo();
Exit(inputNumber);
break;
case 2:
while (inputNumber != 0) {
Console.WriteLine("인벤토리입니다\n보유 중인 아이템을 관리할 수 있습니다.");
Console.WriteLine("\n[아이템 목록]");
foreach (Item item in items)
{
item.ItemStats();
}
Console.WriteLine("\n1.장착관리");
Console.WriteLine("\n0.나가기");
Console.WriteLine("\n원하시는 행동을 입력해주세요.\n>>");
inputNumber = int.Parse(Console.ReadLine());
if(inputNumber==1)
{
while (inputNumber != 0)
{
Console.WriteLine("인벤토리입니다\n보유 중인 아이템을 관리할 수 있습니다.");
Console.WriteLine("\n[아이템 목록]");
foreach (Item item in items)
{
item.ItemStats();
}
Console.WriteLine("\n0.나가기");
Console.WriteLine("\n원하시는 행동을 입력해주세요.\n>>");
inputNumber = int.Parse(Console.ReadLine());
if (inputNumber == item1.ItemIndex+1)
{
if(item1.CheckItem==null)
{
item1.HaveItem();
player.Defense += item1.Stat;
}
else
{
item1.UnItem();
player.Defense -= item1.Stat;
}
}
else if(inputNumber==item2.ItemIndex+1)
{
if (item2.CheckItem == null)
{
item2.HaveItem();
player.AttackPower += item2.Stat;
}
else
{
item2.UnItem();
player.AttackPower -= item2.Stat;
}
}
else if (inputNumber != 0)
{
Console.WriteLine("잘못된 숫자를 입력했습니다. 다시 입력해주세요");
}
}
}
else if (inputNumber != 0)
{
Console.WriteLine("잘못된 숫자를 입력했습니다. 다시 입력해주세요");
}
}
break;
case 3:
List<Item> itemShop = new List<Item>();
Item item3 = new Item(); Item item4 = new Item(); Item item5 = new Item(); Item item6 = new Item();
item3.MakeItem(2, "수련자 갑옷", "방어력", 3, "수련에 도음을 주는 갑옷입니다.", 500);
item4.MakeItem(3, "스파르타의 갑옷", "방어력", 10, "스파트라의 전사들이 사용했다는 전설의 갑옷입니다.", 3000);
item5.MakeItem(4, "낡은검", "공격력", 2, "쉽게 볼 수 있는 낡은 검 입니다.", 500);
item6.MakeItem(5, "청동 도끼", "공격력", 5, "어디선가 사용됐던거 같은도끼입니다. ", 1500);
item1.Buy();
item2.Buy();
item3.Unbuy();
item4.Unbuy();
item5.Unbuy();
item6.Unbuy();
itemShop.Add(item1);
itemShop.Add(item2);
itemShop.Add(item3);
itemShop.Add(item4);
itemShop.Add(item5);
itemShop.Add(item6);
while (inputNumber != 0)
{
Console.WriteLine("상점입니다! 필요한 아이템을 구매하세요\n");
Console.WriteLine("[보유 골드]");
Console.WriteLine($"{player.Gold} G");
Console.WriteLine("\n[아이템 목록]");
foreach (Item item in itemShop)
{
item.ShopItem();
}
Console.WriteLine("\n1.아이템 구매");
Console.WriteLine("0.나가기");
inputNumber = int.Parse(Console.ReadLine());
if (inputNumber == 1)
{
while(inputNumber !=0)
{
Console.WriteLine("상점입니다! 필요한 아이템을 구매하세요\n");
Console.WriteLine("[보유 골드]");
Console.WriteLine($"{player.Gold} G");
Console.WriteLine("\n[아이템 목록]");
foreach (Item item in itemShop)
{
item.BuyItem();
}
Console.WriteLine("0.나가기");
inputNumber = int.Parse(Console.ReadLine());
if (inputNumber == item1.ItemIndex + 1)
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
else if (inputNumber == item2.ItemIndex + 1)
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
else if (inputNumber == item3.ItemIndex +1 && player.Gold>=item3.Gold )
{
if (item3.CheckBuyItem != "구매완료")
{
item3.Buy();
player.Gold -= item3.Gold;
Console.WriteLine(("\n구매가 완료했습니다.\n"));
}
else
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
}
else if (inputNumber == item4.ItemIndex + 1 && player.Gold >= item4.Gold)
{
if (item4.CheckBuyItem != "구매완료")
{
item4.Buy();
player.Gold -= item4.Gold;
Console.WriteLine(("\n구매가 완료했습니다.\n"));
}
else
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
}
else if (inputNumber == item5.ItemIndex + 1 && player.Gold >= item5.Gold)
{
if (item5.CheckBuyItem != "구매완료")
{
item5.Buy();
player.Gold -= item5.Gold;
Console.WriteLine(("\n구매가 완료했습니다.\n"));
}
else
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
}
else if (inputNumber == item6.ItemIndex + 1 && player.Gold >= item6.Gold)
{
if (item6.CheckBuyItem != "구매완료")
{
item6.Buy();
player.Gold -= item6.Gold;
Console.WriteLine(("\n구매가 완료했습니다.\n"));
}
else
{
Console.WriteLine("\n이미 구매한 물품입니다.\n");
}
}
else
{
Console.WriteLine("\nGold 가 부족합니다\n");
}
break;
}
}
else if(inputNumber !=0)
{
Console.WriteLine("잘못입력하셨습니다");
}
}
break;
default:
Console.WriteLine("잘못입력하셨습니다");
break;
}
}
}
}
}