代码如下:

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

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

//调色
void color(int ForgC, int BackC) {
	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}

//开头的显示
void application1() {
	system("color 0F");
	printf("——————————""欢迎来玩My map1.1.3""——————————\n");
	printf("请输入你的游戏名称:");
	getline(cin, name);//一整行的输入数据都识别
	printf("请输入你的游戏密码(建议输入英文):");
	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");//清屏
	printf("加密成功");
	Sleep(100);//等待0.1秒
}

//主页
void application2() {
	for (;;) {
		system("cls");//清屏
		printf("1.用户信息\n");
		printf( "2.开始游戏\n");
		color(0, 4);
		printf("3.更新说明\n");
		printf("4.关于程序\n");
		if (a == 0)
			printf("5.开启五彩斑斓\n");
		else if (a == 1)
			printf("5.取消五彩斑斓\n");
		key = _getch(); //读取键盘
		if (key == 49) {
			system("cls");//清屏
			printf("用户名:");
			cout<<name;
			printf("密码:");
			cout<<password2;
			key = _getch();//读取键盘
		} else if (key == 50) {
			break;
		} else if (key == 51) {
			system("cls");//清屏
			system("color 0F");
			if (a == 1) {
				rand1 = rand() % 6;
				if (rand1 == 0)
					system("color 0F");
				else if (rand1 == 1)
					system("color 1F");
				else if (rand1 == 2)
					system("color 2F");
				else if (rand1 == 3)
					system("color 3F");
				else if (rand1 == 4)
					system("color 4F");
				else if (rand1 == 5)
					system("color 5F");
			}
			printf("1.修改了My map1.1.2的bug,保留了My map1.1.1的");
			printf("特性\n");
			key = _getch(); //读取键盘
		} else if (key == 52) {
			system("cls");//清屏
			system("start cmd");//打开cmd
		} else if (key == 53) {
			system("cls");//清屏
			if (a == 0)
				a = 1;
			else if (a == 1)
				a = 0;
		} else {
			system("cls");//清屏
			printf("输入错误");
			Sleep(500);//等待0.5秒
		}
		system("color 0F");
		if (a == 1) {
			rand1 = rand() % 6;
			if (rand1 == 0)
				system("color 0F");
			else if (rand1 == 1)
				system("color 1F");
			else if (rand1 == 2)
				system("color 2F");
			else if (rand1 == 3)
				system("color 3F");
			else if (rand1 == 4)
				system("color 4F");
			else if (rand1 == 5)
				system("color 5F");
		}
	}
}

//选项
void application3() {
	for (;;) {
		//难度
		printf("%s", "——————难度选择——————\n");
		printf("%s", "1.简单\n");
		printf("2.普通\n");
		printf("3.困难\n");
		printf("4.专家\n");
		printf("5.噩梦\n");
		printf("6.未知\n");
		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 {
			printf("输入错误");
			Sleep(500);//等待0.5秒
			system("cls");//清屏
		}
	}
	system("cls");//清屏
	printf("请按任意键继续……");
	key = _getch(); //读取键盘
}

