前言
看到我第二期文章只有1点赞1收藏的我belike:

Doge:?
Doge:别问,问就是作者没活了

上课!!!
正文
1、跳过剧情
这个功能其实我感觉很需要加。因为我在测试的时候,写一段代码再测就要重开一遍程序,再看一遍美妙无比的剧情(并非),实在是太烦人了。

所以我针对这个问题有两种解决方案:
①在看剧情时通过按下某按钮来跳过
②在开始游戏时询问是否观看剧情
方案1
这个我试过很多次,但最终以失败告终。
原因很简单,我们的剧情是使用SlowPrint函数输出的,能插入按键判断的地方只有printf前后,而每在tet.t秒后才判断,也就是说,必须在输出文字后一帧准确无误地按下空格才能跳过!
Doge:作者为什么你用彩色字幕君用得这么频繁了?

这种体验感太差劲了,我不要
方案2
这个就很好实现了,可以在控制台上显示询问的信息,也可以使用一个弹窗来,这里我使用弹窗,绝不是因为作者懒得写代码!
Doge:我不信
这看似很容易,只需在Start函数前面添加一个Message判断就可以了!
if(MessageBox(NULL, "是否跳过剧情?", "剧情", MB_YESNO|MB_ICONQUESTION) == 7)
如果你没弄错的话,此时运行程序并开始游戏你能看到这个:

好耶!!终于可以跳过神人剧情了!!!
2、修复Bug1
我注意到了一个bug:当移动至野外并前往草原后,背景地图便不再刷新

我们希望这样:

这个bug很好修,只不过是我不小心把打印地图的代码放到while循环外面了!
这是修改后的GAME.Move函数:
void Move() {
while (1) {
Cls();
syscolor("ef");
gotoxy(0, 0);
color(51);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
for (int i = 0; i <= 29; i++) {
color(120);
gotoxy(i, 85 - i);
for (int j = 0; j <= 20; j++)
cout << " ";
color(135);
for (int j = 0; j <= 13 + i; j++) {
cout << " ";
}
}
color(234);
gotoxy(6, 25);
printf("γ ψ");
gotoxy(7, 25);
printf(" γ");
gotoxy(8, 25);
printf(" γ ψ");
gotoxy(9, 25);
printf(" γ ψ");
PrintTree(11, 27);
PrintTree(10, 31);
PrintTree(11, 35);
PrintTree(13, 32);
PrintTree(12, 36);
PrintTree(13, 40);
PrintTree(11, 37);
PrintTree(10, 41);
PrintTree(11, 45);
PrintTree(12, 42);
PrintTree(11, 46);
PrintTree(12, 50);
color(49);
gotoxy(0, 105);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(1, 105);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(2, 104);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(3, 104);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(4, 103);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(5, 103);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(6, 102);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(7, 102);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(8, 101);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(9, 101);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(10, 100);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(11, 100);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(12, 99);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(13, 99);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(14, 98);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(15, 98);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(16, 97);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(17, 97);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(18, 96);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(19, 96);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(20, 95);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(21, 95);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(22, 94);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(23, 94);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(24, 93);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(25, 93);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(23, 0);
cout << " ";
gotoxy(24, 0);
cout << " ";
gotoxy(25, 0);
cout << " ";
gotoxy(26, 0);
cout << " ";
gotoxy(27, 0);
color(17);
cout << " ";
color(120);
gotoxy(28, 0);
cout << " ";
gotoxy(29, 0);
cout << " ";
color(135);
gotoxy(3, 86);
cout << "┌─┐";
gotoxy(4, 84);
cout << "┌ ┐";
gotoxy(5, 84);
cout << "└ ▲┘";
gotoxy(6, 86);
cout << "└─┘";
color(15);
gotoxy(0, 0);
cout << "你要去哪里?";
if (outbutton(outdo, 1, 0) == "1、草原") {
KillEnemy(1);
}
}
Sleep(10000);
return;
}
3、修复bug2
如果你开始游戏后,没有上下翻而是按下了→键,再按空格,恭喜你触发了🐞Bug:

这就得牵扯到outbutton函数的底层逻辑了!但说实话这个功能是我从这篇博客中发现并抠出来的。代码我居然也看不懂。所以该怎么办呢?
这很简单!我们只需要——

......乌拉乌拉说了一大堆,还是看不懂!

于是乎我想起来了——
直接把左右换页的代码删了不就行了吗!我可真是

