using System.Security.Cryptography.X509Certificates;
using System.Transactions;
using static CSharp.Program;
namespace CSharp
{
class Program
{
public enum ClassType
{
NONE,기사,궁수,마법사
}
struct Player
{
public int hp;
public int attack;
public int exp;
}
enum MonsterType
{
NONE,
Slime,
Orc,
Skeleton
}
struct Monster
{
public int hp;
public int attack;
}
static ClassType ChoiceJob()
{
ClassType classType = ClassType.NONE;
Console.WriteLine("직업을 선택하세요!");
Console.WriteLine("[1] 기사");
Console.WriteLine("[2] 궁수");
Console.WriteLine("[3] 법사");
string job = Console.ReadLine();
switch (job)
{
case "1":
classType = ClassType.기사;
Console.WriteLine("기사를 선택하셨습니다.");
break;
case "2":
classType = ClassType.궁수;
Console.WriteLine("궁수를 선택하셨습니다.");
break;
case "3":
classType = ClassType.마법사;
Console.WriteLine("마법사 선택하셨습니다.");
break;
default:
Console.WriteLine("잘못 입력하였습니다.");
break;
}
return classType;
}
static void CreateCharacter(ClassType classType, out Player player)
{
switch (classType)
{
case ClassType.기사:
player.hp = 100;
player.attack = 10;
player.exp = 0;
break;
case ClassType.궁수:
player.hp = 75;
player.attack = 12;
player.exp = 0;
break;
case ClassType.마법사:
player.hp = 50;
player.attack = 15;
player.exp = 0;
break;
default:
player.hp = 0;
player.attack = 0;
player.exp = 0;
break;
}
}
static void CreateRandomMonster(out Monster monster)
{
Random rand = new Random();
int randomMonster = rand.Next(1, 4);
switch (randomMonster)
{
case (int)MonsterType.Slime:
Console.WriteLine("슬라임이 스폰되었습니다.");
monster.hp = 20;
monster.attack = 2;
break;
case (int)MonsterType.Orc:
Console.WriteLine("오크가 스폰되었습니다.");
monster.hp = 20;
monster.attack = 2;
break;
case (int)MonsterType.Skeleton:
Console.WriteLine("스켈레톤이 스폰되었습니다.");
monster.hp = 20;
monster.attack = 2;
break;
default:
monster.hp = 0;
monster.attack = 0;
break;
}
}
static void Fight(ref Player player, ref Monster monster)
{
while (true)
{
//플레이어가 몬스터 공격
monster.hp -= player.attack;
if (monster.hp <= 0)
{
Console.WriteLine("승리했습니다!");
Console.WriteLine($"남은 체력 : {player.hp}");
break;
}
//몬스터 반격
player.hp -= monster.attack;
if (player.hp <= 0)
{
Console.WriteLine("패배했습니다!");
break;
}
}
}
static void EnterField(Player player)
{
while(true)
{
Console.WriteLine("필드에 접속했습니다.");
Monster monster;
CreateRandomMonster(out monster);
Console.WriteLine("[1] 전투 모드로 돌입");
Console.WriteLine("[2] 일정 확률로 마을로 도망");
string input = Console.ReadLine();
if (input == "1")
{
Fight(ref player, ref monster);
}
else if(input == "2")
{
//33%
Random rand = new Random();
int randValue = rand.Next(0, 101);
if (randValue <= 33)
{
Console.WriteLine("도망치는데 성공했습니다.");
break;
}
else
{
Fight(ref player, ref monster);
break;
}
}
}
}
static void EnterGame(ref Player player)
{
while (true)
{
Console.WriteLine("마을에 접속했습니다.");
Console.WriteLine("[1] 필드로 간다.");
Console.WriteLine("[2] 로비로 돌아가기.");
string input = Console.ReadLine();
if (input == "1")
{
EnterField(player);
}
else if(input == "2")
{
break;
}
}
}
static void Main(string[] args)
{
while (true)
{
//직업 선택
ClassType classChoice = ChoiceJob();
if (classChoice == ClassType.NONE)
continue;
Player player;
//기사 (100/10) 궁수(75/12) 법사 (50/15)
CreateCharacter(classChoice, out player);
Console.WriteLine($"체력:{player.hp}\n공격력:{player.attack}");
EnterGame(ref player);
}
}
}
}
C#
텍스트 알피지!!
728x90
반응형
반응형