《绝地求生》

新版本!非常刺激!有空投!
以下是代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <time.h>
#include <conio.h>
#include <cmath>

using namespace std;

int number_of_people;
int safe_round;
int number_of_handle;
int player_hp;
int target_hp;
bool kt;
int juli_kt;

void init();
void procedure();
void menu();
void show(char[]);
void end();
void target_active();
void target_init();
void target_meetPlayer();

int suiJi();

class Player
{
    public:
        int hp;
        string name;
        string wu_qi;
        int number_of_bullet;
        string wu_pin[20];
        int number_of_wu_pin;
        string bag;
        int max_number_of_wu_pin;
        int handle;
        int ju_li;

        void active()
        {
            move();
        }
        void init()
        {
            hp = 100;
            wu_qi = "拳头";
            number_of_wu_pin = 0;
            bag = "无";
            max_number_of_wu_pin = 5;
            ju_li = 7000; 
            player_hp = hp;
        }
    private:
        bool run_away;

        void attack()
        {
            int s = suiJi()%10+1;
            cout << name;
            if (wu_qi == "拳头")
            {
                show("出拳!\n\n");
                cout << " O__  \\O" << endl;
                cout << " <|    /\\" << endl;
                cout << " / \\  <\\" << endl;
                cout << endl;
                target_hp -= 5;
                target_meetPlayer();
                show("敌人的hp减少了5!\n\n");
            }
            else
            {
                if (number_of_bullet > 0)
                {
                    show("开火!\n\n");
                    number_of_bullet --;
                    if (s <= 6)
                    {
                        show("命中目标!\n\n");
                        cout << " O__ _@\\O" << endl;
                        cout << "  VV    /\\" << endl;
                        cout << " / \\   <\\" << endl;
                        cout << endl;
                        if (wu_qi == "M1911")
                        {
                            target_hp -= 10;
                            show("敌人的hp减少了10!\n\n");
                        }
                        else if (wu_qi == "MP5") 
                        {
                            target_hp -= 20;
                            show("敌人的hp减少了20!\n\n");
                        }
                        else if (wu_qi == "AK47")
                        {
                            target_hp -= 30;
                            show("敌人的hp减少了30!\n\n");
                        }
                        else if (wu_qi == "S12K")
                        {
                            target_hp -= 40;
                            show("敌人的hp减少了40!\n\n");
                        }
                        else if (wu_qi == "AWM")
                        {
                            target_hp -= 50;
                            show("敌人的hp减少了50!\n\n");
                        }
                        else if (wu_qi == "M82A1")
                        {
                            target_hp -= 80;
                            show("敌人的hp减少了80!\n\n");
                        }
                        target_meetPlayer();
                    }
                    else
                    {
                        show("没打中!QДQ\n\n");
                    }
                }
                else
                {
                    show("没子弹了!QДQ\n\n");
                }
            }
        }
        void move()
        {
            if (ju_li > 0) ju_li -= 200;
            show("距离绝对安全区还有");
            printf("%d",ju_li);
            show("米!\n\n");
            printf("输入1查看状态。\n\n");
            int a;
            cin >> a;
            if (a == 1)
            {
                look();
            }
            if (kt == true and juli_kt == 0)
            {
                show("你已找到空投。\n\n");
                int s = suiJi()%10;
                if (s <= 5)
                {
                    show("空投物资有:\n");
                    cout << "1.药 2.M82A1" << endl;
                    int ch;
                    cin >> ch;
                    if (ch == 1)
                    {
                        if (number_of_wu_pin < max_number_of_wu_pin)
                        {
                            wu_pin[number_of_wu_pin] = "药";
                            number_of_wu_pin++;
                        }
                    }
                    else if (ch == 2)
                    {
                        wu_qi = "M82A1";
                        number_of_bullet = 10;
                        show("你装备了M82A1。\n\n");
                    }
                }
                else
                {
                    show("可是空投物资被别人抢了。。。QДQ");
                }
                kt = false;
            }
            else
            {
                int s;
                s = suiJi()%50;
                if (s >= 1 and s <= 10)
                {
                    meetTarget();
                }
                else if (s >= 10 and s <= 50)
                {
                    getSomething();
                }
            }
        }
        void runAway()
        {
            int s = suiJi()%10+1;
            if (s <= 4)
            {
                run_away = true;
                show("逃跑成功!(^o^)\n\n");
            }
            else
            {
                run_away = false;
                show("逃跑失败!敌人追上来了!QДQ\n\n");
            }
        }
        void daYao()
        {
            if (hp < 100)
            {
                bool find = false;
                for (int i=0; i<number_of_wu_pin; i++)
                {
                    if (wu_pin[i] == "药")
                    {
                        find = true;
                        show("正在打药......\n\n");
                        hp += 30;
                        if (hp > 100)
                        {
                            hp = 100;
                        }
                        player_hp = hp;
                        show("你的hp增加了30。\n\n");
                        for (int j=i; j<number_of_wu_pin-1; j++)
                        {
                            wu_pin[j] = wu_pin[j+1];
                        }
                        number_of_wu_pin--;
                        break;
                    }
                }
                if (find == false)
                {
                    show("你没有药!\n\n");
                }
            }
            else
            {
                show("hp满,不用打药。\n\n");
            }
        }
        void getSomething()
        {
            int s = suiJi()%100+1;
            show("发现");
            char ch;
            if (s >= 1 and s <= 10)
            {
                show("三级包!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("背上了三级包。\n\n");
                    max_number_of_wu_pin = 20;
                    bag = "三级包";
                }
            }
            else if (s >= 11 and s <= 20)
            {
                show("二级包!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("背上了二级包。\n\n");
                    max_number_of_wu_pin = 15;
                    bag = "二级包";
                }
            }
            else if (s >= 21 and s <= 30)
            {
                show("一级包!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("背上了一级包。\n\n");
                    max_number_of_wu_pin = 10;
                    bag = "一级包";
                }
            }
            else if (s >= 31 and s <= 40)
            {
                show("AWM!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("装备了AWM。\n\n");
                    wu_qi = "AWM";
                    number_of_bullet = 5;
                }
            }
            else if (s >= 41 and s <= 50)
            {
                show("S12K!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("装备了S12K。\n\n");
                    wu_qi = "S12K";
                    number_of_bullet = 5;
                }
            }
            else if (s >= 51 and s <= 60)
            {
                show("AK47!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("装备了AK47。\n\n");
                    wu_qi = "AK47";
                    number_of_bullet = 30;
                }
            }
            else if (s >= 61 and s <= 70)
            {
                show("MP5!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("装备了MP5。\n\n");
                    wu_qi = "MP5";
                    number_of_bullet = 25;
                }
            }
            else if (s >= 71 and s <= 80)
            {
                show("M1911!\n\n");
                show("是否拾取?Y/N\n\n");
                cin >> ch;
                if (ch == 'Y')
                {
                    show("装备了M1911。\n\n");
                    wu_qi = "M1911";
                    number_of_bullet = 7;
                }
            }
            else if (s >= 81 and s <= 100)
            {
                show("药!\n\n");
                if (number_of_wu_pin < max_number_of_wu_pin)
                {
                    show("是否拾取?Y/N\n\n");
                    cin >> ch;
                    if (ch == 'Y')
                    {
                        wu_pin[number_of_wu_pin] = "药";
                        number_of_wu_pin++;
                        show("捡起了药。\n\n");
                    }
                }
                else
                {
                    show("可惜,背包满了。\n\n");
                    show("是否丢掉某样东西?Y/N\n\n");
                    cin >> ch;
                    if (ch == 'Y')
                    {
                        int cho;
                        show("请选择你要丢掉的东西:\n");
                        for (int i=0; i<number_of_wu_pin; i++)
                        {
                            cout << i+1 << '.' << wu_pin[i] << endl;
                        }
                        cin >> cho;
                        if (cho >= 1 and cho <= number_of_wu_pin)
                        {
                            for (int i=cho-1; i<number_of_wu_pin-1; i++)
                            {
                                wu_pin[i] = wu_pin[i+1];
                            }
                            number_of_wu_pin--;
                        }
                        else
                        {
                            while (not(cho >= 1 and cho <= number_of_wu_pin))
                            {
                                show("输入错误!\n\n");
                                show("重新输入:");
                                cin >> cho;
                            }
                            for (int i=cho-1; i<number_of_wu_pin-1; i++)
                            {
                                wu_pin[i] = wu_pin[i+1];
                            }
                            number_of_wu_pin--;
                        }
                    }
                }
            }
        }
        void look()
        {
            cout << name << endl;
            cout << "生命值:" << hp << endl;
            cout << "武器:" << wu_qi << ' ' << "子弹:" << number_of_bullet << endl;;
            cout << "背包:" << bag << endl;
            cout << "物品:" << endl;
            if (number_of_wu_pin > 0)
            {
                for (int i=0; i<number_of_wu_pin; i++)
                {
                    cout << wu_pin[i] << endl;
                }
            }
            else
            {
                cout << "无" << endl;
            }
            cout << endl;
            system("pause");
            cout << endl;
        }
        void meetTarget()
        {
            show("发现敌人!(o_o)!\n\n");
            target_init();
            while (target_hp > 0)
            {
                show("该怎么办?\n\n");
                show("1.攻击 2.打药 3.逃跑\n\n");
                cin >> handle;
                if (handle == 1)
                {
                    attack();
                    if (target_hp == 0)
                    {
                        cout << "  @@" << endl;
                        cout << "    @@" << endl;
                        cout << "     @" << endl;
                        cout << "   O---" << endl;
                        cout << "   /> \\\\" << endl;
                        show("你淘汰了一个玩家!\n\n");
                        number_of_people--;
                        break;
                    }
                }
                else if (handle == 2)
                {
                    daYao();
                }
                else if (handle == 3)
                {
                    runAway();
                    if (run_away == true)
                    {
                        break;
                    }
                }
                target_active();
                hp = player_hp;
            }
        }
};

