这个游戏花了我n个小时编,请大家不要学我。
话不多说,我们直接上代码:
#include<iostream>
#include<cstring>
using namespace std;
int lv = 0;
int life = 100;
int exp = 0;
int redjewel = 0;
int yellowjewel = 0;
int orangejewel = 0;
int greenjewel = 0;
int bluejewel = 0;
int purplejewel = 0;
int whitejewel = 0;
int boat = 0;
int wood = 0;
int food = 0;
int sword = 0;
int house = 0;
int input, input2;
int rands[10] = {1, 0, 1, 1, 0, 0, 1, 0, 1, 0};
int randsum = 0;
int life_under = 66;
int life_surface = 100;
int life_on = 30;
int wepon[10] = {5, 6, 4, 7, 5, 4, 3, 8, 5, 4};
int weponsum = 0;
string user;
void die() {
cout << "------------------------------------" << endl;
cout << "你死了!" << endl;
cout << "5秒后重生..." << endl;
_sleep(500);
life = 100;
}
void home() {
cout << "------------------------------------" << endl;
cout << "输入对应数字实现功能。" << endl;
cout << "1:背包" << endl;
cout << "2:等级" << endl;
cout << "3:探险" << endl;
cout << "4:合成" << endl;
cout << "5:返回陆地" << endl;
cout << "6:系统说明" << endl;
cout << "7:退出游戏" << endl;
}
void backpack() {
cout << "------------------------------------" << endl;
cout << "红色宝石×" << redjewel << endl;
cout << "橙色宝石×" << orangejewel << endl;
cout << "黄色宝石×" << yellowjewel << endl;
cout << "绿色宝石×" << greenjewel << endl;
cout << "蓝色宝石×" << bluejewel << endl;
cout << "紫色宝石×" << purplejewel << endl;
cout << "白色宝石×" << whitejewel << endl;
cout << "船×" << boat << endl;
cout << "木头×" << wood << endl;
cout << "食物×" << food << endl;
cout << "剑×" << sword << endl;
}
void level() {
lv = exp / 100;
cout << "------------------------------------" << endl;
cout << user << endl;
cout << "Lv." << lv << " EXP:" << exp << endl;
cout << "血量:" << life << endl;
}
void adventure_main() {
cout << "------------------------------------" << endl;
cout << "1:地狱(红色宝石获取地)" << endl;
cout << "2:地表(黄、橙、绿、蓝、紫宝石获取地)" << endl;
cout << "3:天堂(白色宝石获取地)" << endl;
}
void adventure_1() {
cout << "------------------------------------" << endl;
if (rands[randsum] == 1) {
for (;;) {
cout << "你遇到了地狱岩浆怪(血量:" << life_under << ")选项:1攻击,2逃跑。" << endl;
if (life_under <= 0) {
cout << "你杀死了敌人!在敌人骸骨中发现红色宝石!" << endl;
redjewel++;
break;
}
if (life == 0) {
die();
break;
}
cin >> input;
if (input == 1) {
if (sword > 0)
life_under -= wepon[weponsum];
else
life_under--;
life -= 2;
}
if (input == 2) {
cout << "你逃了回来!" << endl;
break;
}
}
}
if (rands[randsum] == 0) {
cout << "这里安全。" << endl;
}
randsum++;
randsum %= 10;
weponsum++;
weponsum %= 10;
life_under = 66;
}
void adventure_2() {
cout << "------------------------------------" << endl;
if (rands[randsum] == 1) {
for (;;) {
cout << "你遇到了掠夺者(血量:" << life_surface << ")选项:1攻击,2逃跑。" << endl;
if (life_surface <= 0) {
cout << "你杀死了敌人!在敌人骸骨中发现多颗宝石!" << endl;
yellowjewel++;
orangejewel++;
greenjewel++;
bluejewel++;
purplejewel++;
break;
}
if (life == 0) {
die();
break;
}
cin >> input;
if (input == 1) {
if (sword > 0)
life_surface -= wepon[weponsum];
else
life_surface--;
life -= 3;
}
if (input == 2) {
cout << "你逃了回来!" << endl;
break;
}
}
}
if (rands[randsum] == 0) {
cout << "这里安全。可以收集木头。" << endl;
_sleep(2000);
wood++;
cout << "已收集1块木头。" << endl;
}
randsum++;
randsum %= 10;
weponsum++;
weponsum %= 10;
life_surface = 100;
}
void adventure_3() {
cout << "------------------------------------" << endl;
if (rands[randsum] == 1) {
for (;;) {
cout << "你遇到了天堂云魂(血量:" << life_on << ")选项:1攻击,2逃跑。" << endl;
if (life_on <= 0) {
cout << "你杀死了敌人!在敌人骸骨中发现白色宝石!" << endl;
whitejewel++;
break;
}
if (life == 0) {
die();
break;
}
cin >> input;
if (input == 1) {
if (sword > 0)
life_on -= wepon[weponsum];
else
life_on--;
life -= 3;
}
if (input == 2) {
cout << "你逃了回来!" << endl;
break;
}
}
}
if (rands[randsum] == 0) {
cout << "这里安全。" << endl;
}
randsum++;
randsum %= 10;
weponsum++;
weponsum %= 10;
life_on = 30;
}
void make() {
cout << "------------------------------------" << endl;
cout << "合成,请输入数字。" << endl;
cout << "1:木头×5→剑×1" << endl;
cout << "2:木头×20→船×1" << endl;
cout << "3:木头×100→房子×1" << endl;
cin >> input;
if (input == 1) {
if (wood >= 5) {
cout << "已给予" << user << "剑×1。" << endl;
wood -= 5;
sword++;
} else
cout << "材料不足!" << endl;
}
if (input == 2) {
if (wood >= 20) {
cout << "已给予" << user << "船×1。" << endl;
wood -= 20;
boat++;
} else
cout << "材料不足!" << endl;
}
if (input == 3) {
if (wood >= 100) {
cout << "已给予" << user << "房子×1。" << endl;
wood -= 100;
house++;
} else
cout << "材料不足!" << endl;
}
}
void land() {
cout << "------------------------------------" << endl;
if (redjewel > 0 && orangejewel > 0 && yellowjewel > 0 && greenjewel > 0 && bluejewel > 0 && purplejewel > 0 && whitejewel > 0 && house > 0) {
{cout << "你踏上了返航之路!(请关闭游戏,感谢使用)" << endl;
}
} else
cout << "请先集齐7颗宝石,合成房子,船。" << endl;
}
void message() {
cout << "------------------------------------" << endl;
cout << "系统提示:剑合成后会自动使用!" << endl;
}
int main() {
string s1 = "你生在一个荒岛上,通过收集物资,集齐7颗宝石,乘船返回陆地。";
for (int i = 0; i < s1.length(); i++) {
cout << s1[i];
_sleep(100);
}
cout << endl;
cout << "请输入你的名称(不可更改):";
cin >> user;
for (;;) {
home();
cin >> input;
if (input == 1)
backpack();
if (input == 3) {
adventure_main();
cin >> input2;
if (input2 == 1)
adventure_1();
if (input2 == 2)
adventure_2();
if (input2 == 3)
adventure_3();
}
if (input == 2)
level();
if (input == 4)
make();
if (input == 5)
land();
if (input == 6)
message();
if (input == 7)
return 0;
}
return 0;
}