09.20 for문을 이용한 던전게임

C#/실습 2019. 9. 20. 11:27

예제:

코드:

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _09._20
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("케릭터의 이름을 입력해주세요: ");
            string characterName = Console.ReadLine();
            Console.Write("직업을 설정해주세요: ");
            string className = Console.ReadLine();
            Console.Write("체력을 설정해주세요: ");
            string strmaxHp = Console.ReadLine();
            int maxHp = Convert.ToInt32(strmaxHp);
            Console.Write("공격력을 설정해주세요: ");
            string strdmg = Console.ReadLine();
            int heroDamage = Convert.ToInt32(strdmg);
            float monsterDamage = 3.5f;
            float hp = maxHp;//현재 체력
            Console.WriteLine("----------------------");
            Console.WriteLine($"이름: {characterName}");
            Console.WriteLine($"직업: {className}");
            Console.WriteLine($"체력: {hp}/{maxHp}");
            Console.WriteLine($"공격력: {heroDamage}");
            Console.WriteLine("----------------------");
            Console.WriteLine("던전으로 들어갔습니다.");
            Console.WriteLine($"몬스터에게 공격(-{monsterDamage})을 받았습니다. ({hp = hp - monsterDamage}/{maxHp})");
            for (int i =1; i<4; i++)
            {
                Console.WriteLine($"몬스터에게 공격(-{monsterDamage})을 받았습니다. ({hp = hp - monsterDamage}/{maxHp})");
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
: