当前位置: 首页 > news >正文

自制迷宫游戏 c++

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

#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"|---------------------|"};//18int 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;
}

http://www.lryc.cn/news/401298.html

相关文章:

  • 基于复旦微JFMQL100TAI的全国产化FPGA+AI人工智能异构计算平台,兼容XC7Z045-2FFG900I
  • 【数学建模】技术革新——Lingo的使用超详解
  • LLM-阿里 DashVector + langchain self-querying retriever 优化 RAG 实践【Query 优化】
  • 【python】PyQt5的窗口界面的各种交互逻辑实现,轻松掌控图形化界面程序
  • DockerCompose介绍,安装,使用
  • N叉树的前序遍历
  • Linux C++ 054-设计模式之外观模式
  • Linux - 冯-诺依曼体系结构、初始操作系统
  • 成功适配!极验设备指纹HarmonyOS 鸿蒙版官方下载
  • 【C++】字符串学习 知识点+代码记录
  • 尝试理解docker网络通信逻辑
  • 数据仓库哈哈
  • K最近邻(K-Nearest Neighbors, KNN)
  • 深度学习损失计算
  • 论文翻译:通过云计算对联网多智能体系统进行预测控制
  • Java核心(五)多线程
  • IDEA快速生成项目树形结构图
  • 【CPO-TCN-BiGRU-Attention回归预测】基于冠豪猪算法CPO优化时间卷积双向门控循环单元融合注意力机制
  • 面试高级 Java 工程师:2024 年的见闻与思考
  • 设计模式大白话之装饰者模式
  • 动手学深度学习6.3 填充和步幅-笔记练习(PyTorch)
  • 函数的形状怎么定义?
  • Windows 虚拟机服务器项目部署
  • JDBC(2)基础篇2——增删改查及常见问题
  • JVM知识点梳理
  • 产品经理-一份标准需求文档的8个模块(14)
  • 如何用一个例子向10岁小孩解释高并发实时服务的单线程事件循环架构
  • 如何为帕金森病患者选择合适的步行辅助设备?
  • 【排序算法】1.冒泡排序-C语言实现
  • Unity最新第三方开源插件《Stateful Component》管理中大型项目MonoBehaviour各种序列化字段 ,的高级解决方案