목차
추가 기능
- 엔딩 시 이미지 콘솔창에 출력
- 게임 시작 시 메뉴 변경
- 엔딩 목록 수집
엔딩 이미지

엔딩 이미지는 현재 2종만 있으며 나중에 마무리할때 전체 이미지 추가할 예정입니다.
이미지는 챗 gpt 를 통해 생성했습니다.
직접 그릴까 했는데 gpt가 이렇게까지 잘그려줄 줄 몰랐네요...
엔딩 목록(수집요소)

엔딩 목록은 [엔딩 목록] 창에서 확인 할 수 있다.
해당 엔딩을 얻으면 ??? 에서 엔딩 이름과 획득 방법이 표시된다.
새로운 엔딩을 얻을 시 txt 파일에 저장되며,
프로그램 실행 시 txt 파일을 읽어 엔딩별 획득 여부를 불러온다.


Endlist.txt 파일에 엔딩여부가 저장되며
엔딩별 획득여부를 Y, N 으로 표시한다.
소스코드
1. 콘솔창에 bmp 이미지 출력
// 이미지 출력
void ShowBitmap(const char* filename)
{
HBITMAP hBitmap;
BITMAP bitmap;
HDC hdc, hdcMem;
HWND hwnd = GetConsoleWindow(); // 콘솔 창 핸들 가져오기
// 콘솔 DC 얻기
hdc = GetDC(hwnd);
hBitmap = (HBITMAP)LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (!hBitmap)
{
return;
}
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hBitmap);
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
// 20, 50 위치에 200 x 200 사이즈로 출력
StretchBlt(hdc, 20, 100, 250, 250, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
DeleteDC(hdcMem);
ReleaseDC(hwnd, hdc);
DeleteObject(hBitmap);
}
파일 경로를 기준으로 bmp 이미지를 출력한다.
if (Ending_imgName[n]!="")
{
// 이미지 출력하기
ShowBitmap(Ending_imgName[n].c_str());
}
vector에 엔딩별 이미지 경로를 저장한 후 Showbitmap을 호출해서 이미지를 콘솔에 출력합니다.
2. txt 파일에 엔딩 수집여부 저장 및 불러오기
void SaveEndingList(int endNo)
{
std::ifstream fileIn("Endlist.txt"); // 기존 파일 읽기
std::vector<std::string> lines; // 파일 내용을 저장할 벡터
std::string line;
if (!fileIn.is_open()) {
std::cout << "파일을 열 수 없습니다!" << std::endl;
return;
}
// 파일 내용을 읽어서 벡터에 저장
while (getline(fileIn, line))
{
std::stringstream ss(line);
std::string number, isEnable;
ss >> number >> isEnable; // 번호, Y/N 읽기
// 특정 번호를 찾으면 변경
if (std::stoi(number) == endNo)
{
if (isEnable == "N")
{
cout << "신규 엔딩이 목록에 추가되었습니다." << "\n";
}
isEnable = "Y"; // 특정 번호의 값을 Y로 변경
}
lines.push_back(number + " " + isEnable);
}
fileIn.close(); // 파일 닫기
// 수정된 내용을 다시 파일에 저장
std::ofstream fileOut("Endlist.txt"); // 덮어쓰기 모드
if (!fileOut.is_open())
{
std::cout << "파일을 열 수 없습니다!" << std::endl;
return;
}
for (const auto& l : lines)
{
fileOut << l << "\n"; // 줄 단위로 다시 쓰기
}
fileOut.close();
std::cout << "파일 저장 완료!" << std::endl;
}
엔딩 번호(0~9) 를 기준으로 찾아 엔딩여부(Y/N) 을 업데이트합니다.
void SetEndingInfo()
{
Endinfo[0] = { 0,"중독", "독약을 마시고 사망", false};
Endinfo[1] = { 1,"추락", "함정에 빠진 후 사망", false};
// Endinfo[9]번까지 있지만 여기선 생략
// 파일에서 획득여부 읽어와야됨
string line;
ifstream file("Endlist.txt");
if (file.is_open())
{
while (getline(file, line))
{
std::stringstream ss(line); // stringstream으로 줄을 처리
std::string number;
std::string isEnable;
ss >> number; // 번호 읽기
getline(ss >> std::ws, isEnable); // 공백 무시하고 나머지 읽기
if (isEnable == "Y")
{
Endinfo[stoi(number)].isCollected = true;
}
}
file.close(); // 열었떤 파일을 닫는다.
}
else
{
cout << "Unable to open file";
}
}
프로그램 실행시 Endlist.txt 파일을 읽어 엔딩 수집 여부를 Endinfo 구조체에 저장합니다.
전체코드(깃허브 링크)
https://github.com/Chaeyunbyun/GameProject_Test
GitHub - Chaeyunbyun/GameProject_Test
Contribute to Chaeyunbyun/GameProject_Test development by creating an account on GitHub.
github.com
'연습 프로젝트' 카테고리의 다른 글
텍스트 RPG 게임 만들기-2 (C++) (2) | 2025.03.14 |
---|---|
텍스트 RPG 게임 만들기-1 (C++) (0) | 2025.03.12 |