<과제>오우거잡기(3단계완성)

C#/과제 2019. 3. 22. 19:07
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_00
{
    class Test
    {
        public Test()//c# Test 클래스의 생성자
        {
            Console.ForegroundColor = ConsoleColor.White;
            //몬스터 이름은 오우거입니다.
            string monster_name = "오우거";
            Console.WriteLine("몬스터의 이름은 " + monster_name + "입니다.");
 
            //몬스터의 체력은 123 입니다.
            int monster_hpmax = 123;
            int monster_hp = monster_hpmax;
            Console.WriteLine("몬스터의 체력은 " + monster_hp + "/" + monster_hpmax + "입니다.");
 
            //몬스터는 사납고 무섭습니다.
            string monster_character1 = "사나움";
            string monster_character2 = "무서움";
            Console.WriteLine("몬스터의 특성은 " + monster_character1 + ", " + monster_character2 + "입니다.\n");
            //용사의 이름은 홍길동 입니다.
            string warrior_name = "홍길동";
            Console.WriteLine("용사의 이름은 " + warrior_name + "입니다.");
            //용사의 체력은 80입니다.
            int warrior_hpmax = 80;
            int warrior_hp = warrior_hpmax;
            Console.WriteLine("용사의 체력은 " + warrior_hp + "/" + warrior_hpmax + "입니다.");
            //용사의 공격력은 4입니다.
            int warrior_damage = 4;
            Console.WriteLine("용사의 공격력은 " + warrior_damage + "입니다.\n");
 
 
 
            //공격하시겠습니까?
 
            for (int i = 1true;)
            {
                string choice;
                int nof;
                Console.Write("공격하시겠습니까?(y/n):");
                choice = Console.ReadLine();
                if (choice != "y")
                {
                    Console.WriteLine("몬스터가 도망갔습니다.");
                    Console.ReadKey();
                    break;
                }
 
 
 
                Console.Write("몇회 공격하시겠습니까?:");
                nof = int.Parse(Console.ReadLine());
 
                for (int j = 1; j <= nof; j++, i++)
                {
                    //용사가 몬스터를 공격했습니다.
                    Console.WriteLine("용사가 " + monster_name + "을 공격했습니다.[" + i + "회]");
                    //몬스터의 체력은 119입니다.(119/123형식으로 표시)
                    monster_hp = monster_hp - warrior_damage;
                    System.Threading.Thread.Sleep(1000);
 
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(monster_name + "가 " + warrior_damage + "의 피해를 받았습니다!!");
                    Console.ForegroundColor = ConsoleColor.White;
                    
 
                    if (monster_hp <= 0)
                    {
                        
                        Console.WriteLine("몬스터의 체력은 " + "(0" + "/" + monster_hpmax + ")입니다.\n");
                        Console.WriteLine("몬스터가 죽었습니다.");
                        break;
                    }
                    else
                    {
 
                        Console.WriteLine("몬스터의 체력은 (" + monster_hp + "/" + monster_hpmax + ")입니다.\n");
                        System.Threading.Thread.Sleep(1000);
                    }
                    
 
                }
                if (monster_hp <= 0)
                {
                    Console.ReadKey();
                    break;
                }
                
 
            }
 
 
 
        }
        
    }
}
 
 
cs


: