C++迷宫小游戏,无聊时写来练手的,大佬勿喷

这是一款C++编写的迷宫闯关小游戏,作者分享了从V1.3.0到V1.4.2的更新历程,包括新增商店、技能、存档检测、探索模式等功能,并修复了多个BUG,优化了游戏体验。游戏代码和编译环境也一并提供。
摘要由CSDN通过智能技术生成

迷宫闯关 V1.4.2 !

  • 第一次打小游戏,做的不好请见谅!~

V1.3.x

  • 加入了商店,并对游玩体验进行了优化

V1.3.0 (2023/8/6)

  1. 加入了“技能”和“商店”功能
  2. 将炸弹和地雷爆炸设定为连锁反应
  3. 进一步优化代码长度

V1.3.1

  1. 修复了炸弹被多次引爆的问题
  2. 修复了地图左下角总是出现空位,导致爆炸输出越界的问题
  3. 修复了不经常自动存档的问题
  4. 修复了在收集血包时可以无限加血的问题
  5. 修复了炸弹爆炸时加血和加分会再次调用的问题
  6. 修复了已开启但未通过第五关时商店就解锁的问题

V1.3.2

  1. 加入了存档问题检测,使随意更改存档成为过去
  2. 加入了技能面板
  3. 进一步优化代码长度

V1.3.3.1 (2023/8/8)

  1. 加入了消耗品商店,可购买血包和技能体验卡
  2. 加入了当铺,可以用来倒卖消耗品
  3. 优化了技能面板
  4. 进一步优化了代码长度,并修改了大量已知 B U G BUG BUG,优化了游玩体验

小修改

  1. 提高了技能的价格
  2. H a r d Hard Hard 模式下通过第 3 3 3 关就可以解锁商店

V1.3.4

  1. 在中等和困难模式中加入 5 × 5 5 \times 5 5×5 的大炸弹
  2. 大炸弹的爆炸范围内的碎砖墙可能发生破碎
  3. 将炸弹伤害与距离爆炸中心的距离挂钩

小修改

  1. 降低了爆炸产生碎砖墙的概率

V1.4

  • 加入了探索模式。

V1.4.0 (2023/8/26)

  1. 加入了探索模式,将原先的正常迷宫归入扫荡模式(通关后才能进入扫荡模式)。
  2. 修复了已知 B U G BUG BUG

V1.4.1.3

  1. 加入了“地毯”。
  2. 将未失明时的地图探索做出了一点小更改。
  3. 优化了代码长度并修复了已知 B U G BUG BUG

V1.4.2 (2023/9/22)

  1. 加入键位修改功能。
  2. 更改每一关的胜利界面的小细节(没法直接进入商店了)。
  3. 将部分按键改为平滑检测。
  4. 修复了已知 B U G BUG BUG

代码啥的

话不多说,直接上 游戏代码

代码

#include <bits/stdc++.h>
#include <windows.h>
#define maxn 20
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1 : 0)
using namespace std;

int mp[200][200] = {
   0}, rx, ry, score = 0, blood = 10, bao = 0, sgless;
int nandu, op[10] = {
   0}, boomm[100] = {
   0}, len = 1, rlen = 1, facing;
int costsco[maxn] = {
   0, 40, 30, 50, 40, 25, 20, 15, 10, 20, 15};
int needblo[maxn] = {
   0, 1, 4, 0, -1, -2, 1, 4, 0, -1};
int dir[5][2] = {
   {
   0, 0}, {
   0, -1}, {
   -1, 0}, {
   0, 1}, {
   1, 0}}, have[maxn];
char whichkey[] = {
   'Q', 'Z', 'X', 37, 38, 39, 40, 'A', 'W', 'D', 'S'};
