ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 3주차(2)-팀 프로젝트 기능 구현중
    TIL 2023. 8. 29. 22:33
    반응형

    요청받은 기능들은 다 구현했다.

     

    이전 개인 프로젝트에서 사용했던 CheckValidInput 를 이용해 값을 받고,

    메서드를 불러오는 방식을 사용했으나, 별로 마음에 들지 않아 내일 바꿀 예정이다.

    (팀원에게 물어봐서 커서를 이동하여 선택하는 방식을 사용할 예정)

     

    스테이지 해금

    완료

     

    층 정보

    완료

     

    행동

    완료

     

    using LibraryOfSparta.Common;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Security.Cryptography.X509Certificates;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml.Linq;
    
    namespace LibraryOfSparta
    {
        public class Stage
        {
            //public static int currentCompleted = 0; //현재 클리어 상태 저장
            //제이슨으로 저장하신다고 함
    
    
            //스테이지 이름
            public string FloorName { get; set; }
            public string FloorBossName { get; set; }
            public string FloorDesc { get; set; }
            public bool FloorCompleted { get; set; }
    
            public Stage(string name, string bossName, string desc, bool floorCompleted)
            {
                FloorName = name;
                FloorBossName = bossName;
                FloorDesc = desc;
                FloorCompleted = floorCompleted;
    
            }
        }
    
    
        public class Entrance
        {
            static Stage[] stages; //스테이지 배열
            static int currentCompleted; // ClearDataSet() 사용하지 않는곳에서 진입 시 해당 변수 사용 =>ClearDataSet(entrance.currentCompleted)
            static void StageDataBase()
            {
                //스테이지
                //if(초기화 방지 stages == null || stages.Length == 0)
                //return;
                stages = new Stage[]
                {
                    new Stage("1층", "1층 보스", "설명설명설명설명가나다라ㅏ바나나아사나나아사아타가가가다우고아아오애게에에에에으엥ㅇ끼이에에ㅔ에에에에에에엑", false), 
                    new Stage("2층", "2층 보스", "2층 설명설명설명설명", false),
                    new Stage("3층", "3층 보스", "3층 설명설명설명설명", false),
                    new Stage("4층", "4층 보스", "4층 설명설명설명설명", false),
                    new Stage("5층", "5층 보스", "5층 설명설명설명설명", false),
                    new Stage("6층", "6층 보스", "6층 설명설명설명설명", false),
                    new Stage("7층", "7층 보스", "7층 설명설명설명설명", false),
                    new Stage("8층", "8층 보스", "8층 설명설명설명설명", false),
                    new Stage("9층", "9층 보스", "9층 설명설명설명설명", false),
                    new Stage("10층", "10층 보스", "10층 설명설명설명설명", false),
                };
            }
    
            //실제 출력★
            public void EntarceMain()
            {
                if(currentCompleted == null)
                    currentCompleted = 6;
    
                Console.SetWindowSize(Define.SCREEN_X, Define.SCREEN_Y); // 콘솔 창 크기 설정
                DrawPanel(); // 외곽선 UI
                DrawTower(); // 탑
    
                //DrawFloorInfo(0);//인포           
                DrawMenu();//메뉴
                //BGM 시작
    
    
            }
    
    
    
    
            //수정★
            //층 데이터 세팅
            public void ClearDataSet(int num) //클리어 한 층 수 입력받기
            {
                StageDataBase();
                currentCompleted = num;
                if (num == 0)
                    return;
    
    
                for (int i = 0; i < num; i++)
                {
                    stages[i].FloorCompleted = true; //해당 스테이지(클리어 스테이지) 까지 데이터 수정
                }
    
            }
    
            //UI - 탑 (스테이지 클리어 상태 반영)
            public void DrawTower()
            {
                int cloudRange = 0;
                // 탑 몸체
                for (int i = 0; i < 30; i++) // 층 수정 & 층 당 블럭 개수 수정 시 변경
                {
                    Console.SetCursorPosition(16, Define.SCREEN_Y - (7 + i));
                    Console.Write("█▒▒▒█ ◈ █▒▒▒█");
                    if (i % 3 == 0 && i != 0)
                    {
                        //스테이지 해금 체크, 경계선 출력
                        Console.SetCursorPosition(15, Define.SCREEN_Y - (7 + i));
                        Console.Write("X···XX···X");
                        int j = i / 3 - 1;
    
                        if (!stages[j].FloorCompleted) // 스테이지[j]가 false라면)
                        {
                            break;
                        }
                    }
    
                    cloudRange++;
                }
                // 가장 아래
                Console.SetCursorPosition(6, Define.SCREEN_Y - 7);
                Console.Write("〓〓■■■▒░A۞A▣▣A۞A░▒■■■〓〓");
    
                //구름
                for (int i = 4; i < Define.SCREEN_Y - cloudRange - 6; i++) // 50
                {
                    Console.SetCursorPosition(5, i);
                    Console.Write(new string('ω', Define.SCREEN_X - 95));
                }
    
            }
    
    
            //메뉴 - 메인
            public void DrawMenu()
            {
                
                Console.SetCursorPosition(97, 32);
                Console.WriteLine("행동 선택");
                Console.SetCursorPosition(85, 35);
                Console.WriteLine("1. 층 고르기");
                Console.SetCursorPosition(85, 37);
                Console.WriteLine("2. 인벤토리");
                Console.SetCursorPosition(85, 39);
                Console.WriteLine("3. 메인 메뉴");
                //입력창
                Console.SetCursorPosition(2, Define.SCREEN_Y - 3);
    
                Console.Write("\t입력 : ");
                int input = CheckValidInput(1, 2);
                switch (input)
                {
                    case 1:
                        CleaningInfo(1);
                        StageMenu();//스테이지 선택 메서드 호출
                        break;
    
                    case 2:
                        ; //인벤토리로 가기 메서드 호출
                        break;
                    case 3:
                        ;//메뉴로 가기 메서드 호출
                        break;
                }
            }
    
            //메뉴 - 스테이지 선택
    
            public void StageMenu()
            {
                Console.SetCursorPosition(83, 32);
                Console.WriteLine("스테이지 선택[0. 뒤로가기]");
    
                int j = 0;
    
                for (int i = 1; i < currentCompleted + 2; i++)
                {              
                    if(i <= 5)
                    {
                        Console.SetCursorPosition(85, 33 + i + j);
                        Console.WriteLine($"{i}. {i}층 선택");
                    }
                    else
                    {
                        Console.SetCursorPosition(105, 23 + i + j);
                        Console.WriteLine($"{i}. {i}층 선택");
                    }
    
                    j++;
                }
    
    
                //입력창
                Console.SetCursorPosition(2, Define.SCREEN_Y - 3);
    
                Console.Write("\t입력 : ");
                int input = CheckValidInput(0, currentCompleted + 2);
                switch (input)
                {
                    case 0://뒤로가기
                        CleaningInfo(1);
                        DrawMenu();
                        break;
                    case 1://스테이지 선택1
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
    
                    case 2://스테이지 선택2
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 3:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 4:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 5:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 6:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 7:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 8:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 9:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                    case 10:
                        CleaningInfo(1);
                        CleaningInfo(2);
                        DrawFloorInfo(input - 1);
                        CheckStage(input);
                        break;
                } //스테이지 선택 switch
            }
    
            //UI - 층 정보
            public void DrawFloorInfo(int num)
            {
                int tenFloor = 0;
                if (num == 9) { tenFloor = 1; }
    
                Console.SetCursorPosition(100 - tenFloor, 6);
                Console.Write(stages[num].FloorName);
                Console.SetCursorPosition(94 - tenFloor, 11);
                Console.Write($"보스 : {stages[num].FloorBossName}");
    
                // 층 설명 출력
                string floorDesc = $"{stages[num].FloorDesc}";
                Console.SetCursorPosition(91, 15);
    
                int maxLineCount = 4; // 최대 출력 줄 수
                int currentLine = 0; // 현재 줄
                int maxLineWidth = 11; // 최대 글자 수
    
                while (currentLine < maxLineCount) //(!string.IsNullOrEmpty(floorDesc)
                {
                    if (floorDesc.Length > maxLineWidth) //문자의 길이가 최대 출력가능 길이보다 크다면
                    {
                        string line = floorDesc.Substring(0, maxLineWidth); // 던전 설명 0~ 최대 범위까지 자르기
                        Console.Write(line); //복사 출력
    
                        Console.SetCursorPosition(91, Console.CursorTop + 1); // 다음 줄로 이동  Console.CursorTop(현재 커서의 상단 위치)
                        floorDesc = floorDesc.Substring(maxLineWidth); // maxLineWidth까지의 설명 내용을 문자열에서 제거
                    }
                    else
                    {
                        Console.Write(floorDesc); // 그대로 출력
                        break;
                    }
                    currentLine++; // 줄 이동
                }
    
                Console.SetCursorPosition(92, 25);
                Console.Write($"클리어 상태 : {stages[num].FloorCompleted}");
            }
    
    
    
            //UI - 외곽선
            public void DrawPanel()
            {
                //메인 외곽선(123x45)
    
                // 가장 위
                Console.SetCursorPosition(2, 2);
                Console.Write("┌" + new string('─', Define.SCREEN_X - 7) + "┐");
    
                // 가운데
                for (int i = 3; i < Define.SCREEN_Y - 5; i++)
                {
                    Console.SetCursorPosition(2, i);
                    Console.Write("│" + new string(' ', Define.SCREEN_X - 7) + "│");
                }
    
                // 가장 아래
                Console.SetCursorPosition(2, Define.SCREEN_Y - 5);
                Console.Write("└" + new string('─', Define.SCREEN_X - 7) + "┘");
    
    
                //탑 외곽선(70x44)
    
                // 가장 위
                Console.SetCursorPosition(4, 3);
                Console.Write("┌" + new string('─', Define.SCREEN_X - 60) + "┐");
    
                // 가운데
                for (int i = 4; i < Define.SCREEN_Y - 6; i++)
                {
                    Console.SetCursorPosition(4, i);
                    Console.Write("│" + new string(' ', Define.SCREEN_X - 60) + "│");
                }
    
                // 가장 아래
                Console.SetCursorPosition(4, Define.SCREEN_Y - 6);
                Console.Write("└" + new string('─', Define.SCREEN_X - 60) + "┘");
    
    
                //층 정보 외곽선(40x30)
                // 가장 위
                Console.SetCursorPosition(80, 3);
                Console.Write("┌" + new string('─', Define.SCREEN_X - 90) + "┐");
    
                // 가운데
                for (int i = 4; i < Define.SCREEN_Y - 20; i++)
                {
                    Console.SetCursorPosition(80, i);
                    Console.Write("│" + new string(' ', Define.SCREEN_X - 90) + "│");
                }
    
                // 가장 아래
                Console.SetCursorPosition(80, Define.SCREEN_Y - 20);
                Console.Write("└" + new string('─', Define.SCREEN_X - 90) + "┘");
    
                //행동 외곽선(40x30)
                // 가장 위
                Console.SetCursorPosition(80, 31);
                Console.Write("┌" + new string('─', Define.SCREEN_X - 90) + "┐");
    
                // 가운데
                for (int i = 32; i < Define.SCREEN_Y - 5; i++)
                {
                    Console.SetCursorPosition(80, i);
                    Console.Write("│" + new string(' ', Define.SCREEN_X - 90) + "│");
                }
    
                // 가장 아래
                Console.SetCursorPosition(80, Define.SCREEN_Y - 6);
                Console.Write("└" + new string('─', Define.SCREEN_X - 90) + "┘");
            }
    
    
            //UI - 내용물 청소
            private void CleaningInfo(int num)
            {
                switch (num)
                {
                    case 1://행동 메뉴 클리어
                        for (int i = 32; i < Define.SCREEN_Y - 6; i++)
                        {
                            Console.SetCursorPosition(81, i);
                            Console.Write(new string(' ', Define.SCREEN_X - 90));
                        }
                        break;
    
                    case 2://층 정보 클리어
                        for (int i = 4; i < Define.SCREEN_Y - 20; i++)
                        {
                            Console.SetCursorPosition(81, i);
                            Console.Write(new string(' ', Define.SCREEN_X - 90));
                        }
                        break;
                    case 3://잘못된 정보입니다 메시지 클리어(사용안함 나중에 지울것★)
                        for (int i = 4; i < Define.SCREEN_Y - 20; i++)
                        {
                            Console.SetCursorPosition(81, i);
                            Console.SetCursorPosition(' ', Define.SCREEN_X - 3);
                        }
                        break;
                }
            }
    
            //메뉴 - 스테이지 진입 확인 [실제 전투 씬 진입]
            private void CheckStage(int num)
            {
                Console.SetCursorPosition(89, 34);
                Console.WriteLine($"{num} 층에 입장하시겠습니까?");
    
                Console.SetCursorPosition(88, 42);
                Console.WriteLine($"1. 수락\t\t   2. 거절");
    
                //입력창
                Console.SetCursorPosition(2, Define.SCREEN_Y - 3);
    
                Console.Write("\t입력 : ");
                int input = CheckValidInput(1, 2);
                switch (input)
                {
                    case 1://수락
                        //전투 씬 이동
                        break;
                    case 2://거절
                        CleaningInfo(1);
                        CleaningInfo(2);
                        StageMenu();
                        break;
                }
            }
    
            //입력 == 나중에 커서 형식으로 변경
            static int CheckValidInput(int min, int max)
            {
                while (true)
                {
                    string input = Console.ReadLine();
    
                    bool parseSuccess = int.TryParse(input, out var ret);
                    if (parseSuccess)
                    {
                        if (ret >= min && ret <= max)
                            return ret;
                    }
    
                }
            }
    
            public int CurrentCompleted()
            {
                return currentCompleted;
            }
    
            //스테이지 UI (해금구현은 불값을 통해 하고, 씬을 불러오는 경우 초기화->판별->출력)
            //선택 1~10
        }

     

     

    반응형
Designed by Tistory.