첫 C++게임

Charge·2024년 10월 18일

Chat

목록 보기
7/7

2020년 22살에 게임 제작에 대한 지식 없이 C++만을 사용해 게임을 제작했었다.

#include<iostream>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include <time.h>

using namespace std;

void removecursor() // 커서 깜빡임을 없애주는 함수
{
	CONSOLE_CURSOR_INFO cur;
	GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cur);
	cur.bVisible = 0;
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cur);
}

#define U 72
#define D 80
#define L 75
#define R 77
#define S 32

const char* tile[] = { " ", "♠", "☆", "○", "①", "②", "③", "④", "⑤", "⑥", "⑦", "⑧", "◎", "■", "㉭", "▶", "\", "★", "/", "──", "ㅅ", "│ ", " └", "ㅎ", "--", "==", "=>", " @", " │", " ─" };
//						0      1    2     3     4     5     6     7     8     9     10    11    12    13    14    15    16    17    18    19      20    21      22    23    24    25   26   27     28     29
//						땅,  나무,주인공, npc1, 돌1,  돌2, 돌3,  돌4,  돌5,  돌6,   돌7,  돌8, npc2, 바위, 호랑이, 커서
/*int Map_M[10][10] = {
	//0  1  2  3  4  5  6  7  8  9
	{ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},// 0
	{ 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},// 1
	{ 1, 1, 0, 0, 1, 0, 0, 0, 0, 0},// 2
	{ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0},// 3
	{ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0},// 4
	{ 0, 0, 1, 0, 1, 0, 0, 0, 0, 0},// 5
	{ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0},// 6
	{ 0, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 7
	{ 0, 1, 0, 0, 0, 0, 0, 0, 3, 0},// 8
	{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1} // 9
};
*/
const char* menu[5] = { "공격하기", "스킬 사용", "아이템 사용", "스탯 확인하기", "도망가기" };

int Map_M[10][10] = {
	//0  1  2  3  4  5  6  7  8  9
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},// 0
	{ 1, 0, 0, 1, 1, 1, 1, 1, 1, 1},// 1
	{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 2
	{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 3
	{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 4
	{ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1},// 5
	{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 6
	{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},// 7
	{ 1, 1, 0, 0, 0, 0, 0, 0, 3, 0},// 8
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} // 9
};

int Map_P[10][10] = {
	//0  1  2  3  4  5  6  7  8  9
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},// 0
	{ 0, 3, 0, 0, 1, 1, 1, 1, 1, 1},// 1
	{ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1},// 2
	{ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1},// 3
	{ 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},// 4
	{ 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},// 5
	{ 1, 1, 1, 0, 0, 0, 0, 1, 0,12},// 6
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},// 7
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},// 8
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} // 9
};

int Map_Maze[10][10] = {
	//0  1  2  3  4  5  6  7  8  9
	{13,13,13,13,13,13,13,13,13,13},// 0
	{ 0, 0, 0, 0, 0,13, 0, 0, 0,13},// 1
	{13, 0,13,13, 0,13, 0,13, 0,13},// 2
	{13, 0, 0,13, 0, 0, 0,13, 0,13},// 3
	{13,13, 0,13,13,13, 0, 0,13,13},// 4
	{13, 0, 0, 0,13, 0,13, 0, 0,13},// 5
	{13, 0,13, 0, 0, 0, 0,13, 0,13},// 6
	{13, 0,13,13,13,13, 0,13,13,13},// 7
	{13, 0, 0, 0, 0,13, 0, 0, 0,13},// 8
	{13,13,13,13,13,13,13,13,12,13} // 9
};

int Map_F[9][12] = {
	//0  1  2  3  4  5  6  7  8  9 10 11
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 3
	{ 1, 0, 2, 0, 0, 0, 0, 0, 0,14, 0, 1}, // 4
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 5
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
};

int Map_PAtt[3][9][12] = {
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 3
		{ 1, 0, 0, 0, 0, 0, 0, 0, 2,17, 0, 1}, // 4
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	},
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
		{ 1, 0, 0, 0, 0, 0, 0, 0,17,17,17, 1}, // 3
		{ 1, 0, 0, 0, 0, 0, 0, 0,17,14,17, 1}, // 4
		{ 1, 0, 0, 0, 0, 0, 0, 0,17,17,17, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	},
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0,17, 0,17, 0,17}, // 2
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 3
		{ 1, 0, 0, 0, 0, 0, 0,17, 2,14, 0,17}, // 4
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0,17, 0,17, 0,17}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	}
};

