스파르탄캠프/본격적인 캠프

노베이스의 게임개발(본 캠프) TextRpg 기능 구현

SP_1217 2024. 4. 26. 05:32


속이 뒤집어 지기전에 코드를 뒤집을까 고민하며...

using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dungeon
{
    public class Status
    {

        public string Name;
        public int Lv;
        public int Str;
        public int Def;
        public int Hp;
        public int Gold;
        public int menu;

        public Status(string name, int lv, int str, int def, int hp, int gold)
        { //생성자 < 

            Name = name;
            //이름
            Lv = lv;
            //레벨
            Str = str;
            //공격력
            Def = def;
            //방어력
            Hp = hp;
            //체력
            Gold = gold;
            //골드
        }
            while (true)
            {

                Console.WriteLine("캐릭터 정보");
                Console.WriteLine($"Lv : {Lv}");
                Console.WriteLine($"공격력 : {Str}");
                Console.WriteLine($"방어력 : {Def}");
                Console.WriteLine($"체력 : {Hp}");
                Console.WriteLine($"골드 : {Gold}");
                Console.WriteLine("");
                Console.WriteLine("0. 나가기");
                Console.WriteLine("원하시는 행동을 입력해주세요.");

                string input = Console.ReadLine();
                int.TryParse(input, out menu);
                switch (menu)
                {
                    case 0:
                        Console.Clear();
                        return;
                    default:
                        Console.Clear();
                        Console.WriteLine("\n지정된 값이 아닙니다.\n");
                        break;
                }
            }

        }
    }
}

생성자에 string과 int로 캐릭터의 간단한 info같은걸 보여주는걸 작성해주며 다시 Start로 나가

        public Start()
        {
            status = new Status("Rtan", 1, 10, 5, 100, 15000);
        }

이런식으로 불러올수 있게 했습니다 그러면 표현은 아래사진 처럼 가능해지죠.

 

속썩이는 장비창 이놈을 어찌할까...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Dungeon
{
    internal class Inventory
    {
        public int menu;
        Status status;
        Item equipItem;
        List<Item> getitems = new List<Item>();


        public Inventory(Status _status)
        {
            status = _status;
        }

        public void Render()
        {
            while (true)
            {
                Console.Clear();

                Console.WriteLine("\n보유 중인 아이템을 관리할 수 있습니다.\n");
                Console.WriteLine("[아이템 목록]\n");
                Console.WriteLine();
                foreach (Item item in getitems)
                {
                    Console.WriteLine($"{item.itName} 공격력+{item.itAbility}, {item.itInfo}");
                }
                Console.WriteLine("\n1. 장착 관리");
                Console.WriteLine("0. 나가기\n");
                Console.WriteLine("원하시는 행동을 입력해주세요.");

                string input = Console.ReadLine();
                int.TryParse(input, out menu);
                switch (menu)
                {
                    case 0:
                        Console.Clear();
                        return;
                    case 1:
                        Console.Clear();
                        Euip();
                        break;
                    default:
                        Console.Clear();
                        Console.WriteLine();
                        break;
                }

            }

        }
        public void Euip()
        {
            Console.WriteLine("장착 가능한 아이템");
            int i = 1;

            while (true)
            {
                foreach (Item item in getitems)
                {
                    string equippedMark = (item == equipItem) ? "[E]" : ""; // 장착된 아이템에는 [E] 추가
                    Console.WriteLine($"{i}. {item.itName} 공격력+{item.itAbility}, {item.itInfo}");
                    i++;
                }
                Console.Clear();
                Console.WriteLine("장착할 아이템을 선택하세요 (취소: 0):");
                string input = Console.ReadLine();
                int.TryParse(input, out int menu);
                switch (menu)
                {
                    case 0:
                        Console.Clear();
                        return;
                    case 1:
                        if (getitems.Count == 6)
                        {
                            bool quik = menu > 1;
                            if (quik && getitems[menu - 6].Equip) // 선택한 아이템이 장착 가능하면
                            {
                                Console.WriteLine("[E]"); // "[E]" 출력
                            }
                        }
                        break;
                }

            }
        }
         public void Myinventory(Item item)
        {
            getitems.Add(item);
                Console.WriteLine($"{item.itName} 공격력+{item.itAbility}, {item.itInfo}");
        }
    }
}

저는 inventory 안에서 가져온 장비의 설명과 장착이 가능하게 하기 위해 동분서주했고 실제로 표현까지는 가능했으나 장착과 장착을 하기 위한 화면으로 넘어가지는건 말을 안들었죠.

잘 넘어간다, 내 속도 넘어가고...

마음대로 안된다고해서 억지를 부릴순 없었기에 최소한의 마무리만을 위해 장착 관리창으로 넘어가려고만 했습니다 그런데 여기서 문제가 발생했는데

모르면 좀 가져가서 물어봐 T^T

                    case 1:
                        if (getitems.Count == 6)
                        {
                            bool quik = menu > 1;
                            if (quik && getitems[menu - 6].Equip) // 선택한 아이템이 장착 가능하면
                            {
                                Console.WriteLine("[E]"); // "[E]" 출력
                            }
                        }
                        break;
                }





          public void Myinventory(Item item)
        {
            getitems.Add(item);
                Console.WriteLine($"{item.itName} 공격력+{item.itAbility}, {item.itInfo}");
        }

값을 받아오는 곳에서 코드를 넘겨 받는데 이놈이 자꾸 null로 받아오는 겁니다. 왜 주는데 먹질못하니

그러니 제가 할수있는 부분은 새로운 메서드를 생성해서 그곳에 넘겨주는 것이였지만 그것마저도 제대로 해내지 못했습니다. Shop에서 받아온 부분만 Myinventory안에 남길수 있었고 case 1:을 통해서 새로운 창으로 넘어가는건 지속적으로 에러가 났었죠, 이건 제가 미숙해서 일어난 부분이었고 이 부분을 제대로 캐치해서 선생님에게 질문을 드렸어야 했지만 제가 강의 내용을 제대로 듣지 못하고 넘긴 부분이 있엇기에 오히려 말을 이해하지 못해 삐걱거려 약간의 마찰이 생기게 됐죠.


 

목요일 마무리

결국 늦어도 과제는 마무리 해야했고 부족한 강의 학습 + 어수룩한 진행과정에서 생긴 트러블 슈팅 등 많은 것들이 쌓이고 쌓여 결국 스스로 해결하지 못한 상황에 이르렀고 앞으로는 시간에 쫒겨도 더욱 침착해지며 강의 내용을 먼저 머릿속에 집어넣고 과제를 진행하기로 다짐했습니다. 분명한 것은 어중간한 결과물보단 착실하게 진행한 과정만 있다면 다음번에는 더 높은 퀄리티를 낼수있는 발돋움을 할수있다는 것이겠죠. 감사합니다.