bool issg, isopen, isup[260];
float xt = 0;
string thisgamename;
char keyname[260][60] = {
   "", "鼠标左键", "鼠标右键", "[Ctrl]+[Break]",
                         "鼠标中键", "X1 鼠标按钮", "X2 鼠标按钮", "", "[Backspace]", "[Tab]", "", "",
                         "[Clear]", "[Enter]", "", "", "[Shift]", "[Ctrl]", "[Alt]", "[Pause]",
                         "[CapsLock]", "", "", "", "", "", "", "[Esc]", "", "", "", "", "[Space]",
                         "[PageUp]", "[PageDown]", "[End]", "[Home]", "[Left]", "[Up]", "[Right]",
                         "[Down]", "[Select]", "[Print]", "[Execute]", "[PrintScreen]", "[Insert]",
                         "[Delete]", "[Help]", "[0]", "[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]",
                         "[8]", "[9]", "", "", "", "", "", "", "", "[A]", "[B]", "[C]", "[D]", "[E]",
                         "[F]", "[G]", "[H]", "[I]", "[J]", "[K]", "[L]", "[M]", "[N]", "[O]", "[p]",
                         "[Q]", "[R]", "[S]", "[T]", "[U]", "[V]", "[W]", "[X]", "[Y]", "[Z]", "左[Win]",
                         "右[Win]", "[App]", "", "[Sleep]", "小键盘[0]", "小键盘[1]", "小键盘[2]",
                         "小键盘[3]", "小键盘[4]", "小键盘[5]", "小键盘[6]", "小键盘[7]", "小键盘[8]",
                         "小键盘[9]", "[×]", "[+]", "[分隔符]", "[-]", "[Dec]", "[/]", "[F1]", "[F2]",
                         "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]", "[F11]",
                         "[F12]", "[F13]", "[F14]", "[F15]", "[F16]", "[F17]", "[F18]", "[F19]", "[F20]",
                         "[F21]", "[F22]", "[F23]", "[F24]", "", "", "", "", "", "", "", "", "[NumLock]",
                         "[ScrollLock]", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "左[Shift]", "右[Shift]", "左[Ctrl]", "右[Ctrl]", "左[Alt]", "右[Alt]", "", "", "", "",
                         "", "", "", "静音", "音量减小", "音量增加", "下一首", "上一首", "停止", "播放/暂停",
                         "启动邮件", "选择媒体", "启动应用程序_1", "启动应用程序_2", "", "", "[;]",
                         "[+]", "[,]", "[-]", "[.]", "[/]", "[~]", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "[{]", "[\\]",
                         "[}]", "[']", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "[Attn]", "[CrSel]", "[ExSel]", "[ErEOF]", "播放键",
                         "缩放键", "", "[PA1]", "清除键"
                        };

struct blk {
   
	char ch[3];
	int clr;
	blk (const char *s = "  ", int a = 7) {
   
		ch[0] = s[0], ch[1] = s[1], ch[2] = '\0', clr = a;
	}
} blocks[11];

struct node {
   
	int x, y;
};
queue<node> boom;

inline void color(int a) {
   
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}