//新函数
string _(button way[], int x, int y) {
int nowway = 0;
bool up[100] = { true, false, false };
bool down[100] = { true, false, false };
char c;
int now = 0;
for (int i = 0; i < 100; i++) {
if (down[i] == true) {
now = i;
}
}
while (1) {
gotoxy(x, y);
for (int i = 0; way[i].name != ""; i++) {
if (up[i] == true) {
color(240);
cout << "|" << way[i].name << "|";
color(15);
} else {
color(15);
cout << " " << way[i].name << " ";
}
}
printf("\n");
cout << endl;
for (int i = 0; way[nowway].b[i] != ""; i++) {
if (down[i] == true) {
color(127);
cout << " " << way[nowway].b[i] << " " << endl;
color(15);
} else {
color(15);
cout << " " << way[nowway].b[i] << " " << endl;
}
}
c = getch();
if ((c == 'w' || c == Up || c == '8') && now > 0) {
gotoxy(0, 0);
down[now] = false;
down[now - 1] = true;
now -= 1;
}
if ((c == 's' || c == Down || c == '2') && way[nowway].b[now + 1] != "") {
gotoxy(0, 0);
down[now] = false;
down[now + 1] = true;
now += 1;
}
if (c == 32) {
return way[nowway].b[now];
}
}
return "";
}
然后只需把每个outbutton()换成_()就可以了!
4、优化探险
①优化怪物
首先我们先加一个遇见怪物的提示语,为了实现这个,我们先编写一个结构体,这看似很容易。
struct MeetEnemy{
string Notice[5];
};
然后是内容,我只写到了area3,回头接着更!
MeetEnemy meet_enemy[9] = {
{""},
{"远处尘土飞扬,一头野兽正径直朝你的方向狂奔而来!\n", "草丛深处传来窸窸窣窣的响动,似乎有野兽正在靠近……\n", "一阵低沉的吼叫声在草原上回荡,危险就在不远处。\n"},
{"这里好像有动静!该不会是......\n", "滚烫的沙滩尽头,一道黑影快速向你移动,看起来极具攻击性。\n", "海风裹挟着奇怪的嘶吼声,某种荒漠生物盯上了你。\n"},
{"瀑布后方的岩洞中传出沉闷低吼,里面藏着栖息的野兽。\n", "草丛深处传来窸窸窣窣的响动,似乎有野兽正在靠近……\n", "湍急水声掩盖不住猛兽的喘息,它正绕到你的身后。\n"},
};
增加怪物种类!多亏了逗孢AI!
// 平原 丘陵 山 森林 沉船
Enemy enemy[25] = {
{"", {""}, {N}, N, N},
{"小野猪", {"使獠牙攻击", " 撕咬 "}, {5, 8}, 1, 1},
{"疯牛", {"用牛角撞击", " 冲撞"}, {10, 12}, 1, 2},
{"狮子", {"用利齿撕咬", "用利爪攻击"}, {15, 12}, 2, 2},
{"鹰", {"用利爪攻击", "用石头砸中"}, {8, 18}, 2, 2},
{"愤怒的山羊", {"用羊角撞击", "撞击"}, {12, 8}, 3, 2},
{"狼", {"使用 利齿 撕咬"}, {15}, 3, 2},
{"老虎", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {20, 18}, 3, 3},
{"岩狼", {"利齿撕咬腿部", "绕身偷袭后背"}, {15, 16}, 3, 2},
{"猛虎", {"利爪撕裂衣衫", "扑上来狠狠撕咬"}, {20, 18}, 3, 3},
{"水蛇", {"毒牙咬向脚踝", "缠绕四肢收紧"}, {9, 13}, 4, 1},
{"巨鳄", {"死死咬住小腿", "甩动身体撕扯血肉"}, {22, 26}, 4, 3},
{"寄居蟹群", {"硬壳夹伤手指", "成群围攻脚踝"}, {4, 6}, 5, 1},
{"浅海鲨鱼", {"利齿划破大腿", "来回撕咬伤口"}, {24, 30}, 5, 3},
{"孤狼", {"偷袭咬你后腰", "正面扑咬肩膀"}, {16, 19}, 6, 2},
{"黑熊", {"用熊掌重击躯干", "抱住你疯狂撕抓"}, {25, 28}, 6, 3},
{"洞穴蝙蝠", {"成群扑向面部", "的尖牙划伤皮肤"}, {3, 5}, 7, 1},
{"洞熊", {"蛮力冲撞", "爪牙同时进攻"}, {27, 32}, 7, 3},
{"巨型岩蜥", {"长尾抽打躯干", "大口啃咬"}, {18, 22}, 7, 2},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
};
网友:后面剩四个空的干嘛?
这是为了防止数据长度溢出,然后再加一个作战时⚔️的列表:
button fightdo[] = {"", {"1、攻击", "2、防御", "3、逃跑"}, 3};
以上这些在下节课会使用到!
②优化地区
在上一篇文章,地区的定义种类只有1个绿色草原,现在我们把其它的补全:
Area area[10] = {
{"", N, {N, N, N}},
{"绿色草原", 1, {0, 1, 2, 13, 27}},
{"戈壁沙滩", 2, {2, 4, 0, 28, 8}},
{"石山瀑布", 3, {2, 4, 3, 14, 25}},
{"下游河流", 4, {25, 25, 4, 33, 17}},
{"大海边", 5, {26, 26, 26, 2, 28}},
{"远山", 6, {2, 31, 2, 3, 3}},
{"山顶洞穴", 7, {3, 31, 2 ,31, 31}},
};
我们希望每个地区的安全程度![]()
![]()
![]()
:
int safe;
if(a == 1) // 草原 最安全
safe = rand() % 2;
else if(a == 2) // 沙滩
safe = rand() % 3;
else if(a == 3) // 瀑布
safe = rand() % 3;
else if(a == 4) // 河流
safe = rand() % 4;
else if(a == 5) // 海边
safe = rand() % 5;
else if(a == 6) // 远山
safe = rand() % 6;
else if(a == 7) // 洞穴 最危险
safe = rand() % 7;
if (safe == 0) {
...
}else
...
③优化物品
物品种类有点少,但是我目前也只增加了9种:
// 1:锻造类
// 2:食物类
// 3:武器类
Things thingsName[1000] = {
"树枝", 0, 1, 0,
"木头", 0, 1, 1,
"石片", 0, 1, 2,
"石块", 0, 1, 3,
"藤条", 0, 1, 4,
"铁矿", 0, 1, 5,
"煤炭", 0, 1, 6,
"铁片", 0, 1, 7,
"棕榈叶", 0, 1, 8,
"钢铁", 0, 1, 9,
"生肉", 0, 2, 10,
"熟肉", 0, 2, 11,
"肉汤", 0, 2, 12,
"露水", 0, 1, 13,
"雨水", 0, 1, 14,
"雪水", 0, 1, 15,
"面粉", 0, 1, 16,
"小麦", 0, 1, 17,
"面包", 0, 2, 18,
"饼干", 0, 2, 19,
"土豆", 0, 2, 20,
"蜂蜜", 0, 2, 21,
"小锉刀", 0, 3, 22,
"长刀", 0, 3, 23,
"利剑", 0, 3, 24,
"淡水", 0, 1, 25,
"咸水", 0, 1, 26,
"土壤", 0, 1, 27,
"沙子", 0, 1, 28,
"火药", 0, 1, 29,
"炸药", 0, 3, 30,
"矿石", 0, 1, 31,
"麦芽啤酒", 0, 2, 32,
"大麦", 0, 1, 33,
};
想象一下,如果你每次收集物品只能收集一种,那可太无趣了!谁不喜欢一次收集三种呢!于是——随机收集数1~3它出现了!