int Map_HAtt[9][12] = {
	//0  1  2  3  4  5  6  7  8  9 10 11
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
	{16, 0,16, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
	{ 1,16, 0,16, 0, 0, 0, 0, 0, 0, 0, 1}, // 3
	{16, 0,16,14,16, 0, 0, 0, 0, 0, 0, 1}, // 4
	{ 1,16, 0,16, 0,16, 0, 0, 0, 0, 0, 1}, // 5
	{ 1, 0,16, 0,16, 0, 0, 0, 0, 0, 0, 1}, // 6
	{ 1, 0, 0,16, 0,16, 0, 0, 0, 0, 0, 1}, // 7
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
};

int Map_Hsk[3][9][12] = {
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 1}, // 2
		{ 1, 0, 0, 0, 0, 0, 0,18, 0, 0, 0, 1}, // 3
		{ 1, 0, 2, 0, 0, 0, 0,21,20,14, 0, 1}, // 4
		{ 1, 0, 0, 0, 0, 0, 0,22,19, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	},
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0,18,19, 0, 0, 1}, // 2
		{ 1, 0, 0, 0, 0, 0,18, 0, 0, 0, 0, 1}, // 3
		{ 1, 0, 2, 0, 0, 0,21,20,20,14, 0, 1}, // 4
		{ 1, 0, 0, 0, 0, 0,22,19,19, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	},
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0,18,19,19,16,24, 0, 1}, // 2
		{ 1, 0, 0, 0,18, 0, 0,23, 0,24, 0, 1}, // 3
		{ 1, 0, 2, 0,21,20,20, 0, 0,14, 0, 1}, // 4
		{ 1, 0, 0, 0,22,19,19,19, 0,24, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	}
};

int Map_Psk1[2][9][12] = {
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
		{ 1, 0, 0,21, 0, 0, 0, 0, 0, 0, 0, 1}, // 3
		{ 1, 0, 2,27,29, 0, 0, 0, 0,14, 0, 1}, // 4
		{ 1, 0, 0,28, 0, 0, 0, 0, 0, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
		},
	{
		//0  1  2  3  4  5  6  7  8  9 10 11
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}, // 0
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 1
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 2
		{ 1, 0,16, 0,18, 0, 0, 0, 0, 0, 0, 1}, // 3
		{ 1, 0, 2,27, 0, 0, 0, 0, 0,14, 0, 1}, // 4
		{ 1, 0,18, 0,16, 0, 0, 0, 0, 0, 0, 1}, // 5
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 6
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 7
		{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1}  // 8
	}
};

int Map_Psk2[9][36] = {
	//0  1  2  3  4  5  6  7  8  9 10 11
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2
	{ 1, 0, 0, 0,16, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 3
	{ 1, 0, 2,27,25,26, 0, 0, 0,14, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 4
	{ 1, 0, 0, 0,18, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 5
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 6
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 7
	{ 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}  // 8
};

int Choice[5][2] = {
	{ 0,15},
	{ 0, 0},
	{ 0, 0},
	{ 0, 0},
	{ 0, 0}
};

void drow_M()
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cout << tile[Map_M[i][j]];
		}
		cout << endl;
	}
}

void drow_P()
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cout << tile[Map_P[i][j]];
		}
		cout << endl;
	}
}

int drow_MM(int hy, int hx) // 원의 방정식 응용
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			if (((i - hy) * (i - hy)) + ((j - hx) * (j - hx)) <= 4)
				cout << tile[Map_Maze[i][j]];
			else
				cout << " ";
		}
		cout << endl;
	}
	return 0;
}

void drow_F()
{
	for (int i = 0; i < 9; i++)
	{
		for (int j = 0; j < 12; j++)
		{
			cout << tile[Map_F[i][j]];
		}
		cout << endl;
	}
}

void drow_PAtt()
{
	for (int k = 0; k < 3; k++)
	{
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 12; j++)
			{
				cout << tile[Map_PAtt[k][i][j]];
			}
			cout << endl;
		}
		Sleep(100);
		system("cls");
	}
}

