C++自制游戏 - 无尽之剑2.0

【置顶】无尽之剑3.0出了!更新:附魔,优化战斗。有需要关注私信我   

#include <iostream>
#include <cstdio>
#include<string>
#include<stdlib.h>
#include<map>
#include<algorithm>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<cmath>
using namespace std;

map<string,int>m;
char op;int dam=1,he=20,xp=0,fy=0;string pickaxe="none";
void ss(string s,int a)
{
    int len=s.length();
    for(int i=0;i<=len-1;i++)
    {
        cout << s[i];
        Sleep(40);
    }
    if(a==1)
    {
        cout << endl;
    }
}
void fight(int hp,int f)
{
    int h=hp;
    while(h>0)
    {
        system("cls");
        cout << "当前敌方血量:" << h << endl;
        int r;
        srand(time(0));
        Sleep(1000);
        if(rand()%3==0)
        {
            cout << "你打出了暴击伤害" << floor(dam * 1.5) << endl;
            h-=floor(dam * 1.5);
        }
        else
        {
            cout << "你打出了" << dam << "伤害" << endl;
            h-=dam;
        }
        cout << "敌方对你造成了" << floor((f / 100.0) * (100 - fy * 4))<< "伤害" << endl;
        he-=floor((f / 100.0) * (100 - fy * 4));
        cout << "你剩余" << he << "血量" << endl;
        if(he<=0)
        {
            while(1)
            {
                cout << "You died!" << endl;
                Sleep(500);
                system("cls");
            }
        }
        system("pause");
    }
    cout << "你打败了怪物" << endl;
    int o1;
    o1=(hp*2)+f;
    cout << "你获得了" << o1 << "经验" << endl;
    xp+=o1;
    system("pause");
}
int daguai()
{
    int mm;int nn;
    gongji:
    cout << "请输入你想要打的怪物的血量(本次输入需要按下回车)" << endl;
    
    cin >> mm;
    if(mm<=0)
    {
        cout << "输入无效" << endl;
        goto gongji;
    }
    gj:
    cout << "请输入怪物的攻击" << endl;
    
    cin >> nn;
    if(nn<=0)
    {
        cout << "输入无效" << endl;
        goto gj;
    }
    fight(mm,nn);
}
void wakuang()
{
    system("cls");
    uuu:
    int what;
    cout << "你要挖几次矿?" << endl;
    int nnn;
    cin >> nnn;
    if(nnn>100)
    {
        cout << "一次挖矿格数不得超过100" << endl;
        goto uuu;
    }
    else
    {
        for(int i=1;i<=nnn;i++)
        {
            srand(rand()*time(0));
            Sleep(790);
            what = (rand()%100)+1;
            if(what <= 80)
            {
                cout << "获得:石头" << endl;
                m["stone"]++;
            }
            else if(what <= 90)
            {
                cout << "获得:金" << endl;
                m["gold"]++;
            }
            else if(what <=98)
            {
                cout << "获得:铁" << endl;
                m["iron"]++;
            }
            else
            {
                cout << "获得:钻石" << endl;
                m["diamond"]++;
            }
        }
    }
}