int collect1 = rand() % 5;
// 循环直到不重复,而非只随机一次
int collect2 = rand() % 5;
while(collect2 == collect1)
collect2 = rand() % 5;
int collect3 = rand() % 5;
while(collect3 == collect1 || collect3 == collect2)
collect3 = rand() % 5;
int howm1 = rand() % 20 + 4;
int howm2 = rand() % 15 + 6;
int howm3 = rand() % 10 + 8;
int type = rand() % 3 + 1;
cout << "这里安全,可以收集一些东西。" << endl << endl;
Sleep(600);
cout << "你收集了" << howm1 << "个" << thingsName[area[a].things[collect1]].Name;
if(type > 1)
{
cout << "和" << howm2 << "个" << thingsName[area[a].things[collect2]].Name;
}
if(type == 3)
{
cout << "。除此之外,还有" << howm3 << "个" << thingsName[area[a].things[collect3]].Name;
}
Sleep(1000);
cout << endl << endl;
color(10);
Pause();
还有物品的量词,也有着大大的吆西:(等等你告诉我什么叫你收集了6个雨水?!)


物品新增量词!!!(两坨船)
struct Things {
string Name;
int Sum;
int Type;
int ID;
string LiangCi;
};
// 1:锻造类
// 2:食物类
// 3:武器类
Things thingsName[1000] = {
"树枝", 0, 1, 0, "根",
"木头", 0, 1, 1, "根",
"石片", 0, 1, 2, "片",
"石块", 0, 1, 3, "块",
"藤条", 0, 1, 4, "根",
"铁矿", 0, 1, 5, "块",
"煤炭", 0, 1, 6, "块",
"铁片", 0, 1, 7, "片",
"棕榈叶", 0, 1, 8, "片",
"钢铁", 0, 1, 9, "块",
"生肉", 0, 2, 10, "块",
"熟肉", 0, 2, 11, "份",
"肉汤", 0, 2, 12, "碗",
"露水", 0, 1, 13, "份",
"雨水", 0, 1, 14, "份",
"雪水", 0, 1, 15, "份",
"面粉", 0, 1, 16, "份",
"小麦", 0, 1, 17, "粒",
"面包", 0, 2, 18, "块",
"饼干", 0, 2, 19, "片",
"土豆", 0, 2, 20, "颗",
"蜂蜜", 0, 2, 21, "份",
"小锉刀", 0, 3, 22, "把",
"长刀", 0, 3, 23, "把",
"利剑", 0, 3, 24, "把",
"淡水", 0, 1, 25, "份",
"咸水", 0, 1, 26, "份",
"土壤", 0, 1, 27, "堆",
"沙子", 0, 1, 28, "堆",
"火药", 0, 1, 29, "撮",
"炸药", 0, 3, 30, "个",
"矿石", 0, 1, 31, "块",
"麦芽啤酒", 0, 2, 32, "杯",
"大麦", 0, 1, 33, "粒",
};
cout << "你收集了" << howm1 << thingsName[area[a].things[collect1]].LiangCi << thingsName[area[a].things[collect1]].Name;
if(type > 1)
{
cout << "和" << howm2 << thingsName[area[a].things[collect2]].LiangCi << thingsName[area[a].things[collect2]].Name;
}
if(type == 3)
{
cout << "。除此之外,还有" << howm3 << thingsName[area[a].things[collect3]].LiangCi << thingsName[area[a].things[collect3]].Name;
}
完整代码
main.cpp:
#include "Files/Console.in"
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h> // 包含 Windows API 函数声明
#include <conio.h> // 包含 _getch()、gotoxy 等控制台函数
#include <cstdlib> // 包含 rand()、exit() 等
#include <ctime> // 包含 time() 函数
using namespace std;
#define N 0
using namespace console_game;
//x:行, y:列
char press = '1';
int startchange = 1;
struct Enemy {
string name;
string attack[10];
int hurt[10];
int AreaID;
int DangerIndex;
};
struct Area {
string Name;
int areaID;
int things[1000];
};
struct MeetEnemy{
string Notice[5];
};
struct outtext {
char text[100000];
int t;
};
// 平原 丘陵 山 森林 沉船
Enemy enemy[25] = {
{"", {""}, {N}, N, N},
{"小野猪", {"使獠牙攻击", " 撕咬 "}, {5, 8}, 1, 1},
{"疯牛", {"用牛角撞击", " 冲撞"}, {10, 12}, 1, 2},
{"狮子", {"用利齿撕咬", "用利爪攻击"}, {15, 12}, 2, 2},
{"鹰", {"用利爪攻击", "用石头砸中"}, {8, 18}, 2, 2},
{"愤怒的山羊", {"用羊角撞击", "撞击"}, {12, 8}, 3, 2},
{"狼", {"使用 利齿 撕咬"}, {15}, 3, 2},
{"老虎", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {20, 18}, 3, 3},
{"岩狼", {"利齿撕咬腿部", "绕身偷袭后背"}, {15, 16}, 3, 2},
{"猛虎", {"利爪撕裂衣衫", "扑上来狠狠撕咬"}, {20, 18}, 3, 3},
{"水蛇", {"毒牙咬向脚踝", "缠绕四肢收紧"}, {9, 13}, 4, 1},
{"巨鳄", {"死死咬住小腿", "甩动身体撕扯血肉"}, {22, 26}, 4, 3},
{"寄居蟹群", {"硬壳夹伤手指", "成群围攻脚踝"}, {4, 6}, 5, 1},
{"浅海鲨鱼", {"利齿划破大腿", "来回撕咬伤口"}, {24, 30}, 5, 3},
{"孤狼", {"偷袭咬你后腰", "正面扑咬肩膀"}, {16, 19}, 6, 2},
{"黑熊", {"用熊掌重击躯干", "抱住你疯狂撕抓"}, {25, 28}, 6, 3},
{"洞穴蝙蝠", {"成群扑向面部", "的尖牙划伤皮肤"}, {3, 5}, 7, 1},
{"洞熊", {"蛮力冲撞", "爪牙同时进攻"}, {27, 32}, 7, 3},
{"巨型岩蜥", {"长尾抽打躯干", "大口啃咬"}, {18, 22}, 7, 2},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
{"", {""}, {0}, 0, 0},
};
MeetEnemy meet_enemy[9] = {
{""},
{"远处尘土飞扬,一头野兽正径直朝你的方向狂奔而来!\n", "草丛深处传来窸窸窣窣的响动,似乎有野兽正在靠近……\n", "一阵低沉的吼叫声在草原上回荡,危险就在不远处。\n"},
{"这里好像有动静!该不会是......\n", "滚烫的沙滩尽头,一道黑影快速向你移动,看起来极具攻击性。\n", "海风裹挟着奇怪的嘶吼声,某种荒漠生物盯上了你。\n"},
{"瀑布后方的岩洞中传出沉闷低吼,里面藏着栖息的野兽。\n", "草丛深处传来窸窸窣窣的响动,似乎有野兽正在靠近……\n", "湍急水声掩盖不住猛兽的喘息,它正绕到你的身后。\n"},
};
outtext text[20] = {
" ", 0,
"在一片浩瀚无垠的蔚蓝大海上,阳光如同碎金般洒落在波光粼粼的水面上。你正惬意地乘坐着豪华游轮,享受着这美好的海上旅程。\n", 25,
"然而,突如其来的风暴打破了这份宁静,巨大的海浪如同巨兽般吞噬着一切。游轮在狂风巨浪中剧烈摇晃,发出令人胆寒的嘎吱声。\n\n船身被海浪一次次冲击,最终不堪重负,开始解体。你在混乱中被卷入了汹涌的大海,冰冷的海水瞬间将你包围......\n", 20,
"在奋力挣扎了不知多久后,你幸运又不幸地成为了这场灾难中唯一的幸存者,漂流到了一座荒无人烟的岛屿上。当你拖着疲惫不堪的身体爬上沙滩,看着眼前陌生而又荒芜的景象,心中充满了恐惧与无助,但求生的本能却在此时开始悄然觉醒......\n", 30,
"请键入你的用户名: ", 20,
"醒醒......\n", 50,
"我在哪里?......\n", 30,
"Prew......我居然活下来了!\n", 30,
"呼......\n", 30,
"真累哈......\n", 40,
"好了,是时候考虑活下去的问题了......\n", 40
};
struct MciMusic {
void SendMusic(LPCSTR musicname) {
char Code[10] = "play ";
strcat(Code, musicname);
mciSendString(Code, N, 0, N);
}
void PauseMusic(LPCSTR musicname) {
char Code[10] = "pause ";
strcat(Code, musicname);
mciSendString(Code, N, 0, N);
}
void ResumeMusic(LPCSTR musicname) {
char Code[10] = "resume ";
strcat(Code, musicname);
mciSendString(Code, N, 0, N);
}
void CloseMusic(LPCSTR musicname) {
char Code[10] = "close ";
strcat(Code, musicname);
mciSendString(Code, N, 0, N);
}
};
MciMusic music;
string Time;
string Weather;
string Season;
int ismap;
int isrun;
int ispapp;
button homedo[] = {"", {"1、移动", "2、吃饭", "3、医疗", "4、睡觉", "5、建造"}, 5};
button outdo[] = {"", {"1、草原", "2、沙滩", "3、瀑布", "4、河流", "5、海边", "6、远山", "7、山顶洞穴", "8、回家"}, 8};
button fightdo[] = {"", {"1、攻击", "2、防御", "3、逃跑"}, 3};
int LiveDay;
int Random;
string result;
struct Things {
string Name;
int Sum;
int Type;
int ID;
string LiangCi;
};
// 1:锻造类
// 2:食物类
// 3:武器类
Things thingsName[1000] = {
"树枝", 0, 1, 0, "根",
"木头", 0, 1, 1, "根",
"石片", 0, 1, 2, "片",
"石块", 0, 1, 3, "块",
"藤条", 0, 1, 4, "根",
"铁矿", 0, 1, 5, "块",
"煤炭", 0, 1, 6, "块",
"铁片", 0, 1, 7, "片",
"棕榈叶", 0, 1, 8, "片",
"钢铁", 0, 1, 9, "块",
"生肉", 0, 2, 10, "块",
"熟肉", 0, 2, 11, "份",
"肉汤", 0, 2, 12, "碗",
"露水", 0, 1, 13, "份",
"雨水", 0, 1, 14, "份",
"雪水", 0, 1, 15, "份",
"面粉", 0, 1, 16, "份",
"小麦", 0, 1, 17, "粒",
"面包", 0, 2, 18, "块",
"饼干", 0, 2, 19, "片",
"土豆", 0, 2, 20, "颗",
"蜂蜜", 0, 2, 21, "份",
"小锉刀", 0, 3, 22, "把",
"长刀", 0, 3, 23, "把",
"利剑", 0, 3, 24, "把",
"淡水", 0, 1, 25, "份",
"咸水", 0, 1, 26, "份",
"土壤", 0, 1, 27, "堆",
"沙子", 0, 1, 28, "堆",
"火药", 0, 1, 29, "撮",
"炸药", 0, 3, 30, "个",
"矿石", 0, 1, 31, "块",
"麦芽啤酒", 0, 2, 32, "杯",
"大麦", 0, 1, 33, "粒",
};
Area area[10] = {
{"", N, {N, N, N}},
{"绿色草原", 1, {0, 1, 2, 13, 27}},
{"戈壁沙滩", 2, {2, 4, 0, 28, 8}},
{"石山瀑布", 3, {2, 4, 3, 14, 25}},
{"下游河流", 4, {25, 25, 4, 33, 17}},
{"大海边", 5, {26, 26, 26, 2, 28}},
{"远山", 6, {2, 31, 2, 3, 3}},
{"山顶洞穴", 7, {3, 31, 2 ,31, 31}},
};
string PlayerName;
//新函数
string _(button way[], int x, int y) {
int nowway = 0;
bool up[100] = { true, false, false };
bool down[100] = { true, false, false };
char c;
int now = 0;
for (int i = 0; i < 100; i++) {
if (down[i] == true) {
now = i;
}
}
while (1) {
gotoxy(x, y);
for (int i = 0; way[i].name != ""; i++) {
if (up[i] == true) {
color(240);
cout << "|" << way[i].name << "|";
color(15);
} else {
color(15);
cout << " " << way[i].name << " ";
}
}
printf("\n");
cout << endl;
for (int i = 0; way[nowway].b[i] != ""; i++) {
if (down[i] == true) {
color(127);
cout << " " << way[nowway].b[i] << " " << endl;
color(15);
} else {
color(15);
cout << " " << way[nowway].b[i] << " " << endl;
}
}
c = getch();
if ((c == 'w' || c == Up || c == '8') && now > 0) {
gotoxy(0, 0);
down[now] = false;
down[now - 1] = true;
now -= 1;
}
if ((c == 's' || c == Down || c == '2') && way[nowway].b[now + 1] != "") {
gotoxy(0, 0);
down[now] = false;
down[now + 1] = true;
now += 1;
}
if (c == 32) {
return way[nowway].b[now];
}
}
return "";
}
struct GAME {
void KillEnemy(int a) {
Cls();
system("color f0");
// 删掉这里的 srand!main只初始化一次即可
int safe;
if(a == 1) // 草原 最安全
safe = rand() % 2;
else if(a == 2) // 沙滩
safe = rand() % 3;
else if(a == 3) // 瀑布
safe = rand() % 3;
else if(a == 4) // 河流
safe = rand() % 4;
else if(a == 5) // 海边
safe = rand() % 5;
else if(a == 6) // 远山
safe = rand() % 6;
else if(a == 7) // 洞穴 最危险
safe = rand() % 7;
if (safe == 0) {
int collect1 = rand() % 5;
// 循环直到不重复,而非只随机一次
int collect2 = rand() % 5;
while(collect2 == collect1)
collect2 = rand() % 5;
int collect3 = rand() % 5;
while(collect3 == collect1 || collect3 == collect2)
collect3 = rand() % 5;
int howm1 = rand() % 20 + 4;
int howm2 = rand() % 15 + 6;
int howm3 = rand() % 10 + 8;
int type = rand() % 3 + 1;
cout << "这里安全,可以收集一些东西。" << endl << endl;
Sleep(600);
cout << "你收集了" << howm1 << thingsName[area[a].things[collect1]].LiangCi << thingsName[area[a].things[collect1]].Name;
if(type > 1)
{
cout << "和" << howm2 << thingsName[area[a].things[collect2]].LiangCi << thingsName[area[a].things[collect2]].Name;
}
if(type == 3)
{
cout << "。除此之外,还有" << howm3 << thingsName[area[a].things[collect3]].LiangCi << thingsName[area[a].things[collect3]].Name;
}
Sleep(1000);
cout << endl << endl;
color(10);
Pause();
}else
{}
}
void PrintTree(int x, int y) {
gotoxy(x, y + 4);
color(162);
cout << " ";
gotoxy(x + 1, y + 2);
cout << " ~ ~";
gotoxy(x + 2, y);
color(42);
cout << " ~ ~~ ";
gotoxy(x + 3, y + 4);
color(102);
cout << " ";
}
void Move() {
while (1) {
Cls();
syscolor("ef");
gotoxy(0, 0);
color(51);
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
for (int i = 0; i <= 29; i++) {
color(120);
gotoxy(i, 85 - i);
for (int j = 0; j <= 20; j++)
cout << " ";
color(135);
for (int j = 0; j <= 13 + i; j++) {
cout << " ";
}
}
color(234);
gotoxy(6, 25);
printf("γ ψ");
gotoxy(7, 25);
printf(" γ");
gotoxy(8, 25);
printf(" γ ψ");
gotoxy(9, 25);
printf(" γ ψ");
PrintTree(11, 27);
PrintTree(10, 31);
PrintTree(11, 35);
PrintTree(13, 32);
PrintTree(12, 36);
PrintTree(13, 40);
PrintTree(11, 37);
PrintTree(10, 41);
PrintTree(11, 45);
PrintTree(12, 42);
PrintTree(11, 46);
PrintTree(12, 50);
color(49);
gotoxy(0, 105);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(1, 105);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(2, 104);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(3, 104);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(4, 103);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(5, 103);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(6, 102);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(7, 102);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(8, 101);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(9, 101);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(10, 100);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(11, 100);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(12, 99);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(13, 99);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(14, 98);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(15, 98);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(16, 97);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(17, 97);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(18, 96);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(19, 96);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(20, 95);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(21, 95);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(22, 94);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(23, 94);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(24, 93);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(25, 93);
cout << " ";
color(17);
cout << " ";
color(49);
gotoxy(23, 0);
cout << " ";
gotoxy(24, 0);
cout << " ";
gotoxy(25, 0);
cout << " ";
gotoxy(26, 0);
cout << " ";
gotoxy(27, 0);
color(17);
cout << " ";
color(120);
gotoxy(28, 0);
cout << " ";
gotoxy(29, 0);
cout << " ";
color(135);
gotoxy(3, 86);
cout << "┌─┐";
gotoxy(4, 84);
cout << "┌ ┐";
gotoxy(5, 84);
cout << "└ ▲┘";
gotoxy(6, 86);
cout << "└─┘";
color(15);
gotoxy(0, 0);
cout << PlayerName <<",要去哪里?" << endl;
result = "";
result = _(outdo, 1, 0);
if (result == "1、草原") {
KillEnemy(1);
}
if (result == "2、沙滩") {
KillEnemy(2);
}
if (result == "3、瀑布") {
KillEnemy(3);
}
if (result == "4、河流") {
KillEnemy(4);
}
if (result == "5、海边") {
KillEnemy(5);
}
if (result == "6、远山") {
KillEnemy(6);
}
if (result == "7、山顶洞穴") {
KillEnemy(7);
}
if (result == "8、回家") {
GameMain();
}
}
Sleep(10000);
return;
}
void Story1() {
color(15);
gotoxy(0, 0);
slowprint(text[1]);
Sleep(1000);
color(10);
Pause();
Cls();
color(15);
slowprint(text[2]);
Sleep(1000);
color(10);
Pause();
Cls();
color(15);
slowprint(text[3]);
Sleep(1000);
color(10);
Pause();
Cls();
Sleep(3000);
}
void Story2() {
Sleep(5000);
slowprint(text[5]);
Sleep(2000);
slowprint(text[5]);
Sleep(2000);
Cls();
syscolor("8f");
Sleep(1000);
syscolor("7f");
Sleep(1000);
syscolor("f0");
Sleep(3000);
Isay();
slowprint(text[6]);
Sleep(3000);
Isay();
slowprint(text[7]);
Sleep(3000);
Isay();
slowprint(text[8]);
Sleep(3000);
Isay();
slowprint(text[9]);
Sleep(3000);
Isay();
slowprint(text[10]);
Sleep(6000);
}
void slowprint(outtext tet) {
for (int i = 0; i <= strlen(tet.text) - 1; i++) {
Beep(3000, 20);
printf("%c", tet.text[i]);
_sleep(tet.t);
}
}
void Isay() {
cout << PlayerName << ": ";
}
void Start() {
color(15);
Sleep(1000);
music.CloseMusic("Liudiam.mp3");
Story1();
Story2();
Cls();
//printf("───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────");
}
void MainMeum() {
//Run();
HideCursor();
ModeWindow(120, 30);
Art_Title("荒岛往事 Alpha V1.0.3");
Art_Windows(1);
color(63);
PrintSpace(30, 119);
music.SendMusic("Liudiam.mp3");
// 绘制沙滩
color(238);
gotoxy(27, 0);
PrintSpace(3, 119);
//黄238 白255
//绘制太阳
color(255);
gotoxy(3, 100);
cout << " ";
gotoxy(4, 100);
cout << " ";
gotoxy(5, 100);
cout << " ";
gotoxy(6, 100);
cout << " ";
// 绘制棕榈树
gotoxy(19, 8);
color(34);
printf(" ");
gotoxy(19, 16);
color(34);
printf(" ");
gotoxy(20, 10);
color(34);
printf(" ");
gotoxy(20, 14);
color(34);
printf(" ");
gotoxy(21, 12);
color(34);
printf(" ");
gotoxy(22, 12);
color(102);
printf(" ");
gotoxy(23, 12);
color(102);
printf(" ");
gotoxy(24, 12);
color(102);
printf(" ");
gotoxy(25, 12);
color(102);
printf(" ");
gotoxy(26, 12);
color(102);
printf(" ");
gotoxy(22, 10);
color(34);
printf(" ");
gotoxy(23, 8);
color(34);
printf(" ");
gotoxy(23, 16);
color(34);
printf(" ");
color(63);
gotoxy(13, 56);
printf("荒岛往事");
while (press != ' ') {
if (startchange == 1) {
gotoxy(15, 55);
printf("[开始游戏]");
gotoxy(17, 55);
printf(" 设置游戏 ");
gotoxy(19, 55);
printf(" 退出游戏 ");
}
if (startchange == 2) {
gotoxy(15, 55);
printf(" 开始游戏 ");
gotoxy(17, 55);
printf("[设置游戏]");
gotoxy(19, 55);
printf(" 退出游戏 ");
}
if (startchange == 3) {
gotoxy(15, 55);
printf(" 开始游戏 ");
gotoxy(17, 55);
printf(" 设置游戏 ");
gotoxy(19, 55);
printf("[退出游戏]");
}
press = getch();
if (press == Down)
if (startchange != 3)
startchange++;
else
startchange = 1;
if (press == Up)
if (startchange != 1)
startchange--;
else
startchange = 3;
music.SendMusic("Click.mp3");
Sleep(100);
}
if (startchange == 1) {
syscolor("7f");
Sleep(100);
syscolor("87");
Sleep(100);
syscolor("08");
Sleep(100);
Cls();
music.CloseMusic("Liudiam.mp3");
Cls();
color(15);
slowprint(text[4]);
cin >> PlayerName;
if(MessageBox(NULL, "是否跳过剧情?", "看到的入是给", MB_YESNO|MB_ICONQUESTION) == 7)
Start();
GameMain();
Sleep(10000);
} else if (startchange == 2) {
gotoxy(0, 0);
printf("上下键选择,空格键确定");
_getch();
startchange = 1;
press = 'v';
MainMeum();
} else if (startchange == 3)
exit(0);
return;
}
void Make_Text(string same, string name) {
ofstream outfile(same, ios::out);
if (!outfile) {
cerr << "open error" << endl;
}
outfile << name;
outfile.close();
}
void Hide() {
HWND s;
s = FindWindow("ConsoleWindowClass", NULL);//找到当前窗口句柄
if (s) {
ShowOwnedPopups(s, SW_HIDE);//显示或隐藏由指定窗口所有的全部弹出式窗口
ShowWindow(s, SW_HIDE);//隐藏窗口
}
}
BOOL IsOsWin7OrAbove() {
OSVERSIONINFOEX osInfo = {0};
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osInfo.dwMajorVersion = 6;
osInfo.dwMinorVersion = 1;
DWORDLONG conditionMask = 0;
VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_EQUAL);
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_EQUAL);
return VerifyVersionInfo(
&osInfo,
VER_MAJORVERSION | VER_MINORVERSION,
conditionMask
) != 0;
}
void PrintSpace(int H, int L) {
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= L; j++)
cout << " ";
cout << endl;
}
}
void Run() {
// BOOL CanRun = IsOsWin7OrAbove();
// if (CanRun == FALSE) {
// Hide();
// MessageBox(NULL, "很遗憾!\n此产品不支持当前系统版本!\n(仅支持 Windows 7)\n", "荒岛往事.exe 运行错误!", MB_ICONERROR | MB_OK);
// exit(0);
// }
}
void GameRun() {
MainMeum();
return;
}
void GameMain() {
Cls();
syscolor("f0");
printf("──────────时间:");
Random = rand() % 6;
if (Random == 0) {
Time = "早晨";
printf("早晨");
} else if (Random == 1) {
Time = "上午";
printf("上午");
} else if (Random == 2) {
Time = "中午";
printf("中午");
} else if (Random == 3) {
Time = "下午";
printf("下午");
} else if (Random == 4) {
Time = "晚上";
printf("晚上");
} else if (Random == 5) {
Time = "凌晨";
printf("凌晨");
}
printf("────季节:");
Random = rand() % 4;
if (Random == 0) {
Season = "春";
printf("春");
}
if (Random == 1) {
Season = "夏";
printf("夏");
}
if (Random == 2) {
Season = "秋";
printf("秋");
}
if (Random == 3) {
Season = "冬";
printf("冬");
}
Random = rand() % 7;
printf("────天气:");
if (Random == 0) {
Weather = "晴朗无云";
printf("晴朗无云");
}
if (Random == 1) {
Weather = "多云";
printf("多云──");
}
if (Random == 2) {
Weather = "阴";
printf("阴───");
}
if (Random == 3) {
Weather = "雨";
printf("雨───");
}
if (Random == 4) {
Weather = "大风";
printf("大风──");
}
if (Random == 5) {
Weather = "暴风雨";
printf("暴风雨─");
}
if (Random == 6 && Season == "冬") {
Weather = "雪";
printf("雪───");
}
printf("────生存天数:%d", LiveDay);
printf("───────────────────────────────────────────────────────\n");
cout << PlayerName <<"想要做什么?" << endl;
while (1) {
result = "";
result = _(homedo, 1, 0);
if (result == "1、移动") {
Move();
}
}
}
};
GAME games;
int main(void) {
srand((unsigned)time(NULL));
games.GameRun();
return 0;
}
喂!别急着走啊!按下Ctrl + D有惊喜啊QAQ

1168

被折叠的 条评论
为什么被折叠?