void drow_HAtt()
{
	for (int i = 0; i < 9; i++)
	{
		for (int j = 0; j < 12; j++)
		{
			cout << tile[Map_HAtt[i][j]];
			Sleep(1);
		}
		cout << endl;
	}
}

void drow_menu()
{
	for (int i = 0; i < 5; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (j == 2)
				cout << menu[i];
			else
				cout << tile[Choice[i][j]];
		}
		cout << endl;
	}
}

void Attack_player()
{
	for (int c = 2; c < 9; c++) // 플레이어 몬스터 앞으로 이동
	{
		Map_F[4][c - 1] = 0;
		Map_F[4][c] = 2;
		drow_F();
		drow_menu();
		Sleep(100);
		system("cls");
	}
	drow_PAtt();
	for (int c = 8; c > 1; c--) // 플레이어 제자리 복귀
	{
		if (c != 8)
			Map_F[4][c + 1] = 0;
		Map_F[4][c] = 2;
		drow_F();
		drow_menu();
		Sleep(100);
		system("cls");
	}
}

void Attack_mon()
{
	for (int c = 9; c > 2; c--)
	{
		Map_F[4][c + 1] = 0;
		Map_F[4][c] = 14;
		drow_F();
		Sleep(100);
		system("cls");
	}
	drow_HAtt();
	system("cls");
	for (int c = 3; c < 10; c++)
	{
		if (c != 3)
			Map_F[4][c - 1] = 0;
		Map_F[4][c] = 14;
		drow_F();
		Sleep(100);
		system("cls");
	}
}

void drow_Hsk()
{
	for (int k = 0; k < 3; k++)
	{
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 12; j++)
			{
				cout << tile[Map_Hsk[k][i][j]];
			}
			cout << endl;
		}
		Sleep(150);
		system("cls");
	}
}

void drow_Psk1()
{
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			for (int k = 0; k < 9; k++)
			{
				for (int l = 0; l < 12; l++)
				{
					cout << tile[Map_Psk1[j][k][l]];
				}
				cout << endl;
			}
			if (j == 0)
				cout << "아..";
			else
				cout << "메..";
			Sleep(1000);
			system("cls");
		}
	}
}

void drow_Psk2()
{
	for (int i = 0; i < 30; i++)
	{
		system("cls");
		for (int j = 0; j < 9; j++)
		{
			for (int l = 0; l < 36; l++)
			{
				cout << tile[Map_Psk2[j][l]];
			}
			cout << endl;
		}
		cout << "하";
		for (int l = 0; l < i; l++)
		{
			if (l < 25)
				cout << "아";
			else if (l == 25)
				cout << "악";
			else if (l > 25)
				cout << "!";
		}
		Sleep(30);
		for (int j = 0; j < 9; j++)
		{
			for (int l = 36; l > 0; l--)
			{
				if (Map_Psk2[j][l] == 16)
					Map_Psk2[j][l + 1] = 16;
				else if (Map_Psk2[j][l] == 18)
					Map_Psk2[j][l + 1] = 18;
				else if (Map_Psk2[j][l] == 26)
				{
					if (Map_Psk2[j][l + 1] == 14)
						Map_Psk2[j][l + 2] = 14;
					Map_Psk2[j][l] = 25;
					Map_Psk2[j][l + 1] = 26;
				}
			}
		}
	}
}

void lines(const char* a) // 대화가 간격을 유지하며 나오는 함수
{
	for (int i = 0; i <= strlen(a); i++)
	{
		cout << a[i];
		Sleep(60);
	}
}

class Charac
{
private:
	const char* Name;
	int HP; // 체력
	int Att_stat; // 기본 공격력
	int Apple = 1; // 사과 (HP 10 회복)
public:
	void showstat() // 스탯 보기
	{
		cout << " 이름 : " << Name << endl << " 체력 : " << HP << endl << " 공격력 : " << Att_stat << endl;
	}
	int die() // 사망
	{
		if (HP <= 0)
			return 0;
		else
			return 1;
	}
	void die_txt()
	{
		cout << Name;
		lines("(은)는 사망했다.");
	}
	void apple_txt1()
	{
		Apple--;
		HP += 10;
		cout << Name;
		lines("(은)는 사과를 먹고 체력을 10 회복했다.");
		cout << endl << Name;
		lines("의 사과는");
		cout << Apple;
		lines("개가 남았다.");
	}
	void apple_txt2()
	{
		lines("아이템이 존재하지 않는다.");
	}
	void initstat(const char* name, int hp, int att_s)
	{
		Name = name;
		HP = hp;
		Att_stat = att_s;
	}

