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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
namespace Study_004
{
class App
{
public App()
{
Console.WriteLine("2020-04-07\n\n======================================================\n");
/*
//영웅 공격 예제.
int attackPoint = 0;
bool parseable = false;
int minAttackPoint = 1;
int maxAttackPoint = 5;
float maxMonsterHp = 20f;
float minMonsterHp = 10f;
float remainMonsterHp = 0f;
string[] itemDropList = { "장검", "단검", "도끼", "철퇴" };
Random rand = new Random(DateTime.Now.Millisecond);
for(; ; )
{
//영웅의 공격력 받는 부분.
Console.Write("영웅의 공격력은 몇입니까? ({0} / {1}) ", minAttackPoint, maxAttackPoint);
parseable = int.TryParse(Console.ReadLine(), out attackPoint);
if (attackPoint >= minAttackPoint && attackPoint <= maxAttackPoint)
{
Console.WriteLine("영웅의 공격력은 {0} 입니다.\n", attackPoint);
break;
}
else
Console.WriteLine("범위를 벗어났습니다.\n");
}
for(; ; )
{
//몬스터 체력 받는 부분.
Console.WriteLine("몬스터의 체력은 몇입니까? ({0} / {1}) ", minMonsterHp, maxMonsterHp);
parseable = float.TryParse(Console.ReadLine(), out remainMonsterHp);
if (remainMonsterHp >= minMonsterHp && remainMonsterHp <= maxMonsterHp)
{
maxMonsterHp = remainMonsterHp;
Console.WriteLine("몬스터의 체력은 {0} 입니다.\n", remainMonsterHp);
break;
}
else
Console.WriteLine("범위를 벗어났습니다.\n");
}
for(; ; )
{
//공격 하는 부분.
Console.Write("몬스터를 공격 하시려면 '공격'을 입력하세요. ");
if (Console.ReadLine() == "공격")
{
float attackBuff = (rand.NextDouble() > 0.5) ? 1.1f * attackPoint : 1.0f * attackPoint;
remainMonsterHp -= attackBuff;
if (remainMonsterHp <= 0)
{
remainMonsterHp = 0;
if (attackBuff > (float)attackPoint)
Console.WriteLine("몬스터를 쎄게 공격({0}) 했습니다. ({1:F2}, {2})", attackBuff, remainMonsterHp, maxMonsterHp);
else
Console.WriteLine("몬스터를 공격({0}) 했습니다. ({1:F2}, {2})", attackBuff, remainMonsterHp, maxMonsterHp);
Console.WriteLine("몬스터가 쓰러졌습니다.\n");
break;
}
else
{
if (attackBuff > (float)attackPoint)
Console.WriteLine("몬스터를 쎄게 공격({0}) 했습니다. ({1:F2}, {2})", attackBuff, remainMonsterHp, maxMonsterHp);
else
Console.WriteLine("몬스터를 공격({0}) 했습니다. ({1:F2}, {2})", attackBuff, remainMonsterHp, maxMonsterHp);
}
}
else
Console.WriteLine("잘못된 명령어 입니다.");
}
string dropItem = itemDropList[rand.Next(itemDropList.Length)];
for (; ; )
{
Console.WriteLine("몬스터가 아이템({0})을 떨어트렸습니다. ", dropItem);
Console.WriteLine("아이템을 획득하시려면 '{0} 집어'를 입력하세요. ", dropItem);
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine("잘못된 명령어 입니다.\n");
else if ("집어" != input[1].Trim())
Console.WriteLine("잘못된 명령어 입니다.\n");
else if (dropItem != input[0].Trim())
Console.WriteLine("'{0}'이라는 아이템은 없습니다.\n", input[0]);
else
{
Console.WriteLine("{0}을 획득했습니다.\n", dropItem);
break;
}
}
*/
/*
//줄넘기 while문 예제.
Console.Write("줄넘기를 몇 회 하시겠습니까? : ");
int maxCount = int.Parse(Console.ReadLine());
int count = 1;
while(count <= maxCount && maxCount > 0)
Console.WriteLine("줄넘기를 {0}회 했습니다.", count++);
Console.WriteLine("줄넘기를 마쳤습니다.");
*/
/*
//구구단 출력.
int dan = 0;
int count = 1;
while (dan != -1)
{
Console.Write("출력하고 싶은 구구단의 단수를 입력 하세요. ");
while (count < 10 && dan != -1)
{
Console.WriteLine("{0} X {1} = {2}", dan, count, dan * count);
count++;
}
count = 1;
Console.WriteLine();
}
Console.WriteLine("구구단 프로그램을 종료합니다. ");
*/
/*
//While문 구구단 여러개 입력
while (true)
{
Console.Write("출력하고 싶은 구구단의 단수를 입력 하세요 (최대 3개)");
string input = Console.ReadLine();
if (input == "-1")
{
Console.WriteLine("구구단 프로그램을 종료합니다.");
break;
}
string[] splitString = input.Split(',');
int count = 1;
int index = 0;
while(index < splitString.Length)
{
while(count < 10)
{
Console.WriteLine("{0}X{1}={2}", int.Parse(splitString[index]), count, int.Parse(splitString[index]) * count);
count++;
}
count = 1;
index++;
Console.WriteLine();
}
}
*/
/*
//while문 영웅 게임.
int heroDamage = 0;
int minDamage = 1;
int maxDamage = 5;
Console.Write("영웅의 공격력은 몇입니까 ({0} ~ {1}). ", minDamage, maxDamage);
while (!int.TryParse(Console.ReadLine(), out heroDamage) || heroDamage < minDamage || heroDamage > maxDamage)
{
Console.WriteLine("범위를 벗어났습니다.");
Console.Write("영웅의 공격력은 몇입니까 ({0} ~ {1}). ", minDamage, maxDamage);
}
Console.WriteLine("영웅의 공격력은 {0}입니다.", heroDamage);
*/
/*
//Idle 프레임 while
Console.Write("실행할 애니메이션의 이름을 적으세요. ");
string animationName = Console.ReadLine();
int totalFrame = 0;
int minFrame = 6;
int maxFrame = 30;
while (true)
{
Console.Write("애니메이션의 total 프레임은 몇 프레임 입니까 (6 ~ 30)? ");
totalFrame = int.Parse(Console.ReadLine());
if (totalFrame <= maxFrame && totalFrame >= minFrame)
break;
Console.WriteLine("범위가 잘못됐습니다.");
}
while (true)
{
Console.Write("애니메이션을 실행하시려면 'Play' 라고 입력하세요. ");
if (Console.ReadLine() == "Play")
break;
Console.WriteLine("잘못 입력되었습니다.");
}
Console.WriteLine("");
int count = 0;
while (count < totalFrame)
Console.WriteLine("{0} {1}프레임을 실행.", animationName, ++count);
Console.WriteLine("\nIdle 애니메이션 실행을 완료 했습니다.");
*/
/*
//애니메이션 프레임2
Console.Write("애니메이션의 이름 : ");
string animationName = Console.ReadLine();
Console.WriteLine("");
int minFrame = 1;
int totalFrame = 0;
int curFrame = 0;
int attackFrame = 0;
while (true)
{
Console.Write("{0} 애니메이션의 total Frame은 몇입니까?. ", animationName);
totalFrame = int.Parse(Console.ReadLine());
if (totalFrame < minFrame)
Console.WriteLine("범위값이 잘못되었습니다. ");
else
break;
}
while (true)
{
Console.Write("{0} 애니메이션의 타격 Frame은 몇입니까?. ", animationName);
attackFrame = int.Parse(Console.ReadLine());
if (attackFrame < totalFrame && attackFrame > 0)
break;
else
Console.WriteLine("범위값이 잘못되었습니다. ");
}
Console.Write("{0} 애니메이션의 타격 프레임때 쓸 이펙트 효과는? . ", animationName);
string attackEffect = Console.ReadLine();
while (true)
{
Console.Write("애니메이션을 실행하시려면 Play를 입력 하세요. ");
string input = Console.ReadLine();
if (input == "Play")
break;
else
Console.WriteLine("입력이 잘못됐습니다. ");
}
Console.WriteLine("");
while (curFrame < totalFrame)
{
curFrame++;
if (curFrame == attackFrame)
Console.WriteLine(attackEffect);
else
Console.WriteLine("{0} {1} frame", animationName, curFrame);
}
Console.WriteLine("\n{0} 애니메이션 플레이를 완료 했습니다.", animationName);
*/
//while문 연습3
int curFrame = 0;
Console.Write("공격 애니메이션 1 : ");
string attackAnimation1 = Console.ReadLine();
Console.Write("공격 애니메이션 1 total Frame : ");
int attackTotalFrame1 = int.Parse(Console.ReadLine());
Console.Write("공격 애니메이션 1 타격 프레임 : ");
int attackFrame1 = int.Parse(Console.ReadLine());
Console.Write("공격 애니메이션 1 효과 : ");
string attackEffect1 = Console.ReadLine();
Console.WriteLine("");
Console.Write("공격 애니메이션 2 : ");
string attackAnimation2 = Console.ReadLine();
Console.Write("공격 애니메이션 2 total Frame : ");
int attackTotalFrame2 = int.Parse(Console.ReadLine());
Console.Write("공격 애니메이션 2 타격 프레임 : ");
int attackFrame2 = int.Parse(Console.ReadLine());
Console.Write("공격 애니메이션 2 효과 : ");
string attackEffect2 = Console.ReadLine();
Console.WriteLine("");
Console.Write("기본 애니메이션 : ");
string baseAnimationName = Console.ReadLine();
Console.Write("기본 애니메이션 total 프레임 : ");
int baseAnimationTotalFrame = int.Parse(Console.ReadLine());
Console.WriteLine("");
while (true)
{
Console.Write("Play 입력 : ");
if (Console.ReadLine() == "Play")
break;
else
Console.WriteLine("입력값이 잘못됐습니다.");
}
Console.WriteLine("");
while (curFrame < attackTotalFrame1)
{
curFrame++;
if (attackFrame1 == curFrame)
Console.WriteLine("{0}", attackEffect1);
else
{
Console.WriteLine("{0} {1} frame", attackAnimation1, curFrame);
}
}
curFrame = 0;
Console.WriteLine("");
while (curFrame < attackTotalFrame2)
{
curFrame++;
if (attackFrame2 == curFrame)
Console.WriteLine("{0}", attackEffect2);
else
{
Console.WriteLine("{0} {1} frame", attackAnimation2, curFrame);
}
}
curFrame = 0;
Console.WriteLine("");
while (curFrame < baseAnimationTotalFrame)
{
curFrame++;
Console.WriteLine("{0} {1} frame", baseAnimationName, curFrame);
}
Console.WriteLine("애니메이션 종료");
}
}
}
|
연습한 while문 예제 입니다. 주석을 하나씩 풀며 해봐야 합니다. 특별한 점은 없었습니다.
Study_006-1 (0) | 2020.04.09 |
---|---|
Study_005 (0) | 2020.04.08 |
Study003-01 (0) | 2020.04.06 |
Study_002-2 (0) | 2020.04.03 |
Study_002-1 (0) | 2020.04.03 |