[C++] 추리게임 오프닝 만들기

2022. 6. 16. 19:32코딩 1막 <C++개념편>/코딩 1막 <C++응용편>

728x90

#include <iostream>
#include <string>
#include <Windows.h> 

using namespace std;

void SetColor(int colorNumber)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNumber);
}


struct Detective
{
    string name;
    int inspriation;
    int healthGage;
    int maxHealthGage;

    void SetProfile()
    {
        system("cls");
        cout << "당신의 이름은 무엇입니까? " << endl;
        string input;
        getline(cin, input);
        name = input;

        maxHealthGage = 100;
        healthGage = maxHealthGage;
        inspriation = 0;
    }

    void ShowProfile()
    {
        system("cls");
        cout << "--------------" << endl;
        cout << "탐정의 이름 : " << name << endl;
        cout << "떠올린 영감 수 : " << inspriation << endl;
        cout << "남은 체력 : " << healthGage << endl;
        cout << "--------------" << endl;
    }
};




struct Game
{
    Detective* player;

    Game()
    {
        player = new Detective();
        Opening();
    }

    void Opening()
    {

        //Sleep(밀리초) 밀리초만큼 기다림 //밀리초라서 1000이면 1초
        Sleep(1000);
        cout << "안녕" << endl;

        Sleep(1000);
        cout << "사실 나는..." << endl;

        Sleep(2000);
        //SetColor(컬러번호) 컬러번호의 색으로 콘솔글자색을 바꿔 줌.
        SetColor(12);
        cout << "고구마다!" << endl;
        SetColor(15);

        Sleep(5000);


        //system("cls") 콘솔화면을 지워줌
        system("cls");

        cout << "-----------------------------------------------" << endl;
        cout << "----------숨막히는 고구마의 추리게임-----------" << endl;
        cout << "-----------------------------------------------" << endl;
        cout << "-----------------------------------------------" << endl;
        cout << "------------------GAME START-------------------" << endl;
        cout << "-----------------------------------------------" << endl;
        cout << "--------------아무키나 누르세요----------------" << endl;

        string temp;
        getline(cin, temp);
        system("cls");

        player->SetProfile();

        Select();
    }

    void StartReasoning()
    {
        system("cls");
        cout << "추리를 시작합니다" << endl;
        Sleep(1000);
        //탐정의 영감을 올리고싶음//
        //하지만 체력은 떨어짐//
        player->inspriation += 5;
        player->healthGage -= 10;
        cout << "추리가 끝났습니다" << endl;
        Sleep(1000);
        system("cls");
    }

    void Rest()
    {
        system("cls");
        cout << "쉬어서 체력을 회복합니다" << endl;
        Sleep(1000);
        SetColor(10);
        cout << "체력을 회복되었습니다" << endl;
        player->healthGage = player->maxHealthGage;
        //탐정의 체력을 올리고싶음//
        Sleep(1000);
        SetColor(15);
        system("cls");
    }

    void Confirm()
    {
        system("cls");
        cout << "당신은.." << endl;
        Sleep(1000);
        cout << "범인을.." << endl;
        Sleep(1000);
        cout << "찾았습니다..!" << endl;
        Sleep(1000);
    }

    void ShowDetectiveInfo()
    {
        player->ShowProfile();
    }


    void Select()
    {
        int input;
        while (true)
        {
            ShowDetectiveInfo();
            cout << endl << endl;
            cout << "선택지를 고르세요" << endl;
            cout << "1. 추리, 2. 휴식, 3.확인" << endl;
            cin >> input;
            if (input == 1)
            {
                StartReasoning();
            }
            else if (input == 2)
            {
                Rest();
            }
            else if (input == 3)
            {
                Confirm();
            }
            else
            {
                cout << "다시 입력해주세요." << endl;
            }
        }
    }
};


void main()
{

    Game game;

}

출력 결과

728x90