diff --git a/TextRPG_1/Program.cs b/TextRPG_1/Program.cs new file mode 100644 index 0000000..b322834 --- /dev/null +++ b/TextRPG_1/Program.cs @@ -0,0 +1,282 @@ +using System; + +namespace TextRPG_1 +{ + class Program + { + enum ClassType + { + None = 0, + Knight = 1, + Archer = 2, + Mage = 3 + } + + struct Player + { + public int hp; + public int attack; + } + + // ClassType, Player를 참고해 MonsterType과 Monster 구조체를 완성해보세요. + // 몬스터 종류 + // Slime -> 체력: 20 / 공격력: 2 + // Orc -> 체력: 40 / 공격력: 5 + // Skeleton -> 체력: 30 / 공격력: 7 + enum MonsterType + { + // TODO + None = 0, + Slime = 1, + Orc = 2, + Skeleton = 3 + } + + struct Monster + { + // TODO + public int hp; + public int attack; + } + + // 플레이어 직업 선택 함수 + static ClassType ChooseClass() + { + Console.WriteLine("직업을 선택하세요!"); + Console.WriteLine("[1]. 검사"); + Console.WriteLine("[2]. 궁수"); + Console.WriteLine("[3]. 법사"); + + ClassType choice = ClassType.None; + + string input = Console.ReadLine(); + + switch (input) + { + case "1": + choice = ClassType.Knight; + break; + case "2": + choice = ClassType.Archer; + break; + case "3": + choice = ClassType.Mage; + break; + } + + return choice; + } + + // 플레이어 생성 함수 + static void CreatePlayer(ClassType choice, out Player player) + { + switch (choice) + { + case ClassType.Knight: + player.hp = 100; + player.attack = 10; + break; + case ClassType.Archer: + player.hp = 85; + player.attack = 12; + break; + case ClassType.Mage: + player.hp = 60; + player.attack = 15; + break; + default: + player.hp = 0; + player.attack = 0; + break; + } + } + + // 플레이어 생성 함수 (CreatePlayer)를 참고해 몬스터 랜덤 생성 함수 (CreateRandomMonster)를 완성해보세요. + // 1. 1~3 중 랜덤으로 수를 하나 뽑습니다. + // 2. 뽑은 숫자가 1일 경우에는 슬라임, 2일 경우에는 오크, 3일 경우에는 스켈레톤을 생성하는 코드를 짭니다. (CreatePlayer 참고) + // default의 경우 몬스터의 체력을 0, 공격력을 0이로 초기화만 해줍니다. + // 2-1. 이 때 공격력과 체력을 초기화해주는 코드가 case 실행문에 반복적으로 나타납니다. 함수로 따로 빼서 구현해봅시다. + // 3. "(몬스터 이름)이 생성되었습니다."라는 문구를 출력해줍니다. (default의 경우 생략) + + // 몬스터 종류 + // Slime -> 체력: 20 / 공격력: 2 + // Orc -> 체력: 40 / 공격력: 5 + // Skeleton -> 체력: 30 / 공격력: 7 + + + static void ResetMonster(MonsterType monsterType, out int hp, out int attack) + { + hp = 0; + attack = 0; + + switch (monsterType) + { + case MonsterType.Slime: + hp = 20; + attack = 2; + Console.WriteLine("슬라임이 생성되었습니다."); + break; + case MonsterType.Orc: + hp = 40; + attack = 5; + Console.WriteLine("오크가 생성되었습니다."); + break; + case MonsterType.Skeleton: + hp = 30; + attack = 7; + Console.WriteLine("스켈레톤이 생성되었습니다."); + break; + default: + hp = 0; + attack = 0; + break; + } + + } + + // 몬스터 랜덤 생성 함수 + static void CreateRandomMonster(out Monster monster) + { + // TODO + // Random 객체 생성 + Random random = new Random(); + // 1~3까지 숫자 랜덤으로 선택 + int randomNumber = random.Next(1, 4); + + monster.hp = 0; + monster.attack = 0; + + // 몬스터 생성 + MonsterType monsterType = (MonsterType)randomNumber; + ResetMonster(monsterType, out monster.hp, out monster.attack); + } + + // 게임 접속 함수 + static void EnterGame(ref Player player) + { + while(true) + { + Console.WriteLine("마을에 접속했습니다!"); + Console.WriteLine("[1]. 필드로 간다"); + Console.WriteLine("[2]. 로비로 돌아가기"); + + string choice = Console.ReadLine(); + switch (choice) + { + case "1": + EnterField(ref player); + break; + case "2": + return; + } + } + } + + // 필드 접속 함수 + static void EnterField(ref Player player) + { + Console.WriteLine("필드에 접속했습니다!"); + + while (true) + { + // 랜덤 몬스터 등장 + Monster monster; + CreateRandomMonster(out monster); + + Console.WriteLine("[1]. 전투 모드로 돌입"); + Console.WriteLine("[2]. 일정 확률로 마을로 도망"); + + // 사용자 입력을 받아 input에 저장 + string input = Console.ReadLine(); + + if (input == "1") + { + Fight(ref player, ref monster); + + //continue를 이용해 플레이어가 사망상태가 아니라면 루프를 계속 돌고 , + //사망한 상태라면 break로 EnterField를 빠져나가 마을로 가게 함. + if (player.hp > 0) + continue; + break; + } + else + { + // 30퍼센트 확률로 도망에 성공 + Random rand = new Random(); + int randValue = rand.Next(0, 101); + if (randValue<=33) + { + Console.WriteLine("도망쳤습니다!"); + break; + } + // 도망에 실패했다면 전투에 돌입한다. + else + { + Console.WriteLine("도망치지 못합니다!"); + Fight(ref player, ref monster); + if (player.hp > 0) + continue; + break; + } + } + } + } + + // 무한루프 안을 채워 플레이어 vs 몬스터 전투 함수를 완성해보세요. + // 1. 플레이어가 먼저 몬스터를 공격한 뒤, 몬스터가 플레이어를 공격합니다. 플레이어가 몬스터를 공격할 경우, 몬스터의 체력에서 플레이어의 공격력 수치만큼을 뺍니다. 몬스터가 플레이어를 공격할 경우, 플레이어의 체력에서 몬스터의 공격력 수치만큼을 뺍니다. + // 2. 플레이어가 몬스터를 공격했을 때, 몬스터의 체력이 0 이하가 된다면 + // 1. "적을 무찔렀습니다!" 라는 문구를 출력합니다 + // 2. 플레이어의 남은 체력을 출력해줍니다 (ex. 남은 체력: 87) + // 3. 무한루프를 빠져나갑니다. + // 3. 몬스터가 플레이어를 공격했을 때, 플레이어의 체력이 0 이하가 된다면 "Game Over... 마을로 돌아갑니다..."를 출력한 뒤 무한루프를 빠져나갑니다. + + // 플레이어 vs 몬스터 전투 함수 + static void Fight(ref Player player, ref Monster monster) + { + while (true) + { + // TODO + monster.hp -= player.attack; + if (monster.hp > 0 && player.hp > 0) + { + player.hp -= monster.attack; + } + else if (monster.hp <= 0 && player.hp > 0) + { + Console.WriteLine("적을 무찔렀습니다!"); + Console.WriteLine("남은 체력: "+player.hp); + break; + } + else if (player.hp <= 0) + { + Console.WriteLine("Game Over... 마을로 돌아갑니다..."); + break; + } + } + } + + // 메인 함수 + static void Main(string[] args) + { + ClassType choice = ClassType.None; + + while (true) + { + // 플레이어의 직업을 선택 + choice = ChooseClass(); + + // continue 이용해 ClassType선택이 완료되지 않은 상태라면 이후 코드로 넘어가지 않도록 함. + if (choice == ClassType.None) + continue; + + // 플레이어 생성 (체력과 공격력 정보 초기화) + Player player; + CreatePlayer(choice, out player); + Console.WriteLine($"HP:{player.hp} Attack:{player.attack}"); + + // 게임 시작 + EnterGame(ref player); + } + } + } +} \ No newline at end of file diff --git a/TextRPG_1/Properties/AssemblyInfo.cs b/TextRPG_1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8e1e90d --- /dev/null +++ b/TextRPG_1/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TextRPG_1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TextRPG_1")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0682F3D5-AA47-4112-874C-EF02E2DFF465")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/TextRPG_1/TextRPG_1.csproj b/TextRPG_1/TextRPG_1.csproj new file mode 100644 index 0000000..e81b093 --- /dev/null +++ b/TextRPG_1/TextRPG_1.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {0682F3D5-AA47-4112-874C-EF02E2DFF465} + Exe + Properties + TextRPG_1 + TextRPG_1 + v4.7.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + diff --git a/TextRPG_1/bin/Debug/TextRPG_1.exe b/TextRPG_1/bin/Debug/TextRPG_1.exe new file mode 100644 index 0000000..8458cc6 Binary files /dev/null and b/TextRPG_1/bin/Debug/TextRPG_1.exe differ diff --git a/TextRPG_1/bin/Debug/TextRPG_1.pdb b/TextRPG_1/bin/Debug/TextRPG_1.pdb new file mode 100644 index 0000000..b01180d Binary files /dev/null and b/TextRPG_1/bin/Debug/TextRPG_1.pdb differ diff --git a/TextRPG_1/obj/Debug/TextRPG_1.csproj.AssemblyReference.cache b/TextRPG_1/obj/Debug/TextRPG_1.csproj.AssemblyReference.cache new file mode 100644 index 0000000..053a967 Binary files /dev/null and b/TextRPG_1/obj/Debug/TextRPG_1.csproj.AssemblyReference.cache differ diff --git a/TextRPG_1/obj/Debug/TextRPG_1.csproj.CoreCompileInputs.cache b/TextRPG_1/obj/Debug/TextRPG_1.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..a69093a --- /dev/null +++ b/TextRPG_1/obj/Debug/TextRPG_1.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +27e020e97ae9d4148c555a3db50878e8476112f8 diff --git a/TextRPG_1/obj/Debug/TextRPG_1.csproj.FileListAbsolute.txt b/TextRPG_1/obj/Debug/TextRPG_1.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..f2702b9 --- /dev/null +++ b/TextRPG_1/obj/Debug/TextRPG_1.csproj.FileListAbsolute.txt @@ -0,0 +1,6 @@ +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\bin\Debug\TextRPG_1.exe +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\bin\Debug\TextRPG_1.pdb +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\obj\Debug\TextRPG_1.csproj.AssemblyReference.cache +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\obj\Debug\TextRPG_1.csproj.CoreCompileInputs.cache +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\obj\Debug\TextRPG_1.exe +C:\Users\USER\RiderProjects\TextRPG_1\TextRPG_1\obj\Debug\TextRPG_1.pdb diff --git a/TextRPG_1/obj/Debug/TextRPG_1.exe b/TextRPG_1/obj/Debug/TextRPG_1.exe new file mode 100644 index 0000000..8458cc6 Binary files /dev/null and b/TextRPG_1/obj/Debug/TextRPG_1.exe differ diff --git a/TextRPG_1/obj/Debug/TextRPG_1.pdb b/TextRPG_1/obj/Debug/TextRPG_1.pdb new file mode 100644 index 0000000..b01180d Binary files /dev/null and b/TextRPG_1/obj/Debug/TextRPG_1.pdb differ diff --git "a/[13\352\270\260 \355\221\234\354\235\200\354\204\234] C# \352\270\260\354\264\210 \354\204\270\354\205\230 2\354\260\250\354\213\234 \352\263\274\354\240\234 \354\240\234\354\266\234.pdf" "b/[13\352\270\260 \355\221\234\354\235\200\354\204\234] C# \352\270\260\354\264\210 \354\204\270\354\205\230 2\354\260\250\354\213\234 \352\263\274\354\240\234 \354\240\234\354\266\234.pdf" new file mode 100644 index 0000000..0f6f52f Binary files /dev/null and "b/[13\352\270\260 \355\221\234\354\235\200\354\204\234] C# \352\270\260\354\264\210 \354\204\270\354\205\230 2\354\260\250\354\213\234 \352\263\274\354\240\234 \354\240\234\354\266\234.pdf" differ