언어 정리/c#

c# console Text RPG

rimugiri 2024. 5. 10. 18:07
728x90

제작 기간 : 1주일

팀원 : 박건원, 이진우, 오승희, 최재성

 

사용 기술 : c#

 

1. 데이터 저장

Newtonsoft.json라이브러리 활용과 인터페이스 저장을 위해 Custom JsonConverter 제작하기

https://rimugiri.tistory.com/entry/c-NewtonSoftjson-%ED%99%9C%EC%9A%A9-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A0%80%EC%9E%A5-interface-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%B6%94%EA%B0%80

 

c# NewtonSoft.json 활용 데이터 저장 <interface 데이터 추가>

문제 Interface의 경우 데이터를 불러 올 상황에 JsonConvert 오류가 발생하게 된다. 따라서 이를 해결하기 위한 방안을 소개한다. 0. 데이터 저장 클래스 ▶ 예제 클래스 및 인터페이스 선언 class Player

rimugiri.tistory.com

 

2. c# 음악 재생하기

https://rimugiri.tistory.com/entry/c-Console-%EC%9D%8C%EC%95%85-%EC%B6%9C%EB%A0%A5-%EB%B0%A9%EB%B2%95-wav-mp3

 

c# Console 음악 출력 방법 (.wav, .mp3)

1. using System.Media; 이 라이브러리를 사용 하면 .wav파일을 콘솔 상에서 재생할 수 있다. 새로운 쓰레드를 자동으로 생성해 주어 그 쓰레드에서 작동하여 아래에서 자신이 하고싶은 동작을 구현 할

rimugiri.tistory.com

3. 핵심적임 흐름제어 코드

흐름을 한곳에서 관리하게 하기 위하여 GameManager를 singleton으로 두어 하나의 함수로 선택에 대한 호출이 가능하게 하였다.

public void SetNextAction(int minValue, int maxValue)
{
    Console.WriteLine("\n원하는 행동을 입력해 주세요");
    while (IsInValidAction(minValue, maxValue) == false) { Console.WriteLine("잘못된 입력입니다 다시 선택해 주세요"); }
    Console.WriteLine();
}
bool IsInValidAction(int minValue, int maxValue)
{
    if (int.TryParse(Console.ReadLine(), out action) == false) return false;

    if (action > maxValue || action < minValue) return false;

    return true;
}

 

 

 

https://github.com/gunwonpark/TextRPGGame?tab=readme-ov-file

 

GitHub - gunwonpark/TextRPGGame: MakeTextRPGGame

MakeTextRPGGame. Contribute to gunwonpark/TextRPGGame development by creating an account on GitHub.

github.com

 

728x90