接上期 将这个游戏的代码给大家看

//头文件
#include <bits/stdc++.h>
#include <stdio.h>
#include <conio.h>
//读取头文件
using namespace std;

long long homex = 25, homey = 25, homeh = 26; //出生点的位置
long long x = 25, y = 25, h = 26; //自己的位置
int key;//按键码值读取
char letter;//输入字母
string character;//输入字符
string name;//游戏名称
string password1;//游戏密码
string password2;//游戏密码(反码)
long long hp1, hp2; //"我"和敌人的血量(满血)
long long hp01, hp02; //"我"和敌人的血量(实时)
float electricity = 100; //手电筒的电
long long number1, number2; //随机函数获取
int direction1, direction2; //横、竖方向
int height;//高度
long long attack;//攻击次数
long long Staging1, Staging2, Staging3, Staging4; //暂存点
long long death;//死亡次数

//开头的显示
void application1() {
	cout << "——————————" << "欢迎来玩My map1.1.1" << "——————————" << endl;
	cout << "请输入你的游戏名称:";
	getline(cin, name);//一整行的输入数据都识别
	cout << "请输入你的游戏密码(建议输入英文):";
	getline(cin, password1);//一整行的输入数据都识别
	Sleep(1000);//等待一秒
	//反码加密
	password2 = password1;
	int mid = 0;
	for (int i = 0; i < password2.size(); i++) {
		if ((password2[i] >= 'a') && (password2[i] <= 'z')) {
			mid = password2[i] - 'a';
			password2[i] = 'z' - mid;
		} else if ((password2[i] >= 'A') && (password2[i] <= 'Z')) {
			mid = password2[i] - 'A';
			password2[i] = 'Z' - mid;
		}
	}
	system("cls");//清屏
	cout << "加密成功";
	Sleep(100);//等待0.1秒
}

//主页
void application2() {
	for (;;) {
		system("cls");//清屏
		cout << "1.用户信息" << endl;
		cout << "2.开始游戏" << endl;
		key = _getch(); //读取键盘
		if (key == 49) {
			system("cls");
			cout << "用户名:" << name << endl;
			cout << "密码:" << password2;
			key = _getch();//读取键盘
		} else if (key == 50) {
			break;
		} else {
			cout << "输入错误";
			Sleep(500);//等待0.5秒
		}
	}
}

//选项
void application3() {
	for (;;) {
		//难度
		cout << "——————难度选择——————" << endl;
		cout << "1.简单" << endl;
		cout << "2.普通" << endl;
		cout << "3.困难" << endl;
		cout << "4.专家" << endl;
		cout << "5.噩梦" << endl;
		cout << "6.未知" << endl;
		key = _getch(); //读取键盘
		if (key == 49) {
			//"我"和敌人各100血
			hp1 = 100;
			hp2 = 100;
			break;
		} else if (key == 50) {
			//"我"100血,敌人500血
			hp1 = 100;
			hp2 = 500;
			break;
		} else if (key == 51) {
			//"我"100血,敌人1000血
			hp1 = 100;
			hp2 = 1000;
			break;
		} else if (key == 52) {
			//"我"100血,敌人5000血
			hp1 = 100;
			hp2 = 5000;
			break;
		} else if (key == 53) {
			//"我"100血,敌人50000血
			hp1 = 100;
			hp2 = 50000;
			break;
		} else if (key == 54) {
			//"我"50血,敌人100000血
			hp1 = 50;
			hp2 = 100000;
			break;
		} else {
			cout << "输入错误";
			Sleep(500);//等待0.5秒
			system("cls");//清屏
		}
	}
	system("cls");//清屏
	cout << "请按任意键继续……";
	key = _getch(); //读取键盘
}

//游戏说明
void application4() {
	cout << "游戏说明:" << endl;
	key = _getch(); //读取键盘
	cout << "1.按w,s,a,d键就能上、下、左、右移动," << endl;
	Sleep(100);//等待0.1秒
	cout << "按空格键可以跳跃," << endl;
	Sleep(100);//等待0.1秒
	cout << "按i,k,j,l可以画面上、下、左、右移动" << endl;
	key = _getch(); //读取键盘
	cout << "2.游戏中的地势为平地,而且无树、草、花,无法破坏" << endl;
	key = _getch(); //读取键盘
	cout << "3.游戏中的泥土用#表示," << endl;
	Sleep(100);//等待0.1秒
	cout << "长着青苔的石砖用&表示," << endl;
	Sleep(100);//等待0.1秒
	cout << "随机用?表示" << endl;
	key = _getch(); //读取键盘
	cout << "4.千万不要往头顶望!!!" << endl;
	key = _getch(); //读取键盘
	cout << "5.你可以按g键激怒Boss,让它来正面跟你pvp" << endl;
	key = _getch(); //读取键盘
	cout << "6.如果手电筒的电为0,那么”Game Over“了" << endl;
	key = _getch(); //读取键盘
	cout << "7.按下esc键(键盘左上角的按键),就能设置出生点,死亡后重生到出生点" << endl;
	key = _getch(); //读取键盘
	cout << "8.往下看,会进入潜行模式无法移动(跳跃除外)" << endl;
	key = _getch(); //读取键盘
	cout << "9.按h键,挥剑" << endl;
	key = _getch(); //读取键盘
	cout << "10.Boss会隐形" << endl;
	key = _getch(); //读取键盘
	cout << "11.Boss血量为0时,按任意键即可" << endl;
	Sleep(300);//等待0.3秒
	cout << "按任意键开始游戏……";
	key = _getch(); //读取键盘
}

