김김김의 게임개발
  • C# #8 TextRPG 1
    2023년 08월 18일 20시 55분 33초에 업로드 된 글입니다.
    작성자: noun06

    개요

    • 개인 과제인 C# 콘솔 텍스트 RPG게임이다. 일단 필수 구현 부분에서의 뼈대와 클래스 설계를 진행하였는데 로직 자체에 문제가 많고 효율성이 떨어져서 버그가 많이 발생하기 때문에 입력처리 관련 기능은 전부 없애고 다시 최적화하여 작성할 예정이다. 초기 기본 클래스는 다음과 같이 크게 3 부분으로 나눌 예정이다.

     

    • 캐릭터 클래스: 플레이어의 기본 속성과 행동을 정의. 레벨, 체력, 공격력, 방어력, 이름, 직업.. 레벨업, 경험치 획득 등과 관련된 메서드
    • 아이템 클래스: 게임 매 아이템들의 이름, 설명, 효과(방어력 증가, 공격력 증가) 정의.
    • 게임 매니저 클래스: 게임의 진행, 화면 표시, 사용자 입출력 처리 등.

     

    코드

    namespace TextRPG
    {
        internal class GameManager
        {
            static void Main(string[] args)
            {
                MainMenu();
                
            }
    
            //게임 시작 시 호출되는 메인화면
            static void MainMenu()
            {
                Console.Clear();
                Console.WriteLine("마을에 오신 여러분 환영합니다!\n이곳에서 던전으로 들어가기 전 활동을 할 수 있습니다.");
                
                Console.WriteLine("\n1.상태보기");
                Console.WriteLine("2.인벤토리");
    
                int userInput = GetUserInput();
                switch (userInput)
                {
                    case 1:
                        MyInfo();
                        break;
                    case 2:
                        InventoryInfo();
                        break;
                }
            }
    
            //상태창 관리 메서드
            static void MyInfo()
            {
                Console.Clear();
                Player player = new Player("김전사", "전사");
    
                Console.WriteLine("\n0.나가기");
    
                int userInput = GetUserInput();
                while (userInput != 0)
                {
                    Console.WriteLine("잘못된 입력입니다!");
                    userInput = GetUserInput();
                }
    
                MainMenu();
            }
    
            //인벤토리창 관리 메서드
            static void InventoryInfo()
            {
                Console.Clear();
    
                Console.WriteLine("\n0.나가기");
    
                int userInput = GetUserInput();
                while (userInput != 0)
                {
                    Console.WriteLine("잘못된 입력입니다!");
                    userInput = GetUserInput();
                }
    
                MainMenu();
            }
    
            //사용자의 입력 처리를 관리하는 메서드
            static int GetUserInput()
            {
                while (true)
                {
                    Console.Write("\n원하시는 행동을 입력해주세요.\n>> ");
                    string input = Console.ReadLine();
    
                    if (int.TryParse(input, out int userInput))
                    {
                        // 0,1,2가 입력되었을 때만 반환
                        if (userInput == 0 || userInput == 1 || userInput ==2)
                        {
                            return userInput;
                        } 
                        else
                        {
                            Console.WriteLine("잘못된 입력입니다!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("잘못된 입력입니다!");
                    }
                }
            }
        }
        //캐릭터의 정보들을 조정하는 클래스
        class Player
        {
            public string Name;
            public string Class;
            public int Level;
            public int Attack;
            public int Defense;
            public int Health;
            public int Gold;
    
            public Player(string name, string playerClass)
            {
                Name = name;
                Class = playerClass;
                Level = 1;
                Attack = 10;
                Defense = 5;
                Health = 100;
                Gold = 1500;
                Console.WriteLine($"이름: {Name}");
                Console.WriteLine($"직업: {Class}");
                Console.WriteLine($"레벨: {Level}");
                Console.WriteLine($"공격력: {Attack}");
                Console.WriteLine($"방어력: {Defense}");
                Console.WriteLine($"체력: {Health}");
                Console.WriteLine($"골드: {Gold}");
            }
        }
    
        class Item
        {
    
        }
    }

     

     

    'C#' 카테고리의 다른 글

    C# #10 TextRPG 2  (0) 2023.08.20
    C# #9 알고리즘 기초 2  (0) 2023.08.19
    C# #7 스네이크 게임  (1) 2023.08.18
    C# #6 알고리즘 기초  (0) 2023.08.17
    C# #5 클래스, 객체, 상속, 다형성  (0) 2023.08.16
    댓글