	int Attack() // 공격
	{
		cout << Name;
		lines("(이)가");
		return Att_stat;
	}
	void damage(int dam) // 피격
	{
		cout << Name;
		lines("(을)를 공격했다!");
		cout << endl;
		Sleep(500); // 피격 모션
		cout << Name;
		lines("(은)는");
		cout << dam;
		lines("의 피해를 입었다.");
		cout << endl;
		cout << "...SPACE" << endl;
		if (HP >= dam)
			HP -= dam;
		else
			HP = 0;
		die();
	}
	void run()
	{
		cout << Name;
		lines("(은)는 도망치는데");
	}
	int apple()
	{
		if (Apple >= 1)
			return 0;
	}
	void HPbar()
	{
		for (int q = 0; q < 4; q++) {
			if (q == 0)
				cout << Name << "의 HP";
			else {
				for (int w = 0; w < 13; w++) {
					if (q == 1) {
						if (w == 0)
							cout << " ";
						else if (w == 1)
							cout << "┌";
						else if (w == 12)
							cout << "┐";
						else
							cout << "──";
					}
					else if (q == 2) {
						if (w == 0)
							cout << " ";
						else if (w == 1 || w == 12)
							cout << "│";
						else if (w <= HP / 10 + 1)
							cout << "■";
						else
							cout << " ";
					}
					else if (q == 3) {
						if (w == 0)
							cout << " ";
						else if (w == 1)
							cout << "└";
						else if (w == 12)
							cout << "┘";
						else
							cout << "──";
					}
				}
			}
			cout << endl;
		}
	}
	int skill()
	{
		cout << Name;
		lines("(이)가");
		return Att_stat * 2;
	}
	int Hskill()
	{
		if (HP > 10)
		{
			lines("스킬 사용 준비가 되지 않았습니다.");
			cout << endl;
			lines("체력이 10 이하 일때 잠금이 해제됩니다.");
			cout << endl;
			return 0;
		}
	}
};

void move()
{
	int hx = 1, hy = 1;
	Map_M[hy][hx] = 2;
	drow_M();
	while (1) // 유저 움직임
	{

		if (_kbhit())
		{
			int input = _getch();
			Map_M[hy][hx] = 0;
			if (input == U && Map_M[hy - 1][hx] != 1)
			{
				if (Map_M[hy - 1][hx] == 3)
					break;
				hy--;
			}
			else if (input == D && Map_M[hy + 1][hx] != 1)
			{
				if (Map_M[hy + 1][hx] == 3)
					break;
				hy++;
			}
			else if (input == L && Map_M[hy][hx - 1] != 1)
			{
				if (Map_M[hy][hx - 1] == 3)
					break;
				hx--;
			}
			else if (input == R && Map_M[hy][hx + 1] != 1)
			{
				if (Map_M[hy][hx + 1] == 3)
					break;
				hx++;
			}
			Map_M[hy][hx] = 2;
			system("cls");
			drow_M();
		}
	}
}