//故事情节(前)
void application5() {
	cout << "有一天,你到平原冒险,误入了迷雾平原。" << endl;
	Sleep(100);//等待0.1秒
	cout << "你只带了无限食物、手电筒和铜剑。" << endl;
	Sleep(100);//等待0.1秒
	cout << "手电筒的光只能照亮你的附近" << endl;
	Sleep(100);//等待0.1秒
	cout << "你能否胜利呢???" << endl;
	Sleep(100);//等待0.1秒
	cout << "祝你好运," << name;
	key = _getch(); //读取键盘
}

//故事情节(后)
void application6() {
	cout << "你成功讨伐了Boss,迷雾也无影无踪," << endl;
	cout << "边界墙也消失了";
}

//主函数
int main() {
	long long map[50][50][20] = {0};
	long long delay;//延迟
	application1();
	application2();
	system("cls");//清屏
	application3();
	system("cls");//清屏
	application4();
	system("cls");//清屏
	application5();
	system("cls");//清屏
	for (;;) {
		cout << "输入密码:";
		getline(cin, character); ////一整行的输入数据都识别
		if (character != password1) {
			cout << "密码错误";
			Sleep(500);//等待0.5秒
			system("cls");//清屏
		} else {
			printf("ok");
			Sleep(500);//等待0.5秒
			system("cls");//清屏
			break;
		}
	}
	cout << "延迟:";
	cin >> delay;
	system("cls");//清屏
	//以防死亡就不能继续玩
	hp02 = hp2;
	for (;;) {
		//赋值
		hp01 = hp1;
		height = 0;
		x = homex;
		y = homey;
		h = homeh;
		electricity = 100;
		direction1 = 0;
		direction2 = 90;
		attack = 0;
		system("cls");//清屏
		//游戏内部
		for (;;) {
			//加载地面
			for (long long i = x - 1; i < x + 2; i++)
				for (long long j = y - 1; j < y + 2; j++)
					if (map[i][j][25] != 1)
						map[i][j][25] = 2;
			//加载边界墙
			if (x == 49) {
				map[x + 1][y][h] = 3;
			}
			if (y == 49) {
				map[x][y + 1][h] = 3;
			}
			if (h == 19) {
				map[x][y][h + 1] = 3;
			}
			if (x == 1) {
				map[x - 1][y][h] = 3;
			}
			if (y == 1) {
				map[x][y - 1][h] = 3;
			}
			if (h == 1) {
				map[x][y][h - 1] = 3;
			}
			//主题
			cout << "坐标:" << x << ',' << y << ',' << h << endl;
			cout << "我的血量:" << hp1 << "\\" << hp01 << endl;
			cout << "Boss的血量:" << hp2 << "\\" << hp02 << endl;
			cout << "手电筒的电量:" << electricity << endl;
			//显示
			//前
			if (direction1 == 0 && direction2 == 90) {
				for (long long i = y + 1; i > y - 2; i--) {
					for (long long j = h + 1; j < h + 3; j++) {
						if (map[x + 1][i][j] == 0) {
							cout << ' ';
						} else if (map[x + 1][i][j] == 1) {
							cout << '?';
						} else if (map[x + 1][i][j] == 2) {
							cout << '#';
						} else if (map[x + 1][i][j] == 3) {
							cout << '&';
						}
					}
					cout << endl;
				}
			}
			//后
			if (direction1 == 180 && direction2 == 90) {
				for (long long i = y + 1; i > y - 2; i--) {
					for (long long j = h + 1; j < h + 3; j++) {
						if (map[x - 1][i][j] == 0) {
							cout << ' ';
						} else if (map[x - 1][i][j] == 1) {
							cout << '?';
						} else if (map[x - 1][i][j] == 2) {
							cout << '#';
						} else if (map[x - 1][i][j] == 3) {
							cout << '&';
						}
					}
					cout << endl;
				}
			}
			//左
			if (direction1 == 270 && direction2 == 90) {
				for (long long i = x + 1; i > x - 2; i--) {
					for (long long j = h + 1; j < h + 3; j++) {
						if (map[i][y - 1][j] == 0) {
							cout << ' ';
						} else if (map[i][y - 1][j] == 1) {
							cout << '?';
						} else if (map[i][y - 1][j] == 2) {
							cout << '#';
						} else if (map[i][y - 1][j] == 3) {
							cout << '&';
						}
					}
					cout << endl;
				}
			}
			//右
			if (direction1 == 90 && direction2 == 90) {
				for (long long i = x + 1; i > x - 2; i--) {
					for (long long j = h + 1; j < h + 3; j++) {
						if (map[i][y + 1][j] == 0) {
							cout << ' ';
						} else if (map[i][y + 1][j] == 1) {
							cout << '?';
						} else if (map[i][y + 1][j] == 2) {
							cout << '#';
						} else if (map[i][y + 1][j] == 3) {
							cout << '&';
						}
					}
					cout << endl;
				}
			}
			//上
			if (direction2 == 180) {
				system("cls");//清屏
				cout << "%        %" << endl << endl;
				cout << "%        %" << endl;
				cout << " %      %" << endl;
				cout << "  %    %" << endl;
				cout << "   %  %" << endl;
				cout << "    %%";
				Sleep(5);//等待0.05秒
				system("cls");//清屏
				cout << "Game Over!!!";
				Sleep(2000);//等待2秒
				system("cls");//清屏
				death++;
				break;
			}
			//下
			if (direction2 == 0) {
				for (long long i = x - 1; i < x + 3; i++) {
					for (long long j = y + 1; j > y - 2; j--) {
						if (map[i][j][h - 1] == 0) {
							cout << ' ';
						} else if (map[i][j][h - 1] == 1) {
							cout << '?';
						} else if (map[i][j][h - 1] == 2) {
							cout << '#';
						} else if (map[i][j][h - 1] == 3) {
							cout << '&';
						}
					}
					cout << endl;
				}
			}
			key = _getch(); //读取键盘
			//按键
			if (key == 119 && direction1 == 0 && direction2 == 90 && map[x + 1][y][h] == 0) {
				x++;
			} else if (key == 115 && direction1 == 0 && direction2 == 90 && map[x - 1][y][h] == 0) {
				x--;
			} else if (key == 97 && direction1 == 0 && direction2 == 90 && map[x][y - 1][h] == 0) {
				y--;
			} else if (key == 100 && direction1 == 0 && direction2 == 90 && map[x][y + 1][h] == 0) {
				y++;
			} else if (key == 103 && direction1 == 0 && direction2 == 90) {
				Staging1 = x + 1;
				Staging2 = y;
				Staging3 = h;
				map[x + 1][y][h] = 4;
				attack = attack + 3;
			} else if (key == 104 && direction1 == 0 && direction2 == 90 && map[x + 1][y][h] == 4) {
				hp02 = hp02 - 10;
			} else if (key == 119 && direction1 == 180 && direction2 == 90 && map[x - 1][y][h] == 0) {
				x--;
			} else if (key == 115 && direction1 == 180 && direction2 == 90 && map[x + 1][y][h] == 0) {
				x++;
			} else if (key == 97 && direction1 == 180 && direction2 == 90 && map[x][y + 1][h] == 0) {
				y++;
			} else if (key == 100 && direction1 == 180 && direction2 == 90 && map[x][y - 1][h] == 0) {
				y--;
			} else if (key == 103 && direction1 == 180 && direction2 == 90) {
				Staging1 = x - 1;
				Staging2 = y;
				Staging3 = h;
				map[x - 1][y][h] = 4;
				attack = attack + 3;
			} else if (key == 104 && direction1 == 180 && direction2 == 90 && map[x - 1][y][h] == 4) {
				hp02 = hp02 - 10;
			} else if (key == 119 && direction1 == 270 && direction2 == 90 && map[x][y - 1][h] == 0) {
				y--;
			} else if (key == 115 && direction1 == 270 && direction2 == 90 && map[x][y + 1][h] == 0) {
				y++;
			} else if (key == 97 && direction1 == 270 && direction2 == 90 && map[x - 1][y][h] == 0) {
				x--;
			} else if (key == 100 && direction1 == 270 && direction2 == 90 && map[x + 1][y][h] == 0) {
				x++;
			} else if (key == 103 && direction1 == 270 && direction2 == 90) {
				Staging1 = x;
				Staging2 = y - 1;
				Staging3 = h;
				map[x][y - 1][h] = 4;
				attack = attack + 3;
			} else if (key == 104 && direction1 == 270 && direction2 == 90 && map[x][y - 1][h] == 4) {
				hp02 = hp02 - 10;
			} else if (key == 119 && direction1 == 90 && direction2 == 90 && map[x][y + 1][h] == 0) {
				y++;
			} else if (key == 115 && direction1 == 90 && direction2 == 90 && map[x][y - 1][h] == 0) {
				y--;
			} else if (key == 97 && direction1 == 90 && direction2 == 90 && map[x + 1][y][h] == 0) {
				x++;
			} else if (key == 100 && direction1 == 90 && direction2 == 90 && map[x - 1][y][h] == 0) {
				x--;
			} else if (key == 103 && direction1 == 90 && direction2 == 90) {
				Staging1 = x;
				Staging2 = y + 1;
				Staging3 = h;
				map[x][y + 1][h] = 4;
				attack = attack + 3;
			} else if (key == 104 && direction1 == 0 && direction2 == 90 && map[x][y + 1][h] == 4) {
				hp02 = hp02 - 10;
			} else if (key == 105) {
				direction2 = direction2 + 90;
				if (direction2 == 360) {
					direction2 = 0;
				}
			} else if (key == 107) {
				if (direction2 == 0) {
					direction2 = 360;
				}
				direction2 = direction2 - 90;
			} else if (key == 106) {
				if (direction1 == 0) {
					direction1 = 360;
				}
				direction1 = direction1 - 90;
			} else if (key == 108) {
				direction1 = direction1 + 90;
				if (direction1 == 360) {
					direction1 = 0;
				}
			} else if (key == 27) {
				for (;;) {
					system("cls");//清屏
					cout << "1.设置出生点" << endl;
					cout << "2.退出游戏" << endl;
					cout << "3.继续游戏" << endl;
					key = _getch(); //读取键盘
					if (key == 49) {
						system("cls");//清屏
						homex = x;
						homey = y;
						homeh = 26;
						break;
					} else if (key == 50) {
						for (;;) {
							system("cls");//清屏
							cout << "Y\\N" << endl;
							key = _getch(); //读取键盘
							if (key == 121) {
								system("cls");//清屏
								return 0;
							} else if (key == 110) {
								system("cls");//清屏
								break;
							} else {
								cout << "输入错误";
								Sleep(500);//等待0.5秒
								system("cls");//清屏
							}
						}
					} else if (key == 51) {
						system("cls");//清屏
						break;
					} else {
						cout << "输入错误";
						Sleep(500);//等待0.5秒
						system("cls");//清屏
					}
				}
			} else if (key == 32) {
				h = h + 2;
				height = height + 2;
			}
			Sleep(delay);//延迟
			system("cls");//清屏
			electricity = electricity - 0.5;
			//加血
			if (hp01 != hp1) {
				hp01++;
			}
			//攻击次数-1
			if (attack > 0) {
				attack--;
				hp01 = hp01 - 15;
			}
			//消除Boss
			if (attack == 0) {
				map[Staging1][Staging2][Staging3] = 0;
			}
			//死亡
			if (hp01 <= 0 || electricity <= 0 || direction2 == 270) {
				cout << "Game Over!!!";
				Sleep(2000);//等待2秒
				system("cls");//清屏
				death++;
				break;
			}
			//胜利
			if (hp02 <= 0) {
				system("cls");//清屏
				cout << "你赢了,Game Over" << endl;
				cout << "死亡次数:" << death << endl;
				cout << "Boss血量为" << hp2;
				key = _getch(); //读取键盘
				system("cls");//清屏
				application6();
				return 0;
			}
			//落下
			if (height > 0) {
				height--;
				h--;
			}
		}
	}
	return 0;
}