inline void gto(int x, int y) {
   
	COORD pos;
	pos.X = y;
	pos.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

bool new_game(), cundang(), read(string name), game(), to_start();
bool checkup(int x, int y, int n), whichmod(int n), notwall(int x, int y);
bool isair(int x, int y);
int gq(int n, bool mod), rnk(int x, bool y = 1);
void start(), jiaocheng(), shop(), jinengshop(), scoshop(), huishou();
void whichxitong(), dlt(string name), all_clear(), sout(string a, int t);
void update(int x), manout(int n), mpout(int n, bool mod), goofput(int rx, int ry);
void lose(int num), win(), addvis(int n), boardout(int n), prt(int x, int y);
void booom(int n, bool mod), boomclear(), mpout(int x, int y, bool isbig, bool mod);
void save(string name), look(int n, bool mod), go_though(int x, int y, int n);
void addop(int x, int y, int n, int face), setkey(), change(int x);

void whichxitong() {
   
	typedef void(__stdcall * NTPROC)(DWORD *, DWORD *, DWORD *);
	HINSTANCE hinst = LoadLibrary("ntdll.dll");
	DWORD dwMajor, dwMinor, dwBuildNumber;
	NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
	proc(&dwMajor, &dwMinor, &dwBuildNumber);
	if (dwMajor == 10 && dwMinor == 0) {
   
		xt = 10;
		return ;
	}
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	OSVERSIONINFOEX os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	if (GetVersionEx((OSVERSIONINFO *)&os)) {
   
		if (os.dwMajorVersion == 6 && os.wProductType == VER_NT_WORKSTATION) {
   
			xt = 7;
		}
	}
}

int main() {
   
	srand((unsigned)time(NULL));
	blocks[6] = blocks[0] = {
   "  ", 238};
	blocks[4] = blocks[3] = blocks[1] = {
   "  ", 119};
	blocks[2] = {
   "!!", 27};
	blocks[10] = blocks[5] = {
   "[]", 236};
	blocks[7] = {
   "☆", 231};
	blocks[8] = {
   "☆", 236};
	blocks[9] = {
   "国", 120};
	for (int i = 1; i <= 256; i++) {
   
		if (!KEY_DOWN(i)) {
   
			isup[i] = 1;
		}
	}
	start();
	return 0;
}

bool read(string name) {
   
	string str = name + ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < str.size(); i++) {
   
		ch[i] = str[i];
	}
	char *s = ch;
	FILE *fp = fopen(s, "r");
	fscanf(fp, "%d%d%d%d", &nandu, &blood, &bao, &score);
	bool isold = 0;
	unsigned long long hsh = rnk(nandu, 0) + rnk(blood, 0) + rnk(bao, 0) + rnk(score, 0), thehsh;
	for (int i = 0; i < 10; i++) {
   
		fscanf(fp, "%d", op + i);
		hsh += rnk(op[i], 0);
	}
	for (int i = 1; i < maxn; i++) {
   
		if (fscanf(fp, "%d", have + i) == EOF) isold = 1, have[i] = 0;
		hsh += rnk(have[i], 0);
	}
	have[5] = bao;
	int a = 0;
	if (fscanf(fp, "%d", &a) == EOF) {
   
		isold = 1, isopen = 0;
	} else {
   
		isopen = ((a || (nandu == 3 ? op[4] : op[6])) ? 1 : 0);
	}
	hsh += rnk(isopen, 0);
	for (int i = 0; i <= 10; i++) {
   
		if (fscanf(fp, "%d", &a) == EOF) isold = 1;
		else whichkey[i] = a;
		hsh += rnk(whichkey[i], 0);
	}
	if (fscanf(fp, "%llu", &thehsh) == EOF) isold = 1;
	fclose(fp);
	if (thehsh != hsh && !isold) return 0;
	if (isopen == 0) memset(have, 0, sizeof have);
	save(name);
	return 1;
}

void save(string name) {
   
	name += ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < name.size(); i++) ch[i] = name[i];
	char *s = ch;
	FILE *fp = fopen(s, "w");
	fprintf(fp, "%d %d %d %d ", nandu, blood, bao, score);
	unsigned long long hsh = rnk(nandu, 0) + rnk(blood, 0) + rnk(bao, 0) + rnk(score, 0);
	for (int i = 0; i < 10; i++) {
   
		fprintf(fp, "%d ", op[i]);
		hsh += rnk(op[i], 0);
	}
	for (int i = 1; i < maxn; i++) {
   
		have[5] = bao;
		fprintf(fp, "%d ", have[i]);
		hsh += rnk(have[i], 0);
	}
	isopen |= (nandu == 3 ? op[4] : op[6]);
	fprintf(fp, "%d ", isopen), hsh += rnk(isopen, 0);
	for (int i = 0; i <= 10; i++) {
   
		fprintf(fp, "%d ", whichkey[i]);
		hsh += rnk(whichkey[i], 0);
	}
	fprintf(fp, "%llu", hsh);
	fclose(fp);
	return ;
}

