自制迷宫游戏 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;
}
相关推荐
何曾参静谧2 分钟前
「Py」Python基础篇 之 Python都可以做哪些自动化?
开发语言·python·自动化
Prejudices6 分钟前
C++如何调用Python脚本
开发语言·c++·python
单音GG9 分钟前
推荐一个基于协程的C++(lua)游戏服务器
服务器·c++·游戏·lua
我狠狠地刷刷刷刷刷19 分钟前
中文分词模拟器
开发语言·python·算法
wyh要好好学习22 分钟前
C# WPF 记录DataGrid的表头顺序,下次打开界面时应用到表格中
开发语言·c#·wpf
AitTech23 分钟前
C#实现:电脑系统信息的全面获取与监控
开发语言·c#
qing_04060325 分钟前
C++——多态
开发语言·c++·多态
孙同学_25 分钟前
【C++】—掌握STL vector 类:“Vector简介:动态数组的高效应用”
开发语言·c++
froginwe1126 分钟前
XML 编辑器:功能、选择与使用技巧
开发语言
Jam-Young32 分钟前
Python的装饰器
开发语言·python