这个代码的显示部分是用六面体的感觉写的

4 comments

  • @ 2024-2-18 14:22:20

    头文件可以 加上 #include<windows.h>

    看你更了很多期,可以把版本号也同步在帖内,同时按照分割线去记录每次优化更新内容例如:


    时间:2024.2.17 版本:0.96

    本次新增内容:

    1.xxx

    2.xxx

    优化如下:

    1.xxx


    时间:2024.2.18 版本:0.99

    本次新增内容:

    1.xxx

    2.xxx

    优化如下:

    1.xxx


    加油,期待你更高级版本,如果有兴趣也可以拓展学习下虚幻5引擎,是支持C++语言的游戏引擎,也支持蓝图,期待你更COOL的作品 -知秋

    • @ 2024-2-7 21:45:12

      在哪儿运行?

    • @ 2024-2-6 21:26:32

      再加点刺激的,直接改引导这样有人中途停止或闯关失败直接电脑废了),如果通关就还原引导,并且闯关失败直接蓝屏或者想关闭程序也蓝屏(加点特效)

      👍 1
      • @ 2024-2-7 11:45:01
        //头文件
        #include <bits/stdc++.h>
        #include <stdio.h>
        #include <conio.h>
        //读取头文件
        using namespace std;
        
        long long homex = 25, homey = 25, homeh = 26; //出生点的位置
        long long x = 25, y = 25, h = 26; //自己的位置
        int key;//按键码值读取
        char letter;//输入字母
        string character;//输入字符
        string name;//游戏名称
        string password1;//游戏密码
        string password2;//游戏密码(反码)
        long long hp1, hp2; //"我"和敌人的血量(满血)
        long long hp01, hp02; //"我"和敌人的血量(实时)
        float electricity = 100; //手电筒的电
        long long number1, number2; //随机函数获取
        int direction1, direction2; //横、竖方向
        int height;//高度
        long long attack;//攻击次数
        long long Staging1, Staging2, Staging3, Staging4, Staging5; //暂存点
        long long death;//死亡次数
        
        //开头的显示
        void application1() {
        	cout << "——————————" << "欢迎来玩My map1.1.1" << "——————————" << endl;
        	cout << "请输入你的游戏名称:";
        	getline(cin, name);//一整行的输入数据都识别
        	cout << "请输入你的游戏密码(建议输入英文):";
        	getline(cin, password1);//一整行的输入数据都识别
        	Sleep(1000);//等待一秒
        	//反码加密
        	password2 = password1;
        	int mid = 0;
        	for (int i = 0; i < password2.size(); i++) {
        		if ((password2[i] >= 'a') && (password2[i] <= 'z')) {
        			mid = password2[i] - 'a';
        			password2[i] = 'z' - mid;
        		} else if ((password2[i] >= 'A') && (password2[i] <= 'Z')) {
        			mid = password2[i] - 'A';
        			password2[i] = 'Z' - mid;
        		}
        	}
        	system("cls");//清屏
        	cout << "加密成功";
        	Sleep(100);//等待0.1秒
        }
        
        //主页
        void application2() {
        	for (;;) {
        		system("cls");//清屏
        		cout << "1.用户信息" << endl;
        		cout << "2.开始游戏" << endl;
        		key = _getch(); //读取键盘
        		if (key == 49) {
        			system("cls");
        			cout << "用户名:" << name << endl;
        			cout << "密码:" << password2;
        			key = _getch();//读取键盘
        		} else if (key == 50) {
        			break;
        		} else {
        			cout << "输入错误";
        			Sleep(500);//等待0.5秒
        		}
        	}
        }
        
        //选项
        void application3() {
        	for (;;) {
        		//难度
        		cout << "——————难度选择——————" << endl;
        		cout << "1.简单" << endl;
        		cout << "2.普通" << endl;
        		cout << "3.困难" << endl;
        		cout << "4.专家" << endl;
        		cout << "5.噩梦" << endl;
        		cout << "6.未知" << endl;
        		key = _getch(); //读取键盘
        		if (key == 49) {
        			//"我"和敌人各100血
        			hp1 = 100;
        			hp2 = 100;
        			break;
        		} else if (key == 50) {
        			//"我"100血,敌人500血
        			hp1 = 100;
        			hp2 = 500;
        			break;
        		} else if (key == 51) {
        			//"我"100血,敌人1000血
        			hp1 = 100;
        			hp2 = 1000;
        			break;
        		} else if (key == 52) {
        			//"我"100血,敌人5000血
        			hp1 = 100;
        			hp2 = 5000;
        			break;
        		} else if (key == 53) {
        			//"我"100血,敌人50000血
        			hp1 = 100;
        			hp2 = 50000;
        			break;
        		} else if (key == 54) {
        			//"我"50血,敌人100000血
        			hp1 = 50;
        			hp2 = 100000;
        			break;
        		} else {
        			cout << "输入错误";
        			Sleep(500);//等待0.5秒
        			system("cls");//清屏
        		}
        	}
        	system("cls");//清屏
        	cout << "请按任意键继续……";
        	key = _getch(); //读取键盘
        }
        
        //游戏说明
        void application4() {
        	cout << "游戏说明:" << endl;
        	key = _getch(); //读取键盘
        	cout << "1.按w,s,a,d键就能上、下、左、右移动," << endl;
        	Sleep(100);//等待0.1秒
        	cout << "按空格键可以跳跃," << endl;
        	Sleep(100);//等待0.1秒
        	cout << "按i,k,j,l可以画面上、下、左、右移动" << endl;
        	key = _getch(); //读取键盘
        	cout << "2.游戏中的地势为平地,而且无树、草、花,无法破坏" << endl;
        	key = _getch(); //读取键盘
        	cout << "3.游戏中的泥土用#表示," << endl;
        	Sleep(100);//等待0.1秒
        	cout << "长着青苔的石砖用&表示," << endl;
        	Sleep(100);//等待0.1秒
        	cout << "随机用?表示" << endl;
        	key = _getch(); //读取键盘
        	cout << "4.千万不要往头顶望!!!" << endl;
        	key = _getch(); //读取键盘
        	cout << "5.你可以按g键激怒Boss,让它来正面跟你pvp" << endl;
        	key = _getch(); //读取键盘
        	cout << "6.如果手电筒的电为0,那么”Game Over“了" << endl;
        	key = _getch(); //读取键盘
        	cout << "7.按下esc键(键盘左上角的按键),就能设置出生点,死亡后重生到出生点" << endl;
        	key = _getch(); //读取键盘
        	cout << "8.往下看,会进入潜行模式无法移动(跳跃除外)" << endl;
        	key = _getch(); //读取键盘
        	cout << "9.按h键,挥剑" << endl;
        	key = _getch(); //读取键盘
        	cout << "10.Boss会隐形" << endl;
        	key = _getch(); //读取键盘
        	cout << "11.Boss血量为0时,按任意键即可" << endl;
        	Sleep(300);//等待0.3秒
        	cout << "按任意键开始游戏……";
        	key = _getch(); //读取键盘
        }
        
        //故事情节(前)
        void application5() {
        	cout << "有一天,你到平原冒险,误入了迷雾平原。" << endl;
        	Sleep(100);//等待0.1秒
        	cout << "你只带了无限食物、手电筒和铜剑。" << endl;
        	Sleep(100);//等待0.1秒
        	cout << "手电筒的光只能照亮你的附近" << endl;
        	Sleep(100);//等待0.1秒
        	cout << "你能否胜利呢???" << endl;
        	Sleep(100);//等待0.1秒
        	cout << "祝你好运," << name;
        	key = _getch(); //读取键盘
        }
        
        //故事情节(后)
        void application6() {
        	cout << "你成功讨伐了Boss,迷雾也无影无踪," << endl;
        	cout << "边界墙也消失了";
        }
        
        //主函数
        int main() {
        	long long map[50][50][20] = {0};
        	long long delay;//延迟
        	application1();
        	application2();
        	system("cls");//清屏
        	application3();
        	system("cls");//清屏
        	application4();
        	system("cls");//清屏
        	application5();
        	system("cls");//清屏
        	for (;;) {
        		cout << "输入密码:";
        		getline(cin, character); ////一整行的输入数据都识别
        		if (character != password1) {
        			cout << "密码错误";
        			Sleep(500);//等待0.5秒
        			system("cls");//清屏
        		} else {
        			printf("ok");
        			Sleep(500);//等待0.5秒
        			system("cls");//清屏
        			break;
        		}
        	}
        	cout << "延迟:";
        	cin >> delay;
        	system("cls");//清屏
        	//以防死亡就不能继续玩
        	hp02 = hp2;
        	for (;;) {
        		//赋值
        		hp01 = hp1;
        		height = 0;
        		x = homex;
        		y = homey;
        		h = homeh;
        		electricity = 100;
        		direction1 = 0;
        		direction2 = 90;
        		attack = 0;
        		system("cls");//清屏
        		//游戏内部
        		for (;;) {
        			//加载地面
        			for (long long i = x - 1; i < x + 2; i++)
        				for (long long j = y - 1; j < y + 2; j++)
        					if (map[i][j][25] != 1)
        						map[i][j][25] = 2;
        			//加载边界墙
        			if (x == 49) {
        				map[x + 1][y][h] = 3;
        			}
        			if (y == 49) {
        				map[x][y + 1][h] = 3;
        			}
        			if (h == 19) {
        				map[x][y][h + 1] = 3;
        			}
        			if (x == 1) {
        				map[x - 1][y][h] = 3;
        			}
        			if (y == 1) {
        				map[x][y - 1][h] = 3;
        			}
        			if (h == 1) {
        				map[x][y][h - 1] = 3;
        			}
        			//主题
        			cout << "坐标:" << x << ',' << y << ',' << h << endl;
        			cout << "我的血量:" << hp1 << "\\" << hp01 << endl;
        			cout << "Boss的血量:" << hp2 << "\\" << hp02 << endl;
        			cout << "手电筒的电量:" << electricity << endl;
        			//显示
        			//前
        			if (direction1 == 0 && direction2 == 90) {
        				for (long long i = y + 1; i > y - 2; i--) {
        					for (long long j = h + 1; j < h + 3; j++) {
        						if (map[x + 1][i][j] == 0) {
        							cout << ' ';
        						} else if (map[x + 1][i][j] == 1) {
        							cout << '?';
        						} else if (map[x + 1][i][j] == 2) {
        							cout << '#';
        						} else if (map[x + 1][i][j] == 3) {
        							cout << '&';
        						}
        					}
        					cout << endl;
        				}
        			}
        			//后
        			if (direction1 == 180 && direction2 == 90) {
        				for (long long i = y + 1; i > y - 2; i--) {
        					for (long long j = h + 1; j < h + 3; j++) {
        						if (map[x - 1][i][j] == 0) {
        							cout << ' ';
        						} else if (map[x - 1][i][j] == 1) {
        							cout << '?';
        						} else if (map[x - 1][i][j] == 2) {
        							cout << '#';
        						} else if (map[x - 1][i][j] == 3) {
        							cout << '&';
        						}
        					}
        					cout << endl;
        				}
        			}
        			//左
        			if (direction1 == 270 && direction2 == 90) {
        				for (long long i = x + 1; i > x - 2; i--) {
        					for (long long j = h + 1; j < h + 3; j++) {
        						if (map[i][y - 1][j] == 0) {
        							cout << ' ';
        						} else if (map[i][y - 1][j] == 1) {
        							cout << '?';
        						} else if (map[i][y - 1][j] == 2) {
        							cout << '#';
        						} else if (map[i][y - 1][j] == 3) {
        							cout << '&';
        						}
        					}
        					cout << endl;
        				}
        			}
        			//右
        			if (direction1 == 90 && direction2 == 90) {
        				for (long long i = x + 1; i > x - 2; i--) {
        					for (long long j = h + 1; j < h + 3; j++) {
        						if (map[i][y + 1][j] == 0) {
        							cout << ' ';
        						} else if (map[i][y + 1][j] == 1) {
        							cout << '?';
        						} else if (map[i][y + 1][j] == 2) {
        							cout << '#';
        						} else if (map[i][y + 1][j] == 3) {
        							cout << '&';
        						}
        					}
        					cout << endl;
        				}
        			}
        			//上
        			if (direction2 == 180) {
        				system("cls");//清屏
        				cout << "%        %" << endl << endl;
        				cout << "%        %" << endl;
        				cout << " %      %" << endl;
        				cout << "  %    %" << endl;
        				cout << "   %  %" << endl;
        				cout << "    %%";
        				Sleep(5);//等待0.05秒
        				system("cls");//清屏
        				cout << "Game Over!!!";
        				if (death == 0) {
        					for (int i = 0; i < 5000; i++) {
        						SetCursorPos(0, 0);
        					}
        					Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n你的内存要废了"),
        					                      (LPCTSTR)TEXT("Windows"), MB_ICONEXCLAMATION);
        					Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n5000秒后计算机自动崩溃"),
        					                      (LPCTSTR)TEXT("Windows"), MB_ICONEXCLAMATION);
        				}
        				Sleep(2000);//等待2秒
        				system("cls");//清屏
        				death++;
        				break;
        			}
        			//下
        			if (direction2 == 0) {
        				for (long long i = x - 1; i < x + 3; i++) {
        					for (long long j = y + 1; j > y - 2; j--) {
        						if (map[i][j][h - 1] == 0) {
        							cout << ' ';
        						} else if (map[i][j][h - 1] == 1) {
        							cout << '?';
        						} else if (map[i][j][h - 1] == 2) {
        							cout << '#';
        						} else if (map[i][j][h - 1] == 3) {
        							cout << '&';
        						}
        					}
        					cout << endl;
        				}
        			}
        			key = _getch(); //读取键盘
        			//按键
        			if (key == 119 && direction1 == 0 && direction2 == 90 && map[x + 1][y][h] == 0) {
        				x++;
        			} else if (key == 115 && direction1 == 0 && direction2 == 90 && map[x - 1][y][h] == 0) {
        				x--;
        			} else if (key == 97 && direction1 == 0 && direction2 == 90 && map[x][y - 1][h] == 0) {
        				y--;
        			} else if (key == 100 && direction1 == 0 && direction2 == 90 && map[x][y + 1][h] == 0) {
        				y++;
        			} else if (key == 103 && direction1 == 0 && direction2 == 90) {
        				Staging1 = x + 1;
        				Staging2 = y;
        				Staging3 = h;
        				map[x + 1][y][h] = 4;
        				attack = attack + 3;
        			} else if (key == 104 && direction1 == 0 && direction2 == 90 && map[x + 1][y][h] == 4) {
        				hp02 = hp02 - 10;
        			} else if (key == 119 && direction1 == 180 && direction2 == 90 && map[x - 1][y][h] == 0) {
        				x--;
        			} else if (key == 115 && direction1 == 180 && direction2 == 90 && map[x + 1][y][h] == 0) {
        				x++;
        			} else if (key == 97 && direction1 == 180 && direction2 == 90 && map[x][y + 1][h] == 0) {
        				y++;
        			} else if (key == 100 && direction1 == 180 && direction2 == 90 && map[x][y - 1][h] == 0) {
        				y--;
        			} else if (key == 103 && direction1 == 180 && direction2 == 90) {
        				Staging1 = x - 1;
        				Staging2 = y;
        				Staging3 = h;
        				map[x - 1][y][h] = 4;
        				attack = attack + 3;
        			} else if (key == 104 && direction1 == 180 && direction2 == 90 && map[x - 1][y][h] == 4) {
        				hp02 = hp02 - 10;
        			} else if (key == 119 && direction1 == 270 && direction2 == 90 && map[x][y - 1][h] == 0) {
        				y--;
        			} else if (key == 115 && direction1 == 270 && direction2 == 90 && map[x][y + 1][h] == 0) {
        				y++;
        			} else if (key == 97 && direction1 == 270 && direction2 == 90 && map[x - 1][y][h] == 0) {
        				x--;
        			} else if (key == 100 && direction1 == 270 && direction2 == 90 && map[x + 1][y][h] == 0) {
        				x++;
        			} else if (key == 103 && direction1 == 270 && direction2 == 90) {
        				Staging1 = x;
        				Staging2 = y - 1;
        				Staging3 = h;
        				map[x][y - 1][h] = 4;
        				attack = attack + 3;
        			} else if (key == 104 && direction1 == 270 && direction2 == 90 && map[x][y - 1][h] == 4) {
        				hp02 = hp02 - 10;
        			} else if (key == 119 && direction1 == 90 && direction2 == 90 && map[x][y + 1][h] == 0) {
        				y++;
        			} else if (key == 115 && direction1 == 90 && direction2 == 90 && map[x][y - 1][h] == 0) {
        				y--;
        			} else if (key == 97 && direction1 == 90 && direction2 == 90 && map[x + 1][y][h] == 0) {
        				x++;
        			} else if (key == 100 && direction1 == 90 && direction2 == 90 && map[x - 1][y][h] == 0) {
        				x--;
        			} else if (key == 103 && direction1 == 90 && direction2 == 90) {
        				Staging1 = x;
        				Staging2 = y + 1;
        				Staging3 = h;
        				map[x][y + 1][h] = 4;
        				attack = attack + 3;
        			} else if (key == 104 && direction1 == 0 && direction2 == 90 && map[x][y + 1][h] == 4) {
        				hp02 = hp02 - 10;
        			} else if (key == 105) {
        				direction2 = direction2 + 90;
        				if (direction2 == 360) {
        					direction2 = 0;
        				}
        			} else if (key == 107) {
        				if (direction2 == 0) {
        					direction2 = 360;
        				}
        				direction2 = direction2 - 90;
        			} else if (key == 106) {
        				if (direction1 == 0) {
        					direction1 = 360;
        				}
        				direction1 = direction1 - 90;
        			} else if (key == 108) {
        				direction1 = direction1 + 90;
        				if (direction1 == 360) {
        					direction1 = 0;
        				}
        			} else if (key == 27) {
        				for (;;) {
        					system("cls");//清屏
        					cout << "1.设置出生点" << endl;
        					cout << "2.退出游戏" << endl;
        					cout << "3.继续游戏" << endl;
        					key = _getch(); //读取键盘
        					if (key == 49) {
        						system("cls");//清屏
        						homex = x;
        						homey = y;
        						homeh = 26;
        						break;
        					} else if (key == 50) {
        						for (;;) {
        							system("cls");//清屏
        							cout << "Y\\N" << endl;
        							key = _getch(); //读取键盘
        							if (key == 121) {
        								system("cls");//清屏
        								return 0;
        							} else if (key == 110) {
        								system("cls");//清屏
        								break;
        							} else {
        								cout << "输入错误";
        								Sleep(500);//等待0.5秒
        								system("cls");//清屏
        							}
        						}
        					} else if (key == 51) {
        						system("cls");//清屏
        						break;
        					} else {
        						cout << "输入错误";
        						Sleep(500);//等待0.5秒
        						system("cls");//清屏
        					}
        				}
        			} else if (key == 32) {
        				h = h + 2;
        				height = height + 2;
        			}
        			Sleep(delay);//延迟
        			system("cls");//清屏
        			electricity = electricity - 0.5;
        			//加血
        			if (hp01 != hp1) {
        				hp01++;
        			}
        			//攻击次数-1
        			if (attack > 0) {
        				attack--;
        				hp01 = hp01 - 15;
        			}
        			//消除Boss
        			if (attack == 0) {
        				map[Staging1][Staging2][Staging3] = 0;
        			}
        			//死亡
        			if (hp01 <= 0 || electricity <= 0 || direction2 == 270) {
        				cout << "Game Over!!!";
        				if (death == 0) {
        					for (int i = 0; i < 5000; i++) {
        						SetCursorPos(0, 0);
        					}
        					Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n你的内存要废了"),
        					                      (LPCTSTR)TEXT("Windows"), MB_ICONEXCLAMATION);
        					Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n5000秒后计算机自动崩溃"),
        					                      (LPCTSTR)TEXT("Windows"), MB_ICONEXCLAMATION);
        				}
        				Sleep(2000);//等待2秒
        				system("cls");//清屏
        				death++;
        				break;
        			}
        			//胜利
        			if (hp02 <= 0) {
        				system("cls");//清屏
        				cout << "你赢了,Game Over" << endl;
        				cout << "死亡次数:" << death << endl;
        				cout << "Boss血量为" << hp2;
        				key = _getch(); //读取键盘
        				system("cls");//清屏
        				if (death >= 1) {
        					Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n哈哈我骗你的"),
        					                      (LPCTSTR)TEXT("Windows"), MB_ICONEXCLAMATION);
        				}
        				application6();
        				return 0;
        			}
        			//落下
        			if (height > 0) {
        				height--;
        				h--;
        			}
        			if (death == 10) {
        				Staging5 = MessageBox(NULL, (LPCTSTR)TEXT("\n自毁"),
        				                      (LPCTSTR)TEXT("C++"), MB_ICONEXCLAMATION);
        				for (int i = 0; i < 1000; i++) {
        					system("start cmd");
        				}
        			}
        		}
        	}
        	return 0;
        }
        
      • @ 2024-2-8 9:42:03

        @

        666,dalao牛逼

    • @ 2024-2-6 20:57:47

      Dev-C++不能用,说是Sleep()函数报错了。

    • 1