c++野外生存

//转自:https://www.luogu.com.cn/team/32221#main
//收藏者的温馨提示:部分情节作者没有更完就咕咕咕啦
//如果你编译报错,请点击工具-编译选项-勾选编译时加入以下命令,在下面的框中输入:-std=c++11,确定即可
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <fstream>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
struct thing
{
   
    string type;
    string name;
    int attack;
    int defense;
    int health;
    int num;
    bool disposable;
    int sharp;
    int durability;
};
struct w
{
   
    string name;
    string b[100];
    int bnum;
};
int health = 1000, maxhealth = 1000, defense = 10, attack = 100;
int capacity = 0;
string name;
int nowway = 0, water = 0, maxwater = 10;
int bagi = 1, protectlevel;
string protect;
string canmakething[1000] = {
    "退出","木剑","木斧","木镐","工作台" };
int canmakethingi = 5;
string f[100] = {
   
    {
   "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"},
    {
   "+..................................................................................................+"},
    {
   "+..................................................................................................+"},
    {
   "+.........+............................................K...........................................+"},
    {
   "+.......FV+........................................................................................+"},
    {
   "+...................F..........T...................................................................+"},
    {
   "+........+................+.............+.............V.......................CF...................+"},
    {
   "+.......+..........................................................................................+"},
    {
   "+.............................................................+.H.+..............B.................+"},
    {
   "+......F.......+.......+............V............................+.................................+"},
    {
   "+...............V....+...............................................................Y.............+"},
    {
   "+....................F+.......+++............++....................................................+"},
    {
   "+.............................+C+.......o....I+.....o...................S..........F...............+"},
    {
   "+..........................................+++.....................................................+"},
    {
   "+.............................+.........................V..........................................+"},
    {
   "+.........Y...........H......+..........o.......+..A...........+...................................+"},
    {
   "+...........................+..................o+............++....G..............YV...............+"},
    {
   "+.....................................................+......+.I...................................+"},
    {
   "+......................+++.......................+++..........+....................................+"},
    {
   "+.....................+..U+......................V........+....+.............Y.....................+"},
    {
   "+.......H...........++...++........................................................................+"},
    {
   "+.......................+Y................++...................M...................................+"},
    {
   "+......................................+...G+...........T..........................................+"},
    {
   "+...H..............W............................................................Y..................+"},
    {
   "+..................................................................................................+"},
    {
   "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"},
};
bool isf[100][100];
int movex[4] = {
    0,-1,0,1 };
int movey[4] = {
    -1,0,1,0 };
//H巨坑 I铁矿 C煤矿 G金矿 o小镇 Y城市 V洞穴 S飞船 F战场 M沼泽 T钛矿 P前哨 B硫磺矿 K军事基地
int Outpostx[100], opxi = 0;
int Outposty[100], opyi = 0;
w way[100] = {
   
    {
   "池塘",{
   "进入森林","背包","状态","装备","制作"}, 5},
    {
   "帮助&设置",{
   "制造配方"},1}
};
int waynum = 2;
bool isw[100] = {
    true, false, false };
bool isb[100] = {
    true, false, false };
thing nowaxe, nowpickaxe, nowweapon, nowhoe;
thing bag[1000] = {
   
    {
   "退出","退出",0,0,0,0,false},
};
string outbutton()
{
   
    char c;
    int now = 0;
    for (int i = 0; i < 100; i++)
    {
   
        if (isb[i] == true)
        {
   
            now = i;
        }
    }
    while (1)
    {
   
        system("cls");
        for (int i = 0; way[i].name != ""; i++)
        {
   
            if (isw[i] == true)
            {
   
                cout << "*" << way[i].name << "*";
            }
            else
            {
   
                cout << " " << way[i].name << " ";
            }
        }
        cout << endl;
        for (int i = 0; way[nowway].b[i] != ""; i++)
        {
   
            if (isb[i] == true)
            {
   
                cout << ">" << way[nowway].b[i] << "<" << endl;
            }
            else
            {
   
                cout << " " << way[nowway].b[i] << " " << endl;
            }
        }
        c = _getch();
        if (c == 'w' && now > 0)
        {
   
            isb[now] = false;
            isb[now - 1] = true;
            now -= 1;
        }
        if (c == 's' && way[nowway].b[now + 1] != "")
        {
   
            isb[now] = false;
            isb[now + 1] = true;
            now += 1;
        }
        if (c == 'a' && nowway > 0)
        {
   
            isw[nowway] = false;
            isw[nowway - 1] = true;
            nowway -= 1;
            isb[now] = false;
            isb[0] = true;
        }
        if (c == 'd' && way[nowway + 1].name != "")
        {
   
            isw[nowway] = false;
            isw[nowway + 1] = true;
            nowway += 1;
            isb[now] = false;
            isb[0] = true;
        }
        if (c == 32)
        {
   
            return way[nowway].b[now];
        }
    }
    return "";
}
string outbag()
{
   
    char c;
    int now = 0;
    bool isbag[1000] = {
    true, false };
    while (1)
    {
   
        system("cls");
        for (int i = 0; bag[i].name != ""; i++)
        {
   
            if (isbag[i] == true)
            {
   
                cout << ">" << bag[i].name << "<";
            }
            else
            {
   
                cout << " " << bag[i].name << " ";
            }
            for (int j = 0; j < 20 - bag[i].name.size() - to_string(bag[i].num).size(); j++)
            {
   
                cout << " ";
            }
            cout << bag[i].num << "    " << bag[i].durability << endl;
        }
        c = _getch();
        if (c == 'w' && now > 0)
        {
   
            isbag[now] = false;
            isbag[now - 1] = true;
            now -= 1;
        }
        if (c == 's' && bag[now + 1].name != "")
        {
   
            isbag[now] = false;
            isbag[now + 1] = true;
            now += 1;
        }
        if (c == 32)
        {
   
            return bag[now].name;
        }
    }
    return 0;
}
bool skills[10];//勘察术 美食家 矿工 收集家 野蛮人 战士 铠甲人 医生 忍者
int fight(string hn, int hmh, int ha, int hd, int hh)
{
   
    while (1)
    {
   
        if (nowweapon.type == "剑") cout << "1,扎刺";
        else if (nowweapon.type == "刀") cout << "1,劈砍";
        else if (nowweapon.type == "机枪") cout << "1,扫射";
        else if (nowweapon.type == "手枪") cout << "1,射击";
        else if (nowweapon.type == "") cout << "1,拳击";
        bool is1 = false, is2 = false, is3 = false;
        int i1, i2, i3;
        for (int i = 0; i < 1000; i++)
        {
   
            if (bag[i].name == "手雷" && bag[i].num != 0)
            {
   
                cout << " 2,丢出[" << bag[i].num << "]";
                is1 = true;
                i1 = i;
                break;
            }
        }
        for (int i = 0; i < 1000; i++)
        {
   
            if (bag[i].name == "长矛" && bag[i].num != 0)
            {
   
                cout << " 3,投掷[" << bag[i].num << "]";
                is2 = true;
                i2 = i;
                break;
            }
        }
        for (int i = 0; i < 1000; i++)
        {
   
            if (bag[i].name == "熏肉" && bag[i].num != 0)
            {
   
                cout << " 4,吃肉[" << bag[i].num << "]";
                is3 = true;
                i3 = i;
                break;
            }
        }
        if (skills[7])
        {
   
            cout << "5,医治";
        }
        string which;
        cin >> which;
        int bullet = 0, missile = 0;
        for (int i = 0; i < 1000; i++)
        {
   
            if (bag[i].name == "子弹")
            {
   
                bullet = bag[i].num;
            }
            if (bag[i].name == "导弹")
            {
   
                missile = bag[i].num;
            }
            else if (bag[i].name == "")
            {
   
                break;
            }
        }
        if (which == "1")
        {
   
            if (nowweapon.type == "剑" || nowweapon.type == "刀" || nowweapon.type == "")
            {
   
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "] @       E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]  @      E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]   @     E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]    @    E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]     @   E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]      @  E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]       @ E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]        @E[" << hh << "/" << hmh << "]";
                if (skills[5]) hh -= (attack + nowweapon.attack) * 2 - hd;
                else hh -= attack + nowweapon.attack - hd;
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]      @  E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]    @    E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]  @      E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
            }
            else if (nowweapon.name == "激光步枪" || bullet > 0 || (nowweapon.name == "火箭筒" && missile > 0))
            {
   
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@o       E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@ o      E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@  o     E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@   o    E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@    o   E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@     o  E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@      o E[" << hh << "/" << hmh << "]";
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@       oE[" << hh << "/" << hmh << "]";
                if (skills[5]) hh -= (attack + nowweapon.attack) * 2 - hd;
                else hh -= attack + nowweapon.attack - hd;
                Sleep(10);
                system("cls");
                cout << "\n\n\n\n\n";
                cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
            }
            else if (bullet <= 0 || (nowweapon.name == "火箭筒" && missile <= 0))
            {
   
                MessageBox(0, TEXT("没弹药了..."), TEXT("重要提示"), MB_OK);
            }
        }
        else if (which == "2" && is1)
        {
   
            hh -= 500;
            system("cls");
            cout << "砰!";
            Sleep(1000);
            system("cls");
            cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
            bag[i1].num--;
        }
        else if (which == "3" && is2)
        {
   
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@>       E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@->      E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@ ->     E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@  ->    E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@   ->   E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@    ->  E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@     -> E[" << hh << "/" << hmh << "]";
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@      ->E[" << hh << "/" << hmh << "]";
            hh -= 200 - hd;
            Sleep(10);
            system("cls");
            cout << "\n\n\n\n\n";
            cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
            bag[i2].num--;
        }
        else if (which == "4" && is3)
        {
   
            if (skills[2])
            {
   
                cout << "生命+1000";
                health += 1000;
                if (health > maxhealth)
                {
   
                    health = maxhealth;
                }
            }
            else
            {
   
                cout << "生命+500";
                health += 500;
                if (health > maxhealth)
                {
   
                    health = maxhealth;
                }
            }
            bag[is3].num--;
        }
        else if (which == "5" && skills[7])
        {
   
            cout << "生命+1500";
            health += 1500;
            if (health > maxhealth)
            {
   
                health = maxhealth;
            }
        }
        if (hh <= 0)
        {
   
            cout << "对方死亡";
            Sleep(1000);
            return 1;
        }
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@       E [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@      E  [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@     E   [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@    E    [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@   E     [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@  E      [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@ E       [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@E        [" << hh << "/" << hmh << "]";
        if (skills[8])
        {
   
            if (rand() % 3 == 2) health -= ha + -defense;
        }
        else if (rand() % 2) health -= ha + -defense;
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@  E      [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@    E    [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@      E  [" << hh << "/" << hmh << "]";
        Sleep(10);
        system("cls");
        cout << "\n\n\n\n\n";
        cout << "[" << health << "/" << maxhealth << "]@        E[" << hh << "/" << hmh << "]";
        Sleep(1000);
        cout << endl;
        if (health <= 0)
        {
   
            cout << "你死亡";
            Sleep(1000);
            return 0;
        }
    }
    return 0;
}
void slowly(const char* p)
{
   
    while (1)
    {
   
        if (*p != 0)
        {
   
            printf("%c", *p++);
        }
        else
        {
   
            break;
        }
        Sleep(75);
    }
}
int welcome()
{
   
    cout << "野外生存1.1.0 (不支持存档)" << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "         本页面会持续更新...   " << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "" << endl;
    _getch();
    return 0;
}
int start()
{
   
    system("cls");
    cout << "□□□□□□■□□□□□□□□□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□■■□□□□□□□□□□□□□□□□□■□□" << endl;
    cout << "□□□□□□■■■□□□□□□□□□□□□□□□■■□□" << endl;
    cout << "□□□■■■■■■■■■■■■■■■□□□□■■■■□□" << endl;
    cout << "□□■□■□■□■□■□■□■□■□■■■■■■■■□□" << endl;
    cout << "□□□■■■■■■■■■■■■■■■■■■■■■■□□□" << endl;
    cout << "□□□□□□□□■■■■■□□□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□□□□■■■■■□□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□□□□□□■■■□□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□□□□□□□■■■□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□□□□□□□□■■■□□□□□□□□□□□□" << endl;
    slowly("一天,你坐着飞机,正打算去美国...");
    Sleep(1000);
    system("cls");
    cout << "□□□□□□■□□□□□□□□□□□□□□□□□□□□□" << endl;
    cout << "□□□□□□■■□□□□□□□□□□□□□□□□□■□□" << endl;
    cout << "□□□□□□■■■□□□□□□□□□□□□□□□■■□□" << endl;
    cout << "□□□■■■■■■■■■■■■■■■□□□□■■■■□□" << endl;
    cout &l
#include<bits/stdc++.h> #include<windows.h> using namespace std; int choice; int a=0,b=0,c=0,d=0; int user_input; void S(int Color) { HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hCon,Color); } void wait() { Sleep(100); user_input=getchar(); } void cls() { Sleep(100); system("cls"); } int main(int argc, char *argv[]) { S(172); start:cls(); goto a1; gameover:printf("游戏结束。"); printf("按回车键继续"); user_input=getchar(); goto start; a1:printf("现在游戏开始。"); user_input=getchar(); printf("一天,你正在开飞机经过一片雪山区。"); wait(); printf("忽然你的操作系统失控了,飞机直直地坠入山中。"); wait(); printf("你朝两旁看了看,左边是雪地,右边是树林。而你正前方是悬崖,所以你不得不转弯。\n1-左转。\n2-右转。\n"); s1:wait(); switch(user_input) { case'1':goto a8; case'2':goto a13; default:goto s1; } a2:cls(); printf("你下了飞机,走向树林。"); wait(); printf("过了一会儿,你感到又饿又冷,就喝了一点威士忌,坐下休息。"); wait(); printf("但是,威士忌并没有让你觉得温暖。你只是觉得很冷、很冷。\n"); goto gameover; a3:cls(); printf("你吃了一些果实,还摘了一些放在口袋,想晚一点吃。"); wait(); printf("过了一会儿,你的肚子剧烈的痛起来。这时,你才意识到,果子有毒!\n"); goto gameover; a4:cls(); printf("你是否要继续往隧道里走?\n1-是。\n2-不了。\n"); s4:wait(); switch(user_input) { case'1':goto a18; case'2':goto a22; default:goto s4; } a5:cls(); printf("你能带三件东西下飞机。请选择:\n1-香蕉、打火机、外套。\n2-威士忌、外套、匕首。\n"); s5:wait(); switch(user_input) { case'1':goto a10; case'2':goto a2; default:goto s5; } a6:cls(); printf("你走到了隧道里,隧道里很黑,忽然你被一个东西绊倒了。\n"); wait(); printf("你爬起来,看了看地上的东西,原来是一条麻绳。\n1-捡起来。\n2-置之不理。\n"); s6:wait(); switch(user_input) { case'1':goto a11; case'2':goto a23; default:goto s6; } a7:cls(); printf("你呆在飞机里,感到越来越冷,你不得不离开了飞机。\n"); goto a5; a8:cls(); printf("随着“噗”地一声闷响,你的飞机安全降落在雪地上。"); wait(); printf("你要离开飞机去找东西吗?\n1-离开。\n2-待着。\n"); s8:wait(); switch(user_input) { case'1':goto a5; case'2':goto a7; default:goto s8; } a9:cls(); printf("你走出了隧道,继续走。\n"); wait(); printf("你来到了一个山谷前。"); wait(); printf("要走过去吗?\n1-走。\n2-不走。\n"); s9:wait(); switch(user_input) { case'1':goto a17; case'2':goto a12; default:goto s9; } a10:cls(); printf("你下了飞机,漫无目的地寻找食物。\n"); wait(); printf("你看到了一棵树,树上结着一种你从未见过的果子。\n1-吃一点。\n2-离开。\n"); s10:wait(); switch(user_input) { case'1':goto a3; case'2':goto a15; default:goto s10; } a11:cls(); printf("你捡起了绳子,发现它很长。"); a++; wait(); wait(); goto a22; a12:cls(); printf("你没有走进山谷,而是继续走。\n"); wait(); printf("很快,你就因饥饿死去了。\n"); wait(); goto gameover; a13:cls(); printf("“轰”,你的飞机撞上了树,爆炸了。"); wait(); goto gameover; a14:cls(); printf("你追着飞机跑。但是,飞机比你快太多了,你没有追上。"); wait(); printf("你很累很累,倒在了地上。"); wait(); printf("你死于虚脱。\n"); wait(); goto gameover; a15:cls(); printf("你没有吃果子,而是继续走。你走了很久,来到一个隧道口。\n1-进去。\n2-不进去。\n"); s15:wait(); switch(user_input) { case'1':goto a6; case'2':goto a21; default:goto s15; } a16:cls(); printf("你捞起了很多鱼,找了些树枝,烤了鱼来吃。"); wait(); printf("你觉得好多了。"); wait(); printf("这时,天空中传来嗡嗡的响声。你抬头一看,有飞机!\n1-追着飞机跑。\n2-点篝火。\n"); s16:wait(); switch(user_input) { case'1':goto a14; case'2':goto a20; default:goto s16; } a17:cls(); printf("你走了很久,有些体力不支,于是你把香蕉吃了。"); wait(); printf("你走了很久,来到了一个废弃矿坑边。\n1-探索一下。\n2-离开。\n"); s17:wait(); switch(user_input) { case'1':goto a24; case'2':goto a19; default:goto s17; } a18:cls(); printf("你继续往隧道里走,你感觉呼吸越来越难受。\n"); wait(); wait(); printf("你死于窒息。\n"); wait(); goto gameover; a19:cls(); printf("你来到了一个冰封的湖边。"); wait(); if(a==1) { if(b==1) { printf("你用麻绳织了个渔网,用锤子砸破冰面,试图捞上一些鱼。\n"); wait(); goto a16; } else { printf("你用麻绳织了个渔网,却无法打破冰面。你无奈地望着湖面,绝望地叹了口气。\n"); wait(); printf("你饿死了。\n"); wait(); goto gameover; } } else { if(b==1) { printf("你用锤子砸破了冰面,却没办法捞鱼。你无奈地望着湖面,绝望地叹了口气。\n"); wait(); printf("你饿死了。\n"); wait(); goto gameover; } else { printf("你很想捞鱼,却无法打破冰面,又没办法捞鱼。你无奈地望着湖面,绝望地叹了口气。\n"); wait(); printf("你饿死了。\n"); wait(); goto gameover; } } a20:cls(); printf("你找来许多木头,点燃了篝火。飞机上的人看见了浓烟,降落下来,把你救上了飞机。\n"); wait(); printf("事后,你被送去了医院治疗。\n"); printf("生存成功!\n"); wait(); goto gameover; a21:cls(); printf("你绕过了隧道,继续走。\n"); goto a9; a22:cls(); printf("你要继续走吗?\n1-是。\n2-不了。\n"); s22:wait(); switch(user_input) { case'1':goto a18; case'2':goto a9; default:goto s22; } a23:cls(); printf("你没有捡起绳子。"); wait(); wait(); goto a22; a24:cls(); printf("你找到了一把锤子。\n"); b++; wait(); wait(); goto a19; return 0; }
好的,生存游戏可以理解为一种模拟人类在野外生存的游戏,我们可以采用以下的设计思路: 1. 定义生物基类,包括生物的基本属性和行为; 2. 定义人类类,包括人类独特的属性和行为,比如饮食、睡眠、狩猎等; 3. 定义动物类,包括动物的属性和行为,比如食性、繁殖等; 4. 定义地图类,用于表示游戏世界,包括地形、环境、资源等; 5. 定义游戏类,用于控制游戏的整个流程,包括初始化、循环、退出等。 以下是用C++实现的示例代码: ```cpp #include <iostream> #include <vector> #include <cstdlib> #include <ctime> // 生物基类 class Creature { public: Creature(int health, int age) : health_(health), age_(age) {} virtual ~Creature() {} virtual void Eat() = 0; // 吃 virtual void Sleep() = 0; // 睡觉 virtual void Move() = 0; // 移动 virtual void Die() { health_ = 0; } // 死亡 int GetHealth() const { return health_; } int GetAge() const { return age_; } protected: int health_; // 生命值 int age_; // 年龄 }; // 人类类 class Human : public Creature { public: Human(int health, int age, int hunger) : Creature(health, age), hunger_(hunger) {} void Eat() override { hunger_ = 0; health_ += 10; } void Sleep() override { health_ += 5; } void Move() override { health_ -= 5; hunger_ += 5; } int GetHunger() const { return hunger_; } private: int hunger_; // 饥饿度 }; // 动物类 class Animal : public Creature { public: Animal(int health, int age, int hunger) : Creature(health, age), hunger_(hunger) {} void Eat() override { hunger_ = 0; health_ += 5; } void Sleep() override { health_ += 3; } void Move() override { health_ -= 3; hunger_ += 3; } int GetHunger() const { return hunger_; } private: int hunger_; // 饥饿度 }; // 地图类 class Map { public: Map(int width, int height) : width_(width), height_(height) {} void AddCreature(Creature* creature, int x, int y) { if (x >= 0 && x < width_ && y >= 0 && y < height_) { creatures_[x][y].push_back(creature); } } void RemoveCreature(Creature* creature, int x, int y) { if (x >= 0 && x < width_ && y >= 0 && y < height_) { auto& creatures = creatures_[x][y]; creatures.erase(std::remove(creatures.begin(), creatures.end(), creature), creatures.end()); } } std::vector<Creature*>& GetCreatures(int x, int y) { return creatures_[x][y]; } private: int width_; int height_; std::vector<Creature*> creatures_[100][100]; }; // 游戏类 class Game { public: Game() : map_(100, 100) {} void Init() { srand(static_cast<unsigned int>(time(nullptr))); // 初始化人类和动物 for (int i = 0; i < 10; ++i) { int x = rand() % 100; int y = rand() % 100; int age = rand() % 100; int hunger = rand() % 100; if (i < 5) { humans_.push_back(new Human(100, age, hunger)); map_.AddCreature(humans_.back(), x, y); } else { animals_.push_back(new Animal(50, age, hunger)); map_.AddCreature(animals_.back(), x, y); } } } void Run() { // 游戏循环 while (true) { // 更新人类状态 for (auto& human : humans_) { human->Eat(); human->Sleep(); human->Move(); if (human->GetHealth() <= 0) { human->Die(); map_.RemoveCreature(human, 0, 0); } } // 更新动物状态 for (auto& animal : animals_) { animal->Eat(); animal->Sleep(); animal->Move(); if (animal->GetHealth() <= 0) { animal->Die(); map_.RemoveCreature(animal, 0, 0); } } // 显示游戏状态 std::system("clear"); for (int y = 0; y < 100; ++y) { for (int x = 0; x < 100; ++x) { auto& creatures = map_.GetCreatures(x, y); if (creatures.empty()) { std::cout << "."; } else if (creatures.size() == 1) { if (dynamic_cast<Human*>(creatures[0])) { std::cout << "@"; } else { std::cout << "*"; } } else { std::cout << "#"; } } std::cout << std::endl; } // 暂停一段时间 std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } private: std::vector<Human*> humans_; std::vector<Animal*> animals_; Map map_; }; int main() { Game game; game.Init(); game.Run(); return 0; } ``` 这是一个简单的生存游戏,其中人类和动物可以在地图上移动、寻找食物、睡觉等,游戏会按照一定的时间间隔不断更新状态,并显示在屏幕上。如果生命值归零,则会死亡。
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值