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

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

728x90

<글자색 바꾸기 기능과 같은 다양한 Windows.h를 써서 게임 오프닝을 만들어보자>

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

using namespace std;

// 구조체 선언부
struct Player;
struct Warrior;
struct Wizard;
void Opening();
void Start();

// 구조체 정의부
struct Player
{
	string name;
	int hp;
	int atk;
	string job;
};

struct Warrior : Player
{
	Warrior();
	Warrior(string _name, int _hp, int _atk, string _job);
	void ShowInfo();
};

struct Wizard : Player
{
	Wizard();
	Wizard(string _name, int _hp, int _atk, string _job);
	void ShowInfo();

};

void Opening()
{
	cout << "어느날" << endl;
	Sleep(2000);
	system("cls");
	cout << "문득 잠에서 깼다" << endl;
	Sleep(3000);
	system("cls");
	cout << "갑자기 누가 문을 쿵쾅 뚜드린다" << endl;
	Sleep(4000);
	system("cls");
	SetColor(4);
	cout << "쿵!" << endl;
	Sleep(2000);
	system("cls");
	SetColor(7);
	cout << "(고요한 방 안)" << endl;
	Sleep(4000);
	system("cls");
	SetColor(4);
	cout << "쿵쿵!" << endl;
	Sleep(2000);
	system("cls");
	SetColor(9);
	cout << "...... '누구세요?' " << endl;
	Sleep(2000);
	system("cls");
	cout << "문이 갑자기 열린다" << endl;
}
void Start()
{
	int choice;
	cout << "캐릭터를 고르세요" << endl;
	Sleep(1000);
	SetColor(11);
	cout << "1. 전사   2. 마법사" << endl;
	cin >> choice;
	while (1)
	{
		if (choice == 1)
		{
			Warrior warrior("용맹한전사", 900, 350, "전사2차");
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
			warrior.ShowInfo();
			break;
		}

		else if (choice == 2)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
			Wizard wizard("신기한마법사", 1400, 950, "마법사3차");
			wizard.ShowInfo();
			break;
		}
		else
		{
			cout << "다시 선택하세요" << endl;
		}
	}
}
void SetColor(int colorNumber)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNumber);
}


void main()
{
	int input = 0;
	Opening();

	SetColor(1);
	cout << "게임을 시작하겠습니까?" << endl;
	Sleep(5000);
	system("cls");
	cout << "선택하십시오." << endl;
	SetColor(8);
	cout << "1. 시작    2. 종료" << endl;

	cin >> input;
	while (1)
	{
		if (input == 1)
		{
			Start();
			break; 
		}

		if (input == 2)
		{
			break;
		}
	}
}

// 전사 구현부
Warrior::Warrior() {}
Warrior:: Warrior(string _name, int _hp, int _atk, string _job)
{
	name = _name;
	hp = _hp;
	atk = _atk;
	job = _job;
}
void Warrior::ShowInfo()
{
	cout << "이름 : " << name << endl;
	cout << "체력 : " << hp << endl;
	cout << "공격력 : " << atk << endl;
	cout << "직업 : " << job << endl;
}

// 마법사 구현부
Wizard::Wizard() {}
Wizard::Wizard(string _name, int _hp, int _atk, string _job)
{
	name = _name;
	hp = _hp;
	atk = _atk;
	job = _job;
}
void Wizard::ShowInfo()
{
	cout << "이름 : " << name << endl;
	cout << "체력 : " << hp << endl;
	cout << "공격력 : " << atk << endl;
	cout << "직업 : " << job << endl;
}

 

728x90