//游戏说明
void application4() {
	printf("游戏说明:\n");
	key = _getch(); //读取键盘
	printf("1.按w,s,a,d键就能上、下、左、右移动,\n");
	Sleep(100);//等待0.1秒
	printf( "按空格键可以跳跃,\n");
	Sleep(100);//等待0.1秒
	printf( "按i,k,j,l可以画面上、下、左、右移动\n");
	key = _getch(); //读取键盘
	printf( "2.游戏中的地势为平地,而且无树、草、花,无法破坏\n");
	key = _getch(); //读取键盘
	printf( "3.游戏中的泥土用#表示,\n");
	Sleep(100);//等待0.1秒
	printf("长着青苔的石砖用&表示,\n");
	Sleep(100);//等待0.1秒
	printf("随机用?表示\n");
	key = _getch(); //读取键盘
	printf("4.千万不要往头顶望!!!\n");
	key = _getch(); //读取键盘
	printf("5.你可以按g键激怒Boss,让它来正面跟你pvp\n");
	key = _getch(); //读取键盘
	printf("6.如果手电筒的电为0,那么”Game Over“了\n");
	key = _getch(); //读取键盘
	printf("7.按下esc键(键盘左上角的按键),就能设置出生点,死亡后重生到出生点\n");
	key = _getch(); //读取键盘
	printf("8.往下看,会进入潜行模式无法移动(跳跃除外)\n");
	key = _getch(); //读取键盘
	printf("9.按h键,挥剑\n");
	key = _getch(); //读取键盘
	printf("10.Boss会隐形\n");
	key = _getch(); //读取键盘
	printf("11.Boss血量为0时,按任意键即可\n");
	Sleep(300);//等待0.3秒
	printf("按任意键开始游戏……\n");
	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() {
	int map[51][51][21] = {0};
	long long delay; //延迟
	application1();
	application2();
	system("color 0F");
	system("cls");//清屏
	application3();
	system("cls");//清屏
	application4();
	system("cls");//清屏
	application5();
	system("cls");//清屏
	for (;;) {
		color(0, 4);
		cout << "输入密码:";
		getline(cin, character); ////一整行的输入数据都识别
		if (character != password1) {
			color(0, 4);
			cout << "密码错误";
			Sleep(500);//等待0.5秒
			system("cls");//清屏
		} else {
			color(0, 4);
			printf("ok");
			Sleep(500);//等待0.5秒
			system("cls");//清屏
			system("color 0F");
			if (a == 1) {
				rand1 = rand() % 6;
				if (rand1 == 0)
					system("color 0F");
				else if (rand1 == 1)
					system("color 1F");
				else if (rand1 == 2)
					system("color 2F");
				else if (rand1 == 3)
					system("color 3F");
				else if (rand1 == 4)
					system("color 4F");
				else if (rand1 == 5)
					system("color 5F");
			}
			break;
		}
		system("color 0F");
		if (a == 1) {
			rand1 = rand() % 6;
			if (rand1 == 0)
				system("color 0F");
			else if (rand1 == 1)
				system("color 1F");
			else if (rand1 == 2)
				system("color 2F");
			else if (rand1 == 3)
				system("color 3F");
			else if (rand1 == 4)
				system("color 4F");
			else if (rand1 == 5)
				system("color 5F");
		}
	}
	color(0, 4);
	cout << "延迟:";
	cin >> delay;
	system("cls");//清屏
	//以防死亡就不能继续玩
	hp02 = hp2;
	system("color 0F");
	if (a == 1) {
		rand1 = rand() % 6;
		if (rand1 == 0)
			system("color 0F");
		else if (rand1 == 1)
			system("color 1F");
		else if (rand1 == 2)
			system("color 2F");
		else if (rand1 == 3)
			system("color 3F");
		else if (rand1 == 4)
			system("color 4F");
		else if (rand1 == 5)
			system("color 5F");
	}
	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 << "手电筒的电量:";
			cout << fixed << setprecision(1) << 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");//清屏
				color(0, 4);
				cout << "%        %" << endl << endl;
				cout << "%        %" << endl;
				cout << " %      %" << endl;
				cout << "  %    %" << endl;
				cout << "   %  %" << endl;
				cout << "    %%";
				Sleep(10);//等待0.01秒
				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;
				}
			}
			if (hp01 <= 50) {
				color(0, 4);
				cout << "   ";
				system("color 0F");
				Sleep(300);
			}
			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;
					cout << "4.设置延迟" << endl;
					if (a == 0)
						printf("5.开启五彩斑斓\n");
					else if (a == 1)
						printf("5.取消五彩斑斓\n");
					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 if (key == 52) {
						system("cls");//清屏
						cout << "当前延迟为:" << delay << endl;
						cout << "新延迟为:";
						cin >> delay;
						system("cls");//清屏
						break;
					} else if (key == 53) {
						if (a == 0) {
							a = 1;
						} else if (a == 1) {
							a = 0;
						}
					} else {
						cout << "输入错误";
						Sleep(500);//等待0.5秒
						system("cls");//清屏
					}
				}
			} else if (key == 32) {
				h = h + 2;
				height = height + 2;
			}
			//加血
			if (hp01 != hp1) {
				hp01++;
			}
			system("cls");//清屏
			Sleep(delay * 10); //延迟
			electricity = electricity - 0.1;
			//攻击次数-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");//清屏
				system("color 4F");
				cout << "你赢了,Game Over" << endl;
				cout << "死亡次数:" << death << endl;
				cout << "Boss血量为" << hp2;
				key = _getch(); //读取键盘
				system("cls");//清屏
				application6();
				return 0;
			}
			//落下
			if (height > 0) {
				height--;
				h--;
			}
			if (a == 1) {
				rand1 = rand() % 6;
				if (rand1 == 0)
					system("color 0F");
				else if (rand1 == 1)
					system("color 1F");
				else if (rand1 == 2)
					system("color 2F");
				else if (rand1 == 3)
					system("color 3F");
				else if (rand1 == 4)
					system("color 4F");
				else if (rand1 == 5)
					system("color 5F");
			}
		}

	}
	return 0;
}

0 comments

No comments so far...