<오우거잡이>수정본

C#/과제 2019. 3. 25. 23:01
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
using System;
 
using System.Collections.Generic;
 
using System.Linq;
 
using System.Text;
 
using System.Threading.Tasks;
 
 
 
namespace _20190322
 
{
 
    class Test
 
    {
 
        public Test()//c# Test 클래스의 생성자
 
        {
 
            Console.ForegroundColor = ConsoleColor.White;
 
            //몬스터 이름은 오우거입니다.
 
            string monsterName = "오우거";
 
            Console.WriteLine("몬스터의 이름은{0}입니다.", monsterName);
 
 
 
            //몬스터의 체력은 123 입니다.
 
            int monsterMaxHp = 123;
 
            int monsterHp = monsterMaxHp;
 
            Console.WriteLine("몬스터의 체력은 ({0}/{1})입니다.", monsterHp, monsterMaxHp);
 
 
 
            //몬스터는 사납고 무섭습니다.
 
            string monsterCharcter1 = "사나움";
 
            string monsterCharcter2 = "무서움";
 
            Console.WriteLine($"몬스터의 특성은 {monsterCharcter1}, {monsterCharcter2}입니다.\n");
 
            //용사의 이름은 홍길동 입니다.
 
            string heroName = "홍길동";
 
            Console.WriteLine("용사의 이름은 " + heroName + "입니다.");
 
            //용사의 체력은 80입니다.
 
            int heroMaxHp = 80;
 
            int heroHp = heroMaxHp;
 
            Console.WriteLine("용사의 체력은 ({0}/{1})입니다.", heroHp, heroMaxHp);
 
            //용사의 공격력은 4입니다.
 
            int heroAttackDamage = 4;
 
            Console.WriteLine($"용사의 공격력은 {heroAttackDamage}입니다.\n");
 
 
 
            //공격하시겠습니까?
 
            for (int i = 1true;)
 
            {
 
 
 
                
 
                Console.Write("공격하시겠습니까?(y/n):");
 
                var inputAgainAttack = Console.ReadKey();
 
                if (inputAgainAttack.Key == ConsoleKey.N)
 
                {
 
                    Console.WriteLine("몬스터가 도망갔습니다.");
 
                    Console.ReadKey();
 
                    break;
 
                }
 
                else if (inputAgainAttack.Key == ConsoleKey.Y)
 
                {
 
                    int multipleAttackChance;
 
                    Console.Write("몇회 공격하시겠습니까?:");
 
                    multipleAttackChance = int.Parse(Console.ReadLine());
 
 
 
                    for (int j = 1; j <= multipleAttackChance; j++, i++)
 
                    {
 
                        //용사가 몬스터를 공격했습니다.
 
                        Console.WriteLine("용사가 {0}을 공격했습니다.[{1}회]", monsterName,i);
 
                        //몬스터의 체력은 119입니다.(119/123형식으로 표시)
 
                        monsterHp = monsterHp - heroAttackDamage;
 
                        System.Threading.Thread.Sleep(1000);
 
 
 
                        Console.ForegroundColor = ConsoleColor.Red;
 
                        Console.WriteLine("{0}이(가) {1}의 피해를 받았습니다!!", monsterName, heroAttackDamage);
 
                        Console.ForegroundColor = ConsoleColor.White;
 
 
 
                        if (monsterHp <= 0)
 
                        {
 
                            Console.WriteLine("몬스터의 체력은 0/{0}입니다.\n",monsterMaxHp);
 
                            Console.WriteLine("몬스터가 죽었습니다.");
 
                            break;
 
                        }
 
                        else
 
                        {
 
                            Console.WriteLine("몬스터의 체력은 ({0}/{1})입니다.\n",monsterHp,monsterMaxHp);
 
                            System.Threading.Thread.Sleep(1000);
 
                        }
 
                    }
 
 
 
                }
 
                else
 
                {
 
                    Console.WriteLine("잘못된 입력 입니다.");
 
                }
 
                if (monsterHp <= 0)
 
                {
 
                    Console.ReadKey();
 
                    break;
 
                }
 
            }
 
        }
 
    }
 
}
 
 
cs


: