[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
'코딩 1막 <C++개념편> > 코딩 1막 <C++응용편>' 카테고리의 다른 글
[C++] 플레이어 클래스를 만들고, 게터와 세터 생성하기 (0) | 2022.06.22 |
---|---|
[C++] 클래스와 구조체의 비교 (0) | 2022.06.22 |
[C++] 게임 오프닝 만들기 (0) | 2022.06.16 |
[C++] 상호참조를 할만한 두 구조체를 만들고 선언부와 구현부를 분리해보자 (0) | 2022.06.16 |
[C++] 움직이는 자동차 시뮬레이션 (구조체, 벡터, 가상함수) (0) | 2022.06.15 |