string keys[] = {
   "", "使用血包", "感知", "跃迁", "向左", "向上", "向右", "向下"};
void change(int x) {
   
	bool flag = 0;
	color(7), gto(x * 2 + 6, 4), cout << keys[x], color(13);
	gto(x * 2 + 6, 15), printf("[  %s  ]    ", keyname[(int)whichkey[x - 1]]);
	Sleep(50);
	while (1) {
   
		for (int i = 2; i <= 256; i++)
			if (
下面是代码 #include #include #include #include #define Height 25 //迷宫的高度,必须为奇数 #define Width 25 //迷宫的宽度,必须为奇数 #define Wall 1 #define Road 0 #define Start 2 #define End 3 #define Esc 5 #define Up 1 #define Down 2 #define Left 3 #define Right 4 int map[Height+2][Width+2]; void gotoxy(int x,int y) //移动坐标 { COORD coord; coord.X=x; coord.Y=y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); } void hidden()//隐藏光标 { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci;); cci.bVisible=0;//赋1为显示,赋0为隐藏 SetConsoleCursorInfo(hOut,&cci;); } void create(int x,int y) //随机生成迷宫 { int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向 int i,j,t; //将方向打乱 for(i=0;i<4;i++) { j=rand()%4; t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; } map[x][y]=Road; for(i=0;i<4;i++) if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) { map[x+c[i][0]][y+c[i][1]]=Road; create(x+2*c[i][0],y+2*c[i][1]); } } int get_key() //接收按键 { char c; while(c=getch()) { if(c==27) return Esc; //Esc if(c!=-32)continue; c=getch(); if(c==72) return Up; //上 if(c==80) return Down; //下 if(c==75) return Left; //左 if(c==77) return Right; //右 } return 0; } void paint(int x,int y) //画迷宫 { gotoxy(2*y-2,x-1); switch(map[x][y]) { case Start: printf("入");break; //画入口 case End: printf("出");break; //画出口 case Wall: printf("▇");break; //画墙 case Road: printf(" ");break; //画路 } } void game() { int x=2,y=1; //玩家当前位置,刚开始在入口处 int c; //用来接收按键 while(1) { gotoxy(2*y-2,x-1); printf("●"); //画出玩家当前位置 if(map[x][y]==End) //判断是否到达出口 { gotoxy(30,24); printf("到达终点,按任意键结束"); getch(); break; } c=get_key(); if(c==Esc) { gotoxy(0,24); break; } switch(c) { case Up: //向上走 if(map[x-1][y]!=Wall) { paint(x,y); x--; } break; case Down: //向下走 if(map[x+1][y]!=Wall) { paint(x,y); x++; } break; case Left: //向左走 if(map[x][y-1]!=Wall) { paint(x,y); y--; } break; case Right: //向右走 if(map[x][y+1]!=Wall) { paint(x,y); y++; } break; } } } int main() { system("title yourname"); int i,j; srand((unsigned)time(NULL)); //初始化随即种子 hidden(); //隐藏光标 for(i=0;i<=Height+1;i++) for(j=0;j<=Width+1;j++) if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫 map[i][j]=Road; else map[i][j]=Wall; create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数 for(i=0;i<=Height+1;i++) //边界处理 { map[i][0]=Wall; map[i][Width+1]=Wall; } for(j=0;j<=Width+1;j++) //边界处理 { map[0][j]=Wall; map[Height+1][j]=Wall; } map[2][1]=Start; //给定入口 map[Height-1][Width]=End; //给定出口 for(i=1;i<=Height;i++) for(j=1;j<=Width;j++) //画出迷宫 paint(i,j); game(); //开始游戏 getch(); return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值