- 分享
如何用c++字符来做3d游戏(4)
- 2024-2-6 13:11:06 @
接上期 我们制作了选项
我们还要做游戏说明还有故事情节,如下
1.
//游戏说明
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(); //读取键盘
}
2.
//故事情节(前)
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(); //读取键盘
}
3.
//故事情节(后)
void application6() {
cout << "你成功讨伐了Boss,迷雾也无影无踪," << endl;
cout << "边界墙也消失了";
}
我还把变量调了一下
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;//死亡次数
结合上期的代码
//头文件
#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");//清屏
return 0;
}
如有疑问,即可提出