실행코드
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace study_006
{
class App
{
enum weaponType
{
Sword, Bow, Axe
}
public App()
{
//Console.WriteLine("2020.04.09");
//소지중인 아이템 : Sword, Axe 출력하기
Console.WriteLine("소지중인 아이템 : Sword, Axe");
while (true)
{
//강화하시려는 무기의 이름을 입력해주세요. 출력 후 물어보기
Console.Write("강화하시려는 무기의 이름을 입력해주세요. ");
var inputWeapon = Console.ReadLine();
switch (Weapon)
{ //만약에 강화 할 무기로 Sword를 입력한다면
case weaponType.Sword:
//강화하시려면 "강화"를 입력해주세요. 출력 후 물어보기
Console.Write("강화하시려면 \"강화\"를 입력해주세요.");
string input = Console.ReadLine();
//(강화 확률은 Sword : 30%, Bow : 25%, Axe : 20% 입니다) 출력
//만약에 강화를 입력한다면 확률은 30% 랜덤 설정해주기
switch (input)
{
case "강화":
Console.WriteLine("(강화 확률은 Sword : 30%, Bow : 25%, Axe : 20% 입니다)");
var rand = new Random();
if (consolidationPer <= 30)
{
Console.WriteLine("아이템 (Sword) 강화에 성공했습니다.");
Console.WriteLine("소지중인 아이템 : {0}(+1),Axe", Weapon);
}
else
{
Console.WriteLine("아이템 (Sword) 강화에 실패했습니다.");
Console.WriteLine("소지중인 아이템 : {0},Axe", Weapon);
continue;
}
break;
default:
Console.WriteLine("잘못된 명령어입니다.");
continue;
}
break;
case weaponType.Axe:
//강화하시려면 "강화"를 입력해주세요. 출력 후 물어보기
Console.Write("강화하시려면 \"강화\"를 입력해주세요.");
string input1 = Console.ReadLine();
//(강화 확률은 Sword : 30%, Bow : 25%, Axe : 20% 입니다) 출력
//만약에 강화를 입력한다면 확률은 30% 랜덤 설정해주기
switch (input1)
{
case "강화":
Console.WriteLine("(강화 확률은 Sword : 30%, Bow : 25%, Axe : 20% 입니다)");
var rand = new Random();
if (consolidationPer <= 20)
{
Console.WriteLine("아이템 {0} 강화에 성공했습니다.", Weapon);
Console.WriteLine("소지중인 아이템 : Sword, {0}(+1)", Weapon);
}
else
{
Console.WriteLine("아이템 {0} 강화에 실패했습니다.", Weapon);
Console.WriteLine("소지중인 아이템 : Sword, {0}", Weapon);
continue;
}
break;
default:
Console.WriteLine("잘못된 명령어입니다.");
continue;
}
break;
default:
Console.WriteLine("입력하신 무기는 소지하고 있지않습니다.");
continue;
}
break;
}
|
실행창
'c# > 수업내용' 카테고리의 다른 글
2020.04.22 json파일 역직렬화, 직렬화 Achievement (0) | 2020.04.22 |
---|---|
2020.04.13 if문 사용 Starcraft (0) | 2020.04.13 |
줄넘기 몇회 하시겠습니까? - while문 for문 if문 사용 (0) | 2020.04.08 |
2020.04.03 연산자, for문 기본개념 (0) | 2020.04.03 |
2020.04.03 for문 출력 (0) | 2020.04.03 |