(3.25) 몬스터 공격하기 ver.수정
C#/과제2019. 3. 26. 01:56
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace study_01 { class Test { public Test() { string monsterName = "오우거"; int monsterHp = 123; int monsterMaxhp = 123; string heroName = "홍길동"; int heroHp = 80; int heroAttackdamage = 4; Console.WriteLine("몬스터의 이름 : {0}입니다", monsterName); Console.WriteLine("몬스터의 체력은 : {0}/{1} 입니다", monsterHp, monsterMaxhp); Console.WriteLine("몬스터는 사납고 무섭습니다. \n"); Console.WriteLine($"용사의 이름 : {heroName}입니다"); Console.WriteLine($"용사의 체력 : {heroHp}입니다"); Console.WriteLine($"용사의 공격력 : {heroAttackdamage}입니다 \n"); Console.WriteLine("용사가 몬스터를 공격했습니다."); Console.WriteLine($"몬스터는 {heroAttackdamage}데미지를 받았습니다."); Console.WriteLine("몬스터의 체력은 {0}/{1}입니다 \n", monsterHp - heroAttackdamage, monsterMaxhp); Console.WriteLine("공격을 더 하시겠습니까? ( Y / N ) \n"); while (true) { ConsoleKeyInfo inputkey = Console.ReadKey(); if (inputkey.Key == ConsoleKey.Y) { Console.Clear(); Thread.Sleep(1000); Console.Clear(); monsterHp -= heroAttackdamage ; Console.BackgroundColor = ConsoleColor.DarkRed; Console.WriteLine("\n 몬스터는 {0}의 피해를 받았습니다.", heroAttackdamage); Console.ResetColor(); if (monsterHp <= 0) { Console.WriteLine("\n몬스터를 처치하였습니다."); break; } Console.WriteLine("몬스터의 체력은 {0}", monsterHp); continue; } else if (inputkey.Key == ConsoleKey.N) { Console.Clear(); Console.WriteLine("\n용사가 도망쳤습니다. \n"); break; } else if (inputkey.Key != ConsoleKey.Y && inputkey.Key != ConsoleKey.N) { Console.Clear(); Console.WriteLine("\n잘못 누르셨습니다."); } } } } } | cs |
'C# > 과제' 카테고리의 다른 글
//미완// Collection[컬렉션] (0) | 2019.03.31 |
---|---|
Boxing 및 Unboxing (0) | 2019.03.29 |
Stack 과 Heap (0) | 2019.03.25 |
몬스터 처치하기 (0) | 2019.03.25 |
(3.22)값 형식 (0) | 2019.03.25 |