void puzzle()
{
	int a[8], s = 0, hy = 1, hx = 2, n;
	srand(time(NULL));
	Map_P[hy][hx] = 2;
	for (int i = 0; i < 8; i++)
	{
		a[i] = i + 4;
	}
	for (int i = 0; i < 30; i++) // 숫자 섞기
	{
		int r = rand() % 6;
		int b = a[r];
		a[r] = a[r + 1];
		a[r + 1] = b;
	}
	for (int i = 4; i < 7; i++) // 4. ,4,5 - 5. 3,4,5, - 6. 3,4,5
	{
		for (int j = 3; j < 6; j++) // 4. 3,4,5 5. 3,4,5, 6. 3,4,5 n : 0 ~ 8
		{
			if (s != 0)
				Map_P[i][j] = a[s - 1];
			s++;
		}
	}
	s = 0;
	drow_P();
	while (1)
	{
		if (_kbhit())
		{
			int input = _getch();
			Map_P[hy][hx] = 0;
			if (input == U && Map_P[hy - 1][hx] != 1 && Map_P[hy - 1][hx] != 3)
			{
				if (3 < Map_P[hy - 1][hx] < 12)
					Map_P[hy][hx] = Map_P[hy - 1][hx];
				if (Map_P[4][3] == 4 && Map_P[4][4] == 5 && Map_P[4][5] == 6 && Map_P[5][3] == 7 && Map_P[5][4] == 8 && Map_P[5][5] == 9 && Map_P[6][3] == 10 && Map_P[6][4] == 11 && s == 0) {
					Map_P[6][7] = 0;
					s++;
					lines("돌들을 제자리에 맞추니 나무가 사라지며 보이지 않던 길이 나타났다.");
					cout << endl;
					cout << "...SPACE" << endl;
					Sleep(500);
					n = _getch();
				}
				if (Map_P[hy - 1][hx] == 12)
					break;
				hy--;
			}
			else if (input == D && Map_P[hy + 1][hx] != 1 && Map_P[hy + 1][hx] != 3)
			{
				if (3 < Map_P[hy + 1][hx] < 12)
					Map_P[hy][hx] = Map_P[hy + 1][hx];
				if (Map_P[4][3] == 4 && Map_P[4][4] == 5 && Map_P[4][5] == 6 && Map_P[5][3] == 7 && Map_P[5][4] == 8 && Map_P[5][5] == 9 && Map_P[6][3] == 10 && Map_P[6][4] == 11 && s == 0) {
					Map_P[6][7] = 0;
					s++;
					lines("돌들을 제자리에 맞추니 나무가 사라지며 보이지 않던 길이 나타났다.");
					cout << endl;
					cout << "...SPACE" << endl;
					Sleep(500);
					n = _getch();
				}
				if (Map_P[hy + 1][hx] == 12)
					break;
				hy++;
			}
			else if (input == L && Map_P[hy][hx - 1] != 1 && Map_P[hy][hx - 1] != 3)
			{
				if (3 < Map_P[hy][hx - 1] < 12)
					Map_P[hy][hx] = Map_P[hy][hx - 1];
				if (Map_P[4][3] == 4 && Map_P[4][4] == 5 && Map_P[4][5] == 6 && Map_P[5][3] == 7 && Map_P[5][4] == 8 && Map_P[5][5] == 9 && Map_P[6][3] == 10 && Map_P[6][4] == 11 && s == 0) {
					Map_P[6][7] = 0;
					s++;
					lines("돌들을 제자리에 맞추니 나무가 사라지며 보이지 않던 길이 나타났다.");
					cout << endl;
					cout << "...SPACE" << endl;
					Sleep(500);
					n = _getch();
				}
				if (Map_P[hy][hx - 1] == 12)
					break;
				hx--;
			}
			else if (input == R && Map_P[hy][hx + 1] != 1 && Map_P[hy][hx + 1] != 3)
			{
				if (3 < Map_P[hy][hx + 1] < 12)
					Map_P[hy][hx] = Map_P[hy][hx + 1];
				if (Map_P[4][3] == 4 && Map_P[4][4] == 5 && Map_P[4][5] == 6 && Map_P[5][3] == 7 && Map_P[5][4] == 8 && Map_P[5][5] == 9 && Map_P[6][3] == 10 && Map_P[6][4] == 11 && s == 0) {
					Map_P[6][7] = 0;
					s++;
					lines("돌들을 제자리에 맞추니 나무가 사라지며 보이지 않던 길이 나타났다.");
					cout << endl;
					cout << "...SPACE" << endl;
					Sleep(500);
					n = _getch();
				}
				if (Map_P[hy][hx + 1] == 12)
					break;
				hx++;
			}
			Map_P[hy][hx] = 2;
			system("cls");
			drow_P();
		}
	}
}