class Enemy
{
    public:
        int hp;
        string wu_qi;

        void acitve()
        {
            attack();
        }
        void init()
        {
            hp = suiJi()%100+1;
            target_hp = hp;
            int s = suiJi()%5+1;
            if (s == 1)
            {
                wu_qi = "M1911";
            }
            else if (s == 2)
            {
                wu_qi = "MP5";
            }
            else if (s == 3)
            {
                wu_qi = "AK47"; 
            }
            else if (s == 4)
            {
                wu_qi = "S12K";
            }
            else if (s == 5)
            {
                wu_qi = "AWM";
            }
        }
    private:
        void attack()
        {
            show("敌人向你开火!\n\n");
            int s = suiJi()%10+1;
            if (s <= 6)
            {
                show("你被击中了!(x_x)\n\n");
                cout << "O/@" << endl;
                cout << " /\\" << endl;
                cout << "  /\\" << endl;
                if (wu_qi == "M1911")
                {
                    player_hp -= 10;
                    show("敌人使用M1911,你的hp减少了10!\n\n");
                }
                else if (wu_qi == "MP5") 
                {
                    player_hp -= 20;
                        show("敌人使用MP5,你的hp减少了20!\n\n");
                }
                else if (wu_qi == "AK47")
                {
                    player_hp -= 30;
                    show("敌人使用AK47,你的hp减少了30!\n\n");
                }
                else if (wu_qi == "S12K")
                {
                    player_hp -= 40;
                    show("敌人使用S12K,你的hp减少了40!\n\n");
                }
                else if (wu_qi == "AWM")
                {
                    player_hp -= 50;
                    show("敌人使用AWM,你的hp减少了50!\n\n");
                }
                if (player_hp <= 0)
                {
                    end();
                }
            }
            else
            {
                show("但是没有击中你。(^o^)\n\n");
            }
        }
};

