namespace ConsoleApp1 { internal class Program { struct Player { public int hp; public int attack; } enum ClassType { None = 0, Knight = 1, Archer = 2, Mage = 3 } enum MonsterType { None = 0, Slime, Orc, Skeleton } struct Monster { public int hp; public int attack; } static ClassType chooseclass() { Console.WriteLine("직업을 선택하세요"); Console.WriteLine("[1 전사]"); Console.WriteLine("[2 궁수]"); Console.WriteLine("[3 법사]"); string input = Console.ReadLine(); ClassType choice = ClassType.None; 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 = 70; break; case ClassType.Archer: player.hp = 75; player.attack = 12; break; case ClassType.Mage: player.hp = 50; player.attack = 15; break; default: player.hp = 0; player.attack = 0; break; } } static void CreateRandomMonster(out Monster monster) { Random rand = new Random(); int randMonster = rand.Next(1, 4); switch (randMonster) { case (int)MonsterType.Slime: Console.WriteLine("슬라임이 생성되었습니다."); monster.hp = 20; monster.attack = 2; break; case (int)MonsterType.Orc: Console.WriteLine("오크가 생성되었습니다."); monster.hp = 40; monster.attack = 5; break; case (int)MonsterType.Skeleton: Console.WriteLine("스켈레톤이 생성되었습니다."); monster.hp = 30; 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(ref 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") { Random rand = new Random(); int randvalue = rand.Next(0, 101); if (randvalue <= 33) { Console.WriteLine("도망치는데 성공했습니다"); break; } else { Fight(ref player, ref monster); } } } } static void EnterGame(ref Player player) { while (true) { Console.WriteLine("마을에 접속한다"); Console.WriteLine("[1] 필드로 접속한다"); Console.WriteLine("[2] 로비로 돌아간다"); string input = Console.ReadLine(); if (input == "1") { EnterField(ref player); } else if (input == "2") { break; } } } static void Main(string[] args) { while (true) { ClassType choice = chooseclass(); if(choice != ClassType.None) { Player player; CreatePlayer(choice, out player); EnterGame(ref player); } } } } } |
'✏️ 취미 > 코딩' 카테고리의 다른 글
| 🕹️ 티스토리 헬로우(hello) 사진(이미지)이 본문 폭을 넘은 경우 (0) | 2026.01.14 |
|---|---|
| 🕹️ 티스토리 헬로우(hello) 스킨 다크모드 없애는 법 (0) | 2026.01.14 |
| [공부] 2D 유니런(유니티+런) 게임 제작 - 배경 (5) (3) | 2025.08.19 |
| [공부] 2D 유니런(유니티+런) 게임 제작 - player 총합 (4) (3) | 2025.08.17 |
| [공부] 2D 유니런(유니티+런) 게임 제작 - (3) (2) | 2025.08.17 |