void Maze()
{
	int hy = 1, hx = 0;
	Map_Maze[hy][hx] = 2;
	drow_MM(hy, hx);
	while (1)
	{
		if (_kbhit())
		{
			int input = _getch();
			Map_Maze[hy][hx] = 0;
			if (input == U && Map_Maze[hy - 1][hx] != 13)
			{
				if (Map_Maze[hy - 1][hx] == 12)
					break;
				hy--;
			}
			else if (input == D && Map_Maze[hy + 1][hx] != 13)
			{
				if (Map_Maze[hy + 1][hx] == 12)
					break;
				hy++;
			}
			else if (input == L && Map_Maze[hy][hx - 1] != 13)
			{
				if (Map_Maze[hy][hx - 1] == 12)
					break;
				hx--;
			}
			else if (input == R && Map_Maze[hy][hx + 1] != 13)
			{
				if (Map_Maze[hy][hx + 1] == 12)
					break;
				hx++;
			}
			Map_Maze[hy][hx] = 2;
			system("cls");
			drow_MM(hy, hx);
		}
	}
}

int over; // 0 : 플레이어 이김, 1 : 플레이어 도망침, 2 : 적 이김
void fight()
{
	srand(time(NULL)); // 도망가기, 호랑이 턴의 랜덤 확률
	Charac Yong;
	Yong.initstat("나", 100, 10);
	Charac Horang2;
	Horang2.initstat("호랑이", 100, 20);
	int cy = 0, n, turn = 1, run;
	drow_F();
	drow_menu();
	Yong.HPbar();
	Horang2.HPbar();
	while (1)
	{
		if (Yong.die() == 0) {
			Yong.die_txt();
			over = 2;
			break;
		}
		else if (Horang2.die() == 0) {
			Horang2.die_txt();
			over = 0;
			break;
		}
		if (_kbhit())
		{
			int input = _getch();
			Choice[cy][1] = 0;
			if (input == U)
			{
				if (cy == 0)
					cy = 4;
				else
					cy--;
			}
			else if (input == D)
			{
				if (cy == 4)
					cy = 0;
				else
					cy++;
			}
			else if (input == S)
			{
				if (cy == 0) // 공격하기
				{
					system("cls");
					Attack_player();
					drow_F();
					drow_menu();
					Horang2.damage(Yong.Attack());
					Yong.HPbar();
					Horang2.HPbar();

					turn = 0;
					n = _getch();
				}
				else if (cy == 1) // 스킬 사용
				{
					if (Yong.Hskill() == 0) {
						void Hskill();
						cout << "...SPACE" << endl;
						n = _getch();
						system("cls");
					}
					else {
						system("cls");
						drow_F();
						drow_menu();
						lines("스킬 잠금해제 조건이 완료되어");
						Yong.skill();
						lines("스킬을 사용합니다.");
						cout << endl;
						cout << "...SPACE" << endl;
						n = _getch();
						system("cls");
						drow_Psk1();
						drow_Psk2();
						over = 0;
						break;
					}
				}
				else if (cy == 2) // 아이템 사용
				{
					if (Yong.apple() == 0) {
						Yong.apple_txt1();
						n = _getch();
						turn = 0;
					}
					else {
						Yong.apple_txt2();
						cout << "...SPACE" << endl;
						n = _getch();
					}
				}
				else if (cy == 3) // 스테이터스 보기
				{
					system("cls");
					cout << "    스테이터스 >>" << endl << endl;
					Yong.showstat();
					cout << endl << " 돌아가기 SPACE   다음 ->" << endl;
					while (1)
					{
						if (_kbhit())
						{
							int input1 = _getch();
							if (input1 == R)
							{
								system("cls");
								cout << " << 스테이터스 " << endl << endl;
								Horang2.showstat();
								cout << endl << " 이전 <- 돌아가기 SPACE" << endl;

							}
							else if (input1 == L)
							{
								system("cls");
								cout << "    스테이터스 >>" << endl << endl;
								Yong.showstat();
								cout << endl << " 돌아가기 SPACE   다음 ->" << endl;
							}
							else if (input1 == S)
								break;
						}
					}
				}
				else if (cy == 4) // 도망치기
				{
					run = rand() % 100;
					if (run < 5) // 5% 확률로 도망치기 성공 
					{
						Yong.run();
						lines("성공했다!");
						cout << endl;
						cout << "...SPACE" << endl;
						over = 1;
						n = _getch();
						break;
					}
					else {
						Yong.run();
						lines("실패했다!");
						cout << endl;
						cout << "...SPACE" << endl;
						n = _getch();
					}
					turn = 0;
				}
			}
			Choice[cy][1] = 15;
			system("cls");
			drow_F();
			drow_menu();
			Yong.HPbar();
			Horang2.HPbar();
			if (turn == 0) // 나의 턴이 끝나면 턴넘김  (호랑이 턴)
			{
				int ho = rand() % 100;
				if (ho < 70) // 기본 공격
				{
					system("cls");
					Attack_mon();
					drow_F();
					Yong.damage(Horang2.Attack());
					Yong.HPbar();
					Horang2.HPbar();
					if (Yong.die() == 0) {
						break;
					}
					n = _getch();
					turn = 1;
				}
				else if (70 <= ho < 90) // 스킬 사용
				{
					system("cls");
					drow_Hsk();
					drow_F();
					lines("메(HO)후 스킬을 사용한");
					Yong.damage(Horang2.skill());
					Yong.HPbar();
					Horang2.HPbar();
					n = _getch();
					turn = 1;
				}
				else if (ho >= 90) // 아이템 사용
				{
					if (Horang2.apple() == 0) {
						Horang2.apple_txt1();
						n = _getch();
					}
					else {
						Horang2.apple_txt2();
						cout << "...SPACE" << endl;
						n = _getch();
					}
					turn = 0;
				}
				system("cls");
				drow_F();
				drow_menu();
				Yong.HPbar();
				Horang2.HPbar();
			}
		}
	}
}

