2D生存(C++控制台)
作者还在更新,暂时比较菜,敬请期待!
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
#define White SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
#define Red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED)
#define Blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE)
#define Green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN)
#define Yellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN)
#define Pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED)
#define Qing SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE)
#define Orange SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN)
#define Purple SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_RED)
char tmp, book[101], tu[21][41];
int mugao, shigao, tiegao, jingao, zuanshigao, mujian, shijian, tiejian, jinjian, zuanshijian, shanghai;
short wuqi;
map <string, string> maps;
vector <string> mapt;
int _int, apple, mutou, shumiao, shitou, tieding, jin, zuanshi, tianshu = 1, kuijia;
int x, y, cnt, c, X, Y, xieliang = 20, baoshidu = 20, times, times2, jiangshi[21][41];
string s;
bool zombie, baitian = true;
queue <int> small_tree[3];
void Slowsay(std::string str, int x);
void fenge();
void youxi();
void make(int x);
unsigned long long R(unsigned long long MAX);
void print();
void tishi();
void wakuang();
void print2();
void ShowCursor(bool visible){
CONSOLE_CURSOR_INFO cursor_info = {20, visible};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int main(){
system("cls");
Slowsay("欢迎来到", 25);
Red;
Slowsay("2D生存", 50);
Green;
Slowsay(" 作者:Tjaweiof 版本:1.09", 25);
White;
fenge();
Slowsay("请输入数字:\n\n1.开始游戏\n2.获得一条随机的提示\n3.退出\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2' && tmp != '3' && tmp != 'x'){
tmp = getche();
}
system("cls");
if (tmp == 'x'){
tmp = '1';
kuijia = 10000;
zuanshijian = 100000;
zuanshi = 1000;
jin = 1000;
tieding = 1000;
shitou = 1000;
mutou = 10000000;
}
if (tmp == '1'){
system("cls");
Slowsay("游戏即将开始,请做好准备......", 25);
system("cls");
srand(time(NULL));
x = R(10);
zombie = true;
Slowsay("出生地:", 25);
switch (x){
case 1:
Green;
Slowsay("草原", 50);
break;
case 2:
Green;
Slowsay("草原", 50);
break;
case 3:
Yellow;
Slowsay("沙漠", 50);
break;
case 4:
Qing;
Slowsay("沼泽", 50);
break;
case 5:
Blue;
Slowsay("大海", 50);
break;
case 6:
y = R(2);
if (y == 1){
Red;
Slowsay("村庄", 50);
} else {
Blue;
Slowsay("大海", 50);
x = 5;
}
break;
case 7:
Green;
Slowsay("高山", 50);
break;
case 8:
White;
Slowsay("雪山", 50);
break;
case 9:
Green;
Slowsay("树林", 50);
break;
case 10:
Green;
Slowsay("树林", 50);
break;
default:
Slowsay("qwq", 50);
exit(0);
}
cout << " ";
Red;
Slowsay("全屏效果更加", 50);
Sleep(2000);
system("cls");
make(x);
youxi();
} else if (tmp == '2'){
x = R(14);
switch (x){
case 1:
Slowsay("【有用的提示】白天尽量砍树,没了树可以种。", 25);
Sleep(3000);
break;
case 2:
Slowsay("【有用的提示】如果一个僵尸在离你10格以内的地方,它会有70%的可能来追赶你。", 25);
Sleep(3000);
break;
case 3:
Slowsay("【有用的提示】战斗的时候也可以吃苹果。", 25);
Sleep(3000);
break;
case 4:
Slowsay("兄弟会背叛你,女人会离开你,金钱会诱惑你,生活会刁难你,只有数学不会,不会就是不会,怎么学都不会。", 25);
Sleep(3000);
break;
case 5:
Slowsay("Please use English.", 25);
Sleep(3000);
break;
case 6:
Slowsay("【有用的提示】提示中可能会有没用的提示。", 25);
Sleep(3000);
break;
case 7:
Slowsay("【有用的提示】只有提示前面标有“【有用的提示】”才是有用的。", 25);
Sleep(3000);
break;
case 8:
Slowsay("如果出现BUG请尽快在洛谷中联系作者!", 25);
Sleep(3000);
break;
case 9:
Slowsay("猫猫最可爱了!", 25);
Sleep(3000);
break;
case 10:
Slowsay("买彩票不一定会中奖,但不买彩票一定不会中奖。", 25);
Sleep(3000);
break;
case 11:
Slowsay("我不是想为原耽争取合法,而是想改变世俗骨子里的偏见。", 25);
Sleep(3000);
break;
case 12:
Slowsay("【有用的提示】砍一些树后,趁着天亮,快去挖矿!", 25);
Sleep(3000);
break;
case 13:
Slowsay("【有用的提示】多来刷一刷提示~你会发现它能帮你很多。", 25);
Sleep(3000);
break;
case 14:
Slowsay("【有用的提示】挖矿获得钻石后赶紧制作钻石剑,它可以帮助你打怪。", 25);
Sleep(3000);
break;
case 15:
Slowsay("【有用的提示】挖矿是需要耐心的。", 25);
Sleep(3000);
break;
case 16:
Slowsay("【有用的提示】你身上的盔甲可以无限叠加,但是一旦套上,就再也摘不下来了。", 25);
Sleep(3000);
break;
}
main();
} else if (tmp == '3'){
for (int i = 1; i <= 10; i++){
printf("退出中");
Slowsay("......", 50);
system("cls");
}
}
White;
return 0;
}
void Slowsay(std::string str, int x){
for (int i = 0; i < (int)str.size(); i++){
Sleep(x);
std::cout << str[i];
}
return;
}
void fenge(){
Yellow;
Slowsay("\n\n**************************************************分割线**************************************************\n\n", 5);
White;
return;
}
void youxi(){
system("cls");
while (true){
print();
tmp = getche();
switch (tmp){
case 'w':
X--;
times++;
times2++;
if (X < 1){
X = 1;
}
break;
case 's':
X++;
times++;
times2++;
if (X > 20){
X = 20;
}
break;
case 'a':
Y--;
times++;
times2++;
if (Y < 1){
Y = 1;
}
break;
case 'd':
Y++;
times++;
times2++;
if (Y > 40){
Y = 40;
}
break;
case 'b':
while (baoshidu < 20 && apple){
apple--;
baoshidu++;
}
break;
case 'p':
if (tu[X][Y] == 'G' && shumiao > 0){
shumiao--;
tu[X][Y] = 't';
small_tree[0].push(50 + R(30));
small_tree[1].push(X);
small_tree[2].push(Y);
}
break;
case 'c':
wakuang();
break;
case 'm':
system("cls");
Slowsay("制作列表:\n0.退出\n1.木镐 花费木头*4\n2.石镐 花费木头*1、石头*3\n3.铁镐 花费木头*1、铁*3\n4.金镐 花费木头*1、金*3\n5.钻石镐 花费木头*1、钻石*3\n6.木剑 花费木头*3\n7.石剑 花费木头*1、石头*2\n8.铁剑 花费木头*1、铁*2\n9.金剑 花费木头*1、金*3\n10.钻石剑 花费木头*1、钻石*3\n11.铁盔甲 花费铁*24\n12.金盔甲 花费金*24\n13.钻石盔甲 花费钻石*24\n14.超级盔甲 花费铁*20、金*20、钻石*20\n", 0);
cin >> _int;
if (_int == 0){
break;
}
while (_int != 1 && _int != 2 && _int != 3 && _int != 4 && _int != 5 && _int != 6 && _int != 7 && _int != 8 && _int != 9 && _int != 10 && _int != 11 && _int != 12 && _int != 13 && _int != 14){
system("cls");
printf("制作列表:\n1.木镐 花费木头*4\n2.石镐 花费木头*1、石头*3\n3.铁镐 花费木头*1、铁*3\n4.金镐 花费木头*1、金*3\n5.钻石镐 花费木头*1、钻石*3\n6.木剑 花费木头*3\n7.石剑 花费木头*1、石头*2\n8.铁剑 花费木头*1、铁*2\n9.金剑 花费木头*1、金*3\n10.钻石剑 花费木头*1、钻石*3\n11.铁盔甲 花费铁*24\n12.金盔甲 花费金*24\n13.钻石盔甲 花费钻石*24\n14.超级盔甲 花费铁*20、金*20、钻石*20\n");
cin >> _int;
if (_int == 0){
break;
}
}
if (_int == 1){
if (mutou < 4){
Slowsay("材料不够!", 25);
} else {
mutou -= 4;
Slowsay("制作成功!", 25);
mugao++;
}
} else if (_int == 2){
if (!mutou || shitou < 3){
Slowsay("材料不够!", 25);
} else {
mutou--;
shitou -= 3;
Slowsay("制作成功!", 25);
shigao++;
}
} else if (_int == 3){
if (!mutou || tieding < 3){
Slowsay("材料不够!", 25);
} else {
mutou--;
tieding -= 3;
Slowsay("制作成功!", 25);
tiegao++;
}
} else if (_int == 4){
if (!mutou || jin < 3){
Slowsay("材料不够!", 25);
} else {
mutou--;
jin -= 3;
Slowsay("制作成功!", 25);
jingao++;
}
} else if (_int == 5){
if (!mutou || zuanshi < 3){
Slowsay("材料不够!", 25);
} else {
mutou--;
zuanshi -= 3;
Slowsay("制作成功!", 25);
zuanshigao++;
}
} else if (_int == 6){
if (mutou < 3){
Slowsay("材料不够!", 25);
} else {
mutou -= 3;
Slowsay("制作成功!", 25);
mujian += 59;
}
} else if (_int == 7){
if (!mutou || shitou < 2){
Slowsay("材料不够!", 25);
} else {
mutou--;
shitou -= 2;
Slowsay("制作成功!", 25);
shijian += 131;
}
} else if (_int == 8){
if (!mutou || tieding < 2){
Slowsay("材料不够!", 25);
} else {
mutou--;
tieding -= 2;
Slowsay("制作成功!", 25);
tiejian += 250;
}
} else if (_int == 9){
if (!mutou || jin < 2){
Slowsay("材料不够!", 25);
} else {
mutou--;
jin -= 2;
Slowsay("制作成功!", 25);
jinjian += 32;
}
} else if (_int == 10){
if (!mutou || zuanshi < 2){
Slowsay("材料不够!", 25);
} else {
mutou--;
zuanshi -= 2;
Slowsay("制作成功!", 25);
zuanshijian += 1561;
}
} else if (_int == 11){
if (tieding < 24){
Slowsay("材料不够!", 25);
} else {
Slowsay("制作成功!", 25);
tieding -= 24;
kuijia += 199;
}
} else if (_int == 12){
if (jin < 24){
Slowsay("材料不够!", 25);
} else {
Slowsay("制作成功!", 25);
jin -= 24;
kuijia += 92;
}
} else if (_int == 13){
if (zuanshi < 24){
Slowsay("材料不够!", 25);
} else {
Slowsay("制作成功!", 25);
zuanshi -= 24;
kuijia += 287;
}
} else if (_int == 14){
if (tieding < 20 || jin < 20 || zuanshi < 20){
Slowsay("材料不够!", 25);
} else {
Slowsay("制作成功!", 25);
tieding -= 20;
jin -= 20;
zuanshi -= 20;
kuijia += 500;
}
}
break;
case 'f':
wuqi++;
wuqi %= 6;
break;
case ' ':
times++;
times2++;
switch (wuqi){
case 0:
shanghai = 1;
break;
case 1:
if (mujian){
shanghai = 5;
} else {
shanghai = 1;
}
break;
case 2:
if (shijian){
shanghai = 6;
} else {
shanghai = 1;
}
break;
case 3:
if (tiejian){
shanghai = 7;
} else {
shanghai = 1;
}
break;
case 4:
if (jinjian){
shanghai = 5;
} else {
shanghai = 1;
}
break;
case 5:
if (zuanshijian){
shanghai = 8;
} else {
shanghai = 1;
}
break;
}
if (jiangshi[X - 1][Y] || jiangshi[X + 1][Y] || jiangshi[X][Y - 1] || jiangshi[X][Y + 1]){
if (jiangshi[X - 1][Y]){
jiangshi[X - 1][Y] -= min(shanghai, jiangshi[X - 1][Y]);
}
if (jiangshi[X + 1][Y]){
jiangshi[X + 1][Y] -= min(shanghai, jiangshi[X + 1][Y]);
}
if (jiangshi[X][Y - 1]){
jiangshi[X][Y - 1] -= min(shanghai, jiangshi[X][Y - 1]);
}
if (jiangshi[X][Y + 1]){
jiangshi[X][Y + 1] -= min(shanghai, jiangshi[X][Y + 1]);
}
system("cls");
print2();
Sleep(500);
} else if (tu[X][Y] == 'T'){
tu[X][Y] = 'G';
apple += 2;
mutou += R(3) + 4;
shumiao += R(2) + 1;
}
break;
default:
break;
}
system("cls");
}
return;
}
typedef unsigned long long ull;
ull R(ull MAX)
{
ull a = 1;
a *= rand(); a *= rand(); a *= rand(); a *= rand(); a %= 1000000007;
a *= rand(); a *= rand(); a *= rand(); a *= rand(); a %= 998244353;
a *= rand(); a *= rand(); a *= rand(); a *= rand(); a %= 1000000007;
return a % MAX + 1;
}
void make(int x){
switch (x){
case 1:
for (int i = 1; i <= 50; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 15; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 15; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 8; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 12; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flowers";
mapt.push_back("F");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
case 2:
for (int i = 1; i <= 50; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 15; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 15; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 8; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 12; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flower";
mapt.push_back("F");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
case 3:
for (int i = 1; i <= 70; i++){
book[++cnt] = 'S';
}
maps["S"] = "Sand";
mapt.push_back("S");
for (int i = 1; i <= 20; i++){
book[++cnt] = 'C';
}
maps["C"] = "Cactus";
mapt.push_back("C");
for (int i = 1; i <= 7; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 1; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 2; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
case 4:
for (int i = 1; i <= 60; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 20; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'L';
}
maps["L"] = "Lotus";
mapt.push_back("L");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
maps["t"] = "treelet";
mapt.push_back("t");
c = 5;
break;
case 5:
for (int i = 1; i <= 80; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
maps["t"] = "treelet";
mapt.push_back("t");
c = 4;
break;
case 6:
for (int i = 1; i <= 25; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 2; i++){
book[++cnt] = 'C';
}
maps["C"] = "Cropland";
mapt.push_back("C");
for (int i = 1; i <= 4; i++){
book[++cnt] = 'H';
}
maps["H"] = "House";
mapt.push_back("H");
for (int i = 1; i <= 9; i++){
book[++cnt] = 'V';
}
maps["V"] = "Villager";
mapt.push_back("V");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 15; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flower";
mapt.push_back("F");
for (int i = 1; i <= 2; i++){
book[++cnt] = 'B';
}
maps["B"] = "Box";
mapt.push_back("B");
for (int i = 1; i <= 20; i++){
book[++cnt] = 'R';
}
maps["R"] = "Road";
mapt.push_back("R");
for (int i = 1; i <= 8; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
maps["t"] = "treelet";
mapt.push_back("t");
c = 11;
break;
case 7:
for (int i = 1; i <= 50; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 20; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 21; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 4; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flower";
mapt.push_back("F");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
case 8:
for (int i = 1; i <= 50; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 20; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 21; i++){
book[++cnt] = 'I';
}
maps["I"] = "Ice";
mapt.push_back("I");
for (int i = 1; i <= 9; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
maps["t"] = "treelet";
mapt.push_back("t");
c = 5;
break;
case 9:
for (int i = 1; i <= 70; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flower";
mapt.push_back("F");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
case 10:
for (int i = 1; i <= 70; i++){
book[++cnt] = 'T';
}
maps["T"] = "Tree";
mapt.push_back("T");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'G';
}
maps["G"] = "Grass";
mapt.push_back("G");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'W';
}
maps["W"] = "Water";
mapt.push_back("W");
for (int i = 1; i <= 10; i++){
book[++cnt] = 'S';
}
maps["S"] = "Stone";
mapt.push_back("S");
for (int i = 1; i <= 5; i++){
book[++cnt] = 'F';
}
maps["F"] = "Flower";
mapt.push_back("F");
maps["t"] = "treelet";
mapt.push_back("t");
c = 6;
break;
default:
Slowsay("qwq", 50);
exit(0);
break;
}
memset(tu, ' ', sizeof tu);
for (long long i = 1; i <= 20; i++){
for (long long j = 1; j <= 40; j++){
if (tu[i][j] != ' '){
continue;
}
x = R(100);
tu[i][j] = book[x];
}
}
X = R(20);
Y = R(40);
return;
}
void print(){
White;
ShowCursor(false);
if (jiangshi[X][Y]){
if (kuijia){
kuijia--;
} else {
xieliang--;
}
}
if (jiangshi[X - 1][Y]){
if (kuijia){
kuijia--;
} else {
xieliang--;
}
}
if (jiangshi[X + 1][Y]){
if (kuijia){
kuijia--;
} else {
xieliang--;
}
}
if (jiangshi[X][Y - 1]){
if (kuijia){
kuijia--;
} else {
xieliang--;
}
}
if (jiangshi[X][Y + 1]){
if (kuijia){
kuijia--;
} else {
xieliang--;
}
}
while (xieliang < 20 && baoshidu >= 16){
xieliang++;
baoshidu--;
}
if (xieliang <= 0){
Red;
Slowsay("你死了,游戏结束!!!", 200);
exit(0);
}
int lll = small_tree[0].size();
for (int i = 1; i <= lll; i++){
small_tree[0].front()--;
tu[small_tree[1].front()][small_tree[2].front()] = 'T';
int a = small_tree[0].front(), b = small_tree[1].front(), c = small_tree[2].front();
small_tree[0].pop();
small_tree[1].pop();
small_tree[2].pop();
if (a){
tu[b][c] = 't';
small_tree[0].push(a);
small_tree[1].push(b);
small_tree[2].push(c);
}
}
bool tmp[21][41] = {};
for (int i = 1; i <= 20; i++){
for (int j = 1; j <= 40; j++){
if (jiangshi[i][j] && !tmp[i][j]){
if (baitian){
jiangshi[i][j]--;
}
if (abs(X - i) + abs(Y - j) == 1 || abs(X - i) + abs(Y - j) > 10 || R(10) <= 3){
tmp[i][j] = true;
} else if (abs(X - i) >= abs(Y - j)){
if (X > i){
if (tmp[i + 1][j] || jiangshi[i + 1][j]){
tmp[i][j] = true;
continue;
}
tmp[i + 1][j] = true;
jiangshi[i + 1][j] += jiangshi[i][j];
jiangshi[i][j] = 0;
} else {
if (tmp[i - 1][j] || jiangshi[i - 1][j]){
tmp[i][j] = true;
continue;
}
tmp[i - 1][j] = true;
jiangshi[i - 1][j] += jiangshi[i][j];
jiangshi[i][j] = 0;
}
} else {
if (Y > j){
if (tmp[i][j + 1] || jiangshi[i][j + 1]){
tmp[i][j] = true;
continue;
}
tmp[i][j + 1] = true;
jiangshi[i][j + 1] += jiangshi[i][j];
jiangshi[i][j] = 0;
} else {
if (tmp[i][j - 1] || jiangshi[i][j - 1]){
tmp[i][j] = true;
continue;
}
tmp[i][j - 1] = true;
jiangshi[i][j - 1] += jiangshi[i][j];
jiangshi[i][j] = 0;
}
}
}
}
}
if (times == 20){
baoshidu--;
times = 0;
if (times2 == 100){
if (baitian){
baitian = false;
for (int i = 1; i <= pow(tianshu << 2, 2); i++){
jiangshi[R(20)][R(40)] = 20;
}
} else {
baitian = true;
tianshu++;
}
times2 = 0;
}
}
if (baitian){
cout << " 第" << tianshu << "天 白天" << endl;
} else {
cout << " 第" << tianshu << "天 夜晚" << endl;
}
if (baoshidu < 0){
baoshidu = 0;
}
if (!baoshidu){
xieliang--;
}
if (R(3) == 1 && !baitian){
jiangshi[R(20)][R(40)] = 20;
jiangshi[R(20)][R(40)] = 20;
jiangshi[R(20)][R(40)] = 20;
}
for (int i = 1; i <= 20; i++){
for (int j = 1; j <= 40; j++){
if (i == X && j == Y){
Red;
} else if (jiangshi[i][j]){
Green;
}
printf("%c ", tu[i][j]);
White;
}
if (i == 1){
printf(" 字母解释:");
} else if (i - 1 <= c){
printf(" ");
cout << mapt[i - 2];
printf(" is ");
cout << maps[mapt[i - 2]];
}
printf("\n");
}
Yellow;
printf("\n\n**************************************************分割线**************************************************\n\n");
White;
printf("血量:%d 饱食度:%d 苹果:%d个 树苗:%d棵 木头:%d根 石头:%d块 铁:%d块 金:%d块 钻石:%d块 武器:", xieliang, baoshidu, apple, shumiao, mutou, shitou, tieding, jin, zuanshi);
switch (wuqi){
case 0:
printf("空");
break;
case 1:
printf("木剑 耐久度:%d", mujian);
break;
case 2:
printf("石剑 耐久度:%d", shijian);
break;
case 3:
printf("铁剑 耐久度:%d", tiejian);
break;
case 4:
printf("金剑 耐久度:%d", jinjian);
break;
case 5:
printf("钻石剑 耐久度:%d", zuanshijian);
break;
}
printf(" 盔甲总耐久:%d", kuijia);
printf("\n\n请输入动作: w:向上,s:向下,a:向左,d:向右,q:丢弃,b:进食,p:种植,c:挖矿, m:制作,空格:攻击(全方位)/破坏(脚下),f:切换武器");
if (xieliang <= 5){
Red;
printf("\n请注意,你的血量过低,请补充!!!\n");
}
ShowCursor(true);
return;
}
void wakuang(){
system("cls");
bool diyu = false, modi = false;
if (!mugao && !shigao && !tiegao && !jingao && !zuanshigao){
Slowsay("你没有任何镐子,请制作!!!", 25);
return;
}
int _shitou = 0, _tieding = 0, _jin = 0, _zuanshi = 0;
while (mugao){
Slowsay("是否使用木镐?\n\n1.是\n2.否\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("正在挖矿,请稍等......", 25);
for (int i = 1; i <= 10; i++){
system("cls");
printf("正在挖矿,请稍等");
Slowsay("......", 25);
}
system("cls");
mugao--;
_shitou += 15 + R(5);
Slowsay("你获得了", 25);
cout << _shitou;
Slowsay("块石头!", 25);
shitou += _shitou;
_shitou = 0;
system("cls");
if (R(1000000) == 1){
diyu = true;
}
if (R(10000000) == 1){
modi = true;
}
} else {
break;
}
}
while (shigao){
Slowsay("是否使用石镐?\n\n1.是\n2.否\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("正在挖矿,请稍等......", 25);
for (int i = 1; i <= 20; i++){
system("cls");
printf("正在挖矿,请稍等");
Slowsay("......", 25);
}
system("cls");
shigao--;
_shitou += 20 + R(10);
_tieding += 1 + R(3);
Slowsay("你获得了", 25);
cout << _shitou;
Slowsay("块石头、", 25);
cout << _tieding;
Slowsay("块铁!", 25);
shitou += _shitou;
_shitou = 0;
tieding += _tieding;
_tieding = 0;
system("cls");
if (R(10000) == 1){
diyu = true;
}
if (R(1000000) == 1){
modi = true;
}
} else {
break;
}
}
while (tiegao){
Slowsay("是否使用铁镐?\n\n1.是\n2.否\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("正在挖矿,请稍等......", 25);
for (int i = 1; i <= 50; i++){
system("cls");
printf("正在挖矿,请稍等");
Slowsay("......", 25);
}
system("cls");
tiegao--;
_shitou += 50 + R(15);
_tieding += 2 + R(5);
_jin += R(3) - 1;
_zuanshi += R(2) - 1;
Slowsay("你获得了", 25);
cout << _shitou;
Slowsay("块石头、", 25);
cout << _tieding;
Slowsay("块铁、", 25);
cout << _jin;
Slowsay("块金、", 25);
cout << _zuanshi;
Slowsay("块钻石!", 25);
shitou += _shitou;
_shitou = 0;
tieding += _tieding;
_tieding = 0;
jin += _jin;
_jin = 0;
zuanshi += _zuanshi;
_zuanshi = 0;
system("cls");
if (R(100) == 1){
diyu = true;
}
if (R(10000) == 1){
modi = true;
}
} else {
break;
}
}
while (jingao){
Slowsay("是否使用金镐?\n\n1.是\n2.否\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("正在挖矿,请稍等......", 25);
for (int i = 1; i <= 15; i++){
system("cls");
printf("正在挖矿,请稍等");
Slowsay("......", 25);
}
system("cls");
jingao--;
_shitou += 40 + R(20);
_tieding += 3 + R(2);
_jin += R(3) - 1;
_zuanshi += R(2) - 1;
Slowsay("你获得了", 25);
cout << _shitou;
Slowsay("块石头、", 25);
cout << _tieding;
Slowsay("块铁、", 25);
cout << _jin;
Slowsay("块金、", 25);
cout << _zuanshi;
Slowsay("块钻石!", 25);
shitou += _shitou;
_shitou = 0;
tieding += _tieding;
_tieding = 0;
jin += _jin;
_jin = 0;
zuanshi += _zuanshi;
_zuanshi = 0;
system("cls");
if (R(50) == 1){
diyu = true;
}
if (R(5000) == 1){
modi = true;
}
} else {
break;
}
}
while (zuanshigao){
Slowsay("是否使用钻石镐?\n\n1.是\n2.否\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("正在挖矿,请稍等......", 25);
for (int i = 1; i <= 70; i++){
system("cls");
printf("正在挖矿,请稍等");
Slowsay("......", 25);
}
system("cls");
zuanshigao--;
_shitou += 100 + R(50);
_tieding += 10 + R(20);
_jin += 5 + R(5);
_zuanshi += 3 + R(7);
Slowsay("你获得了", 25);
cout << _shitou;
Slowsay("块石头、", 25);
cout << _tieding;
Slowsay("块铁、", 25);
cout << _jin;
Slowsay("块金、", 25);
cout << _zuanshi;
Slowsay("块钻石!", 25);
shitou += _shitou;
_shitou = 0;
tieding += _tieding;
_tieding = 0;
jin += _jin;
_jin = 0;
zuanshi += _zuanshi;
_zuanshi = 0;
system("cls");
if (R(5) == 1){
diyu = true;
}
if (R(100) == 1){
modi = true;
}
} else {
break;
}
}
system("cls");
if (diyu){
Slowsay("你在这次挖矿中发现了一个地狱传送门,你有两种选择:\n1.进入\n2.回家\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
system("cls");
printf("你在这次挖矿中发现了一个地狱传送门,你有两种选择:\n1.进入\n2.回家\n");
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("你进入了地狱传送门.................................", 25);
} else if (tmp == '2'){
system("cls");
Slowsay("你回到了家里", 25);
}
}
if (modi){
Slowsay("你在这次挖矿中发现了一个末地传送门,你有两种选择:\n1.进入\n2.回家\n", 25);
tmp = getche();
while (tmp != '1' && tmp != '2'){
system("cls");
printf("你在这次挖矿中发现了一个末地传送门,你有两种选择:\n1.进入\n2.回家\n");
tmp = getche();
}
if (tmp == '1'){
system("cls");
Slowsay("你进入了末地传送门.................................", 25);
} else if (tmp == '2'){
system("cls");
Slowsay("你回到了家里", 25);
}
}
return;
}
void print2(){
White;
ShowCursor(false);
if (baitian){
cout << " 第" << tianshu << "天 白天" << endl;
} else {
cout << " 第" << tianshu << "天 夜晚" << endl;
}
for (int i = 1; i <= 20; i++){
for (int j = 1; j <= 40; j++){
if (i == X && j == Y){
Red;
} else if (jiangshi[i][j]){
if (abs(i - X) + abs(j - Y) == 1){
Orange;
} else {
Green;
}
}
if (jiangshi[i][j]){
printf("%2d", jiangshi[i][j]);
} else {
printf("%c ", tu[i][j]);
}
White;
}
if (i == 1){
printf(" 字母解释:");
} else if (i - 1 <= c){
printf(" ");
cout << mapt[i - 2];
printf(" is ");
cout << maps[mapt[i - 2]];
}
printf("\n");
}
Yellow;
printf("\n\n**************************************************分割线**************************************************\n\n");
White;
printf("血量:%d 饱食度:%d 苹果:%d个 树苗:%d棵 木头:%d根 石头:%d块 铁:%d块 金:%d块 钻石:%d块 武器:", xieliang, baoshidu, apple, shumiao, mutou, shitou, tieding, jin, zuanshi);
switch (wuqi){
case 0:
printf("空");
break;
case 1:
printf("木剑 耐久度:%d", mujian);
break;
case 2:
printf("石剑 耐久度:%d", shijian);
break;
case 3:
printf("铁剑 耐久度:%d", tiejian);
break;
case 4:
printf("金剑 耐久度:%d", jinjian);
break;
case 5:
printf("钻石剑 耐久度:%d", zuanshijian);
break;
}
printf(" 盔甲总耐久:%d", kuijia);
printf("\n\n请输入动作: w:向上,s:向下,a:向左,d:向右,q:丢弃,b:进食,p:种植,c:挖矿, m:制作,空格:攻击(全方位)/破坏(脚下),f:切换武器");
if (xieliang <= 5){
Red;
printf("\n请注意,你的血量过低,请补充!!!\n");
}
ShowCursor(true);
return;
}