0415 미로탈출 과제 미완성
#include 
#include <conio.h>
using namespace std;
struct tile
{
string fore;
string swa;
string fla;
};
struct player
{
};
int main()
{
//실습.
//	10*10 크기의 맵을 구상.
//	플레이어(시작지점(0,0))가 존재
//	탈출지점이 존재한다.
//	WASD 키입력을 통해 플레이어를 이동시킨다.
//	탈출지점은 (0,0)을 제외하고 랜덤 설정
//	O(플레이어)가 E(탈출구)에 도달하면 "탈출에 성공했습니다." 프로그램 종료
//	system("cls"); // 화면 지우는 명령어//맵 초기화
srand(time(NULL));
char map[10][10];
int player_x = 0;
int player_y = 0;
int	exit_x = rand() % 9 + 1;
int	exit_y = rand() % 9 + 1;
int tile_x = rand() % 9 + 1;
int tile_y = rand() % 9 + 1;
int chance = 20;
//맵 구성
	//플레이어
for (int i = 0; i < 10; i++)
{
	for (int j = 0; j < 10; j++)
	{
		map[i][j] = '#';
	}
}
for (int i = 0; i < 20; i++)
{
	tile_x = rand() % 9 + 1;
	tile_y = rand() % 9 + 1;
	map[tile_x][tile_y] = '$';
}
	map[exit_x][exit_y] = 'E';
	//맵 속성
	/*tile map1;*/
//map1: rand() % 2 + 1;
//	map1.fore = " 숲";
//	map1.fla = "평지";
//	map1.swa = "늪";
	//탈출 지점과 플레이어 지점 비교
	while (1)
	{
		map[player_x][player_y] = 'P';
		system("cls");
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				cout << map[i][j];
			} cout << endl;
		}
		cout << "플레이어 좌표 : " << player_x << player_y << endl;
		cout << "탈출구 좌표" << exit_x << exit_y << endl;
		cout << "피로도" << chance << endl;
		if (player_x == exit_x && player_y == exit_y) // 탈출지점
		{
			cout << "종료되었습니다.";
			break;
		}
		//탈출구
		// 키 움직임
		switch (_getch())
		{
		case 'w':
			map[player_x][player_y] = '#';
			player_x -= 1;
			if (player_x < 0)
			{
				player_x = 0;
			}
			break;
		case 'a':
			map[player_x][player_y] = '#';
			player_y -= 1;
			if (player_y < 0)
			{
				player_y = 0;
			}
			break;
		case 's':
			map[player_x][player_y] = '#';
			player_x += 1;
			if (player_x > 9)
			{
				player_x = 9;
			}
			break;
		case 'd':
			map[player_x][player_y] = '#';
			player_y += 1;
			if (player_y > 9)
			{
				player_y = 9;
			}
			break;
		default:
			break;
		}
		if (chance == 0)
		{
			cout << "피로가 쌓였습니다.";
			break;
		}
	}}
Author And Source
이 문제에 관하여(0415 미로탈출 과제 미완성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@1124mw/0415-미로탈출-과제-미완성저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)