void ending()
{
	Charac Yong;
	Charac Horang2;
	if (over == 0) // 0 : 플레이어 이김 (호랑이 사망)
	{
		Yong.skill();
		lines("적을 물리치고 집으로 무사히 돌아갔다.");
	}
	else if (over == 1) // 1 : 플레이어 도망침
	{
		Yong.skill();
		lines("도망에 성공하고 집으로 무사히 돌아갔다.");
	}
	else if (over == 2) // 2 : 적 이김 (플레이어 사망)
	{
		Yong.skill();
		lines("사망했다.");
		cout << endl;
		lines("끝내 집으로 돌아갈수는 없었다.");
	}
}

void story1()
{
	int n;
	lines("나는 숲속에서 길을 잃었다.");
	Sleep(500);
	cout << endl;
	lines("저기에 쉽지않은 기운을 가진 할아버지가 있다.");
	Sleep(500);
	cout << endl;
	lines("말을 걸어보자.");
	Sleep(500);
	cout << endl;
	cout << "...SPACE" << endl;
	Sleep(500);
	n = _getch();
	system("cls");
	move();
}

void story2()
{
	int n;
	lines("나 : 숲을 나가는 길을 아십니까?");
	cout << endl;
	Sleep(500);
	lines("정체모를 할아버지 : 저돌들을 치우고 내려가면 숲을 빠져나갈수 있을거야");
	cout << endl;
	cout << "...SPACE" << endl;
	Sleep(500);
	n = _getch();
	system("cls");
	puzzle();
	n = _getch();
}

void story3()
{
	int n;
	lines("돌들을 무사히 치우고 나니 동굴이 나왔다.");
	cout << endl;
	Sleep(500);
	lines("무섭지만 다시 돌아가기엔 너무 늦었다 들어가보자.");
	cout << endl;
	cout << "...SPACE" << endl;
	Sleep(500);
	n = _getch();
	system("cls");
	Maze();
	n = _getch();
}

void story4()
{
	int n;
	lines("무사히 동굴에서 빠져나왔다.");
	cout << endl;
	Sleep(500);
	lines("나 : 잠시만 저..");
	Sleep(500);
	lines("저건...?!?!");
	cout << endl;
	cout << "...SPACE" << endl;
	Sleep(500);
	n = _getch();
	lines("나 : 호랑이...?!?!?!?!?!?!?!!!");
	cout << endl;
	Sleep(500);
	lines("그렇게 호랑이와의 전투가 시작되었다.");
	cout << "...SPACE" << endl;
	Sleep(500);
	n = _getch();
	system("cls");
	fight();
}

int main() {
	removecursor();
	story1();
	story2();
	story3();
	story4();
	ending();

	return 0;
}

0개의 댓글