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;
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
|
'C# > 실습' 카테고리의 다른 글
09.23 상점 구매하기 및 판매하기 (0) | 2019.09.23 |
---|---|
09.20 줄넘기 (0) | 2019.09.20 |
09.20 과일입력, 숫자입력, 문자열에 따옴표입력 (0) | 2019.09.20 |
구구단 (convert를 이용한 string형식을 int 형식으로 변환, tryparse를 이용한 문자와 숫자 구분) (0) | 2019.09.19 |
2019/09/19 for 루프 (1) | 2019.09.19 |