void hecheng()
{
    int num=1;string thing[999]={"0"};
    system("cls");
    cout << "可合成" << endl;
    if(m["wood"]>0)
    {
        cout << num << ".木板";
        thing[num]="muban";
        num++;
    }
    if(m["muban"]>0)
    {
        cout << num << ".木棍";
        thing[num]="mugun";
        num++;
    }
    if(m["mugun"]>0 and m["stone"]>1)
    {
        cout << num << ".石剑";
        thing[num]="shijian";
        num++;
    }
    if(m["mugun"]>0 and m["iron"]>1)
    {
        cout << num << ".铁剑";
        thing[num]="tiejian";
        num++;
    }
    if(m["mugun"]>0 and m["gold"]>1)
    {
        cout << num << ".金剑";
        thing[num]="jinjian";
        num++;
    }
    if(m["mugun"]>0 and m["diamond"]>1)
    {
        cout << num << ".钻石剑";
        thing[num]="zuanshijian";
        num++;
    }
    if(m["diamond"]>4)
    {
        cout << num << ".钻石头盔";
        thing[num]="zuanshitoukui";
        num++;
    }
    if(m["diamond"]>7)
    {
        cout << num << ".钻石胸甲";
        thing[num]="zuanshixiongjia";
        num++;
    }
    if(m["diamond"]>6)
    {
        cout << num << ".钻石护腿";
        thing[num]="zuanshihutui";
        num++;
    }
    if(m["diamond"]>3)
    {
        cout << num << ".钻石靴子";
        thing[num]="zuanshixuezi";
        num++;
    }
    if(m["iron"]>4)
    {
        cout << num << ".铁头盔";
        thing[num]="tietoukui";
        num++;
    }
    if(m["iron"]>7)
    {
        cout << num << ".铁胸甲";
        thing[num]="tiexiongjia";
        num++;
    }
    if(m["iron"]>6)
    {
        cout << num << ".铁护腿";
        thing[num]="tiehutui";
        num++;
    }
    if(m["iron"]>3)
    {
        cout << num << ".铁靴子";
        thing[num]="tiexuezi";
        num++;
    }
    int opp;
    cout << "请输入你想要合成东西的编号" << endl;
    cin >> opp;
    if(thing[opp]=="0")
    {
        cout << "输入无效" << endl;
    }
    else
    {
        if(thing[opp]=="shijian")
        {
            m["stone"]-=2;
            m["mugun"]--;
            m["shijian"]++;
            dam+=5;
        }
        if(thing[opp]=="tiejian")
        {
            m["iron"]-=2;
            m["mugun"]--;
            m["tiejian"]++;
            dam+=6;
        }
        if(thing[opp]=="jinjian")
        {
            m["gold"]-=2;
            m["mugun"]--;
            m["jinjian"]++;
            dam+=4;
        }
        if(thing[opp]=="zuanshijian")
        {
            m["diamond"]-=2;
            m["mugun"]--;
            m["zuanshijian"]++;
            dam+=7;
        }
        if(thing[opp]=="tietoukui")
        {
            m["iron"]-=5;
            
            m["tietoukui"]++;
            if(m["tietoukui"]==1)
            {
                fy+=3;
            }
            
        }
        if(thing[opp]=="tiexiongjia")
        {
            m["iron"]-=8;
            
            m["tiexiongjia"]++;
            if(m["tiexiongjia"]==1)
            {
                fy+=6;
            }
            
        }
        if(thing[opp]=="tiehutui")
        {
            m["iron"]-=7;
            
            m["tiehutui"]++;
            if(m["tiehutui"]==1)
            {
                fy+=4;
            }
            
        }
        
        if(thing[opp]=="tiexuezi")
        {
            m["iron"]-=4;
            
            m["tiexuezi"]++;
            if(m["tiexuezi"]==1)
            {
                fy+=2;
            }
            
        }
        if(thing[opp]=="zuanshitoukui")
        {
            m["diamond"]-=5;
            
            m["zuanshitoukui"]++;
            if(m["zuanshitoukui"]==1)
            {
                fy+=4;
            }
            
        }
        if(thing[opp]=="zuanshixiongjia")
        {
            m["diamond"]-=8;
            
            m["zuanshixiongjia"]++;
            if(m["zuanshixiongjia"]==1)
            {
                fy+=8;
            }
            
        }
        if(thing[opp]=="zuanshihutui")
        {
            m["diamond"]-=7;
            
            m["zuanshihutui"]++;
            if(m["zuanshihutui"]==1)
            {
                fy+=5;
            }
            
        }
        
        if(thing[opp]=="zuanshixuezi")
        {
            m["diamond"]-=4;
            
            m["zuanshixuezi"]++;
            if(m["zuanshixuezi"]==1)
            {
                fy+=3;
            }
            
        }
        if(thing[opp]=="muban")
        {
            m["wood"]--;
            
            m["muban"]+=4;
            
            
        }
        if(thing[opp]=="mugun")
        {
            m["muban"]--;
            
            m["mugun"]+=2;
            
            
        }
    }
    system("pause");
}

int lushu()
{
    cout << "你要撸几个木头?(一个木头需要3秒)" << endl;
    int oako;
    cin >> oako;
    for(int i=1;i<=oako;i++)
    {
        Sleep(3000);
        cout << "获得:原木" << endl;
        m["wood"]++;
    }
}




int main()
{
    ss("无尽之剑",1);
    ss("a.开始",1);
    op=getch();
    if(op=='a')
    {
        ss("你在你家发现了一把破木剑",1);
        ss("你要捡起破木剑吗?(破木剑,伤害3),按下y确定,n否定",1);
        op=getch();
        if(op=='y')
        {
            m["brokenwoodsword"]=1;
            ss("获得道具 破木剑【40/40】",1);
            dam+=3;
            ss("当前战力:4",1);
            system("pause");
        }
        system("cls");
        ss("你遇到了一个僵尸",0);
        fight(20,1);
        ss("现在你完成了新手教程,快开始游戏吧!",1);
        system("pause");
        m["wood"]+=5;
        while(he>0)
        {
            system("cls");
            ss("a.打怪",1);
            ss("b.挖矿",1);
            ss("c.合成",1);
            ss("d.撸树",1);
            op=getch();
            if(op=='a')
            {
                daguai();
            }
            if(op=='b')
            {
                wakuang();
            }
            if(op=='c')
            {
                hecheng();
            }
            if(op=='d')
            {
                lushu();
            }
        }
    }
    return 0;
}



  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值