Player player;
Enemy target;

int main()
{
    procedure();
    return 0;
}

void init()
{
    number_of_handle = 0;
    safe_round = 8000;
    kt = false;
    player.init();
}

void procedure()
{
    show("欢迎来到绝地求生!\n\n");
    show("请输入玩家人数(最多100人,最少10人):");
    cin >> number_of_people;
    if ((number_of_people < 10)or(number_of_people > 100))
    {
        show("\n输入错误,系统自动为您更正,玩家人数为100人。\n\n");
        number_of_people = 100;
    }
    show("\n请输入你的名字(不含空格):");
    cin >> player.name;
    show("\n正在匹配......\n\n");
    show("匹配成功!开始游戏!\n\n");
    init();
    system("pause");
    system("cls");
    menu();
}

void menu()
{
    show("你已落地。\n\n");
    system("pause");
    while (number_of_people > 1)
    {
        number_of_handle++;
        system("cls"); 
        show("你正在跑毒......\n\n");
        if (number_of_handle%5 == 0)
        {
            safe_round -= 1000;
            show("毒圈直径减小1000米!\n\n");
        }
        if (number_of_handle == 5)
        {
            kt = true;
            show("空投已投下!\n\n");
            juli_kt = 1000;
        }
        if (kt == true)
        {
            show("距离空投还有");
            cout << juli_kt;
            show("米!\n\n");
            if (juli_kt > 0)
            {
                juli_kt -= 200;
            }
        }
        if (number_of_people > 2)
        {
            int s = suiJi()%5+1;
            number_of_people -= s;
            if (number_of_people < 2)
            {
                number_of_people = 2;
            }
        }
        player.active();
        printf("还剩%d人。\n", number_of_people);
        if (number_of_people > 1) system("pause");
        cout << endl; 
    }
    show("大吉大利,今晚吃鸡!\n\n");
    system("pause");
}

void show(char text[])
{
    int len = strlen(text);
    for (int i=0; i<=len; i++)
    {
        cout << text[i];
        Sleep(80);
    }
}

int suiJi()
{
    srand((unsigned)time(0));
    return rand()%100+1;
}

void end()
{
    cout << player.name;
    show("阵亡!\n\n");
    show("再接再厉,下次吃鸡!\n\n");
    system("pause");
    exit(0);
}

void target_active()
{
    target.acitve();
}

void target_init()
{
    target.init();
}

void target_meetPlayer()
{
    target.hp = target_hp;
    if (target.hp < 0)
    {
        target.hp = 0;
        target_hp = 0;
    }
}
全部评论

相关推荐

10-09 00:50
已编辑
长江大学 算法工程师
不期而遇的夏天:1.同学你面试评价不错,概率很大,请耐心等待;2.你的排名比较靠前,不要担心,耐心等待;3.问题不大,正在审批,不要着急签其他公司,等等我们!4.预计9月中下旬,安心过节;5.下周会有结果,请耐心等待下;6.可能国庆节前后,一有结果我马上通知你;7.预计10月中旬,再坚持一下;8.正在走流程,就这两天了;9.同学,结果我也不知道,你如果查到了也告诉我一声;10.同学你出线不明朗,建议签其他公司保底!11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享
专心打鱼:互联网搬运工,贴子都要偷
点赞 评论 收藏
分享
评论
2
收藏
分享
正在热议
# 25届秋招总结 #
439711次浏览 4483人参与
# 春招别灰心,我们一人来一句鼓励 #
41352次浏览 523人参与
# 北方华创开奖 #
107221次浏览 598人参与
# 地方国企笔面经互助 #
7908次浏览 18人参与
# 虾皮求职进展汇总 #
113287次浏览 880人参与
# 实习,投递多份简历没人回复怎么办 #
2453574次浏览 34845人参与
# 阿里云管培生offer #
119598次浏览 2219人参与
# 实习必须要去大厂吗? #
55548次浏览 959人参与
# 同bg的你秋招战况如何? #
75024次浏览 547人参与
# 提前批简历挂麻了怎么办 #
149746次浏览 1975人参与
# 投递实习岗位前的准备 #
1195558次浏览 18545人参与
# 你投递的公司有几家约面了? #
33165次浏览 188人参与
# 双非本科求职如何逆袭 #
661735次浏览 7392人参与
# 机械人春招想让哪家公司来捞你? #
157584次浏览 2267人参与
# 如果公司给你放一天假,你会怎么度过? #
4708次浏览 53人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
11184次浏览 253人参与
# 发工资后,你做的第一件事是什么 #
12333次浏览 61人参与
# 工作中,努力重要还是选择重要? #
35493次浏览 384人参与
# 参加完秋招的机械人,还参加春招吗? #
20068次浏览 240人参与
# 实习想申请秋招offer,能不能argue薪资 #
39197次浏览 314人参与
# 我的上岸简历长这样 #
451849次浏览 8086人参与
# 非技术岗是怎么找实习的 #
155829次浏览 2120人参与
牛客网
牛客企业服务