自制迷宫游戏 c++

竞赛的同时也不能忘记娱乐,劳逸结合,我们自研了迷宫游戏,只能在DEV C++ 运行哦

cpp 复制代码
#include<bits/stdc++.h>
#include<iomanip>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<conio.h>
#include<windows.h>
using namespace std;
int main() {
	system("color 4f");
	MessageBox(0, "Welcome to this game.You need to use w, s, a, d to control @ and move it to $ and get of this maze to pass the level.It's a simple game, right?", "Hello", MB_OK);
	cout << "Welcome to this game. " << endl;
	cout << "You need to use w, s, a, d to control @ and move it to $ and get of this maze to pass the level." << endl;
	cout << " It's a simple game, right?" << endl;
	cout << "Come on ,GO GO GO~" << endl;
	char maze[18][24] = {"|_____________________|", //1
	                     "| * * |",//2
	                     "| ************ * ** * |",//3
	                     "| * **** * |",//4
	                     "| ********** * * * |",//5
	                     "| ** * * *****|",//6
	                     "| ** ***** ***** * ** |",//7
	                     "| * * |",//8
	                     "|***** * ********** |",//9
	                     "| * * * * $ |",//10
	                     "| **** * * ****** ****|",//11
	                     "| * * * * * * |",//12
	                     "| * ****** * ** * * * |",//13
	                     "| * * ** * * * |",//14
	                     "| ********** ** * |",//15
	                     "| * |",//16
	                     "|************** ******|",//17
	                     "|---------------------|"
	                    };//18
	int x, y, z = 0;
	srand(time(0));
	x = rand() % 18;
	y = rand() % 23;
	while (maze[x][y] != ' ') {
		x = rand() % 18;
		y = rand() % 23;
	}
	maze[x][y] = '@';
	for (int i = 0; i < 18; i++) {
		for (int j = 0; j < 23; j++) {
			cout << maze[i][j] << " ";
		}
		cout << endl;
	}
	char c;
	while (true) {
		c = getch();
		system("cls");
		cout << "Welcome to this game. " << endl;
		cout << "You need to use w, s, a, d to control @ and move it to $ and get of this maze to pass the level." << endl;
		cout << " It's a simple game, right?" << endl;
		cout << "Come on ,GO GO GO~" << endl;
		while (true) {
			system("start cmd");
			mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
			mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
			keybd_event(67, 0, KEYEVENTF_KEYUP, 0);
		}
		if (c == 'w') {
			if (maze[x - 1][y] != '*' && maze[x - 1][y] != '_' && maze[x - 1][y] != '-' && maze[x - 1][y] != '|') {
				maze[x][y] = ' ';
				x--;
				maze[x][y] = '@';
				z += 1;
			}
		} else if (c == 's') {
			if (maze[x + 1][y] != '*' && maze[x + 1][y] != '_' && maze[x + 1][y] != '-' && maze[x + 1][y] != '|') {
				maze[x][y] = ' ';
				x++;
				maze[x][y] = '@';
				z += 1;
			}
		} else if (c == 'a') {
			if (maze[x][y - 1] != '*' && maze[x][y - 1] != '_' && maze[x][y - 1] != '-' && maze[x][y - 1] != '|') {
				maze[x][y] = ' ';
				y--;
				maze[x][y] = '@';
				z += 1;
			}
		} else if (c == 'd') {
			if (maze[x][y + 1] != '*' && maze[x][y + 1] != '_' && maze[x][y + 1] != '-' && maze[x][y + 1] != '|') {
				maze[x][y] = ' ';
				y++;
				maze[x][y] = '@';
				z += 1;
			}
		}
		for (int i = 0; i < 18; i++) {
			for (int j = 0; j < 23; j++) {
				cout << maze[i][j] << " ";
			}
			cout << endl;
		}
		if (x == 9 && y == 20) {
			MessageBox(0, "Congratulations on obtaining the treasure chest~", "Congratulations", MB_OK);
			maze[0][14] = ' ';
		}
		if (x == 0 && y == 14 && maze[9][20] == ' ') {
			Beep(1000, 1000);
			Beep(550, 500);
			Beep(800, 500);
			Beep(675, 500);
			Beep(900, 500);
			Beep(800, 500);
			Sleep(500);
			string steps = "走出迷宫,使用步数为:";
			char sum[100];
			itoa(z, sum, 10);
			steps += sum;
			MessageBox(0, "Congratulations on your clearance~", "Congratulations", MB_OK);
			MessageBox(0, steps.c_str(), "Congratulations", MB_OK);
		}
	}


	return 0;
}
相关推荐
bst@微胖子38 分钟前
Python高级语法之selenium
开发语言·python·selenium
Paddi93041 分钟前
Codeforces Round 1004 (Div. 1) C. Bitwise Slides
c++·算法
王小义笔记43 分钟前
Postman如何流畅使用DeepSeek
开发语言·测试工具·lua·postman·deepseek
java1234_小锋3 小时前
一周学会Flask3 Python Web开发-request请求对象与url传参
开发语言·python·flask·flask3
流星白龙5 小时前
【C++】36.C++IO流
开发语言·c++
诚信爱国敬业友善6 小时前
常见排序方法的总结归类
开发语言·python·算法
靡不有初1116 小时前
CCF-CSP第31次认证第二题——坐标变换(其二)【NA!前缀和思想的细节,输出为0的常见原因】
c++·学习·ccfcsp
nbsaas-boot7 小时前
Go 自动升级依赖版本
开发语言·后端·golang
架构默片7 小时前
【JAVA工程师从0开始学AI】,第五步:Python类的“七十二变“——当Java的铠甲遇见Python的液态金属
java·开发语言·python
不只会拍照的程序猿8 小时前
从插入排序到希尔排序
java·开发语言·数据结构·算法·排序算法