C++生存游戏1.5

1.5版本

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
string name;
int mony=600,jb=5,r=0,wait1=400,wait2=500;
double xn=20,dx,zx,xx,sx=20,fy=1,gj=4,m=1212123,mm=321531;
string wq=" ",d="Accteped";
bool f=0,sl=1;
void print(string s){
    for(int i=0;i<s.size();++i){
        cout<<s[i];
        Sleep(100);
    }
}
void qp(){
    system("cls");
}
void sd(){
    while(1){
        qp();
        cout<<name<<":\n您现在有"<<mony<<"个金币"<<endl;
        cout<<"药水:\n1.小型药水(150)\n2.中型药水(300)\n3.大型药水(420)\n装备:\n4.木剑(500)\n5.铁剑(1000)\n6.钻石剑(1600)\n0.退出\n";
        int t;
        cin>>t;
        bool fe=1;
        switch(t){
            case 1:
                if(mony>=200){
                    mony-=200;
                    xx++;cout<<"购买成功!!";Sleep(1000);
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 2:
                if(mony>=400){
                    mony-=400;
                    zx++;cout<<"购买成功!!";Sleep(1000);
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 3:
                if(mony>=500){
                    mony-=500;
                    dx++;cout<<"购买成功!!";
                    Sleep(1000);
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 4:
                if(mony>=600){
                    mony-=600;
                    wq+="木剑 ";
                    sx+=10;
                    xn+=10;
                    gj+=15;cout<<"购买成功!!";Sleep(1000);
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 5:
                if(mony>=1100){
                    mony-=1100;
                    wq+="铁剑 ";
                    sx+=20;
                    xn+=20;
                    gj+=34;cout<<"购买成功!!";Sleep(1000);
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 6:
                if(mony>=1600){
                    mony-=1600;
                    wq+="钻石剑 ";
                    sx+=30;
                    xn+=30;
                    cout<<"购买成功!!";Sleep(1000);
                    gj+=60;
                }else{
                    cout<<"钱不够";Sleep(1000);
                }break;
            case 0:
                fe=0;
                break;
        }
        if(fe==0)break;
        qp();
    }
}
void zt(){
    qp();
    cout<<"血量:";printf("%.1lf    ",xn);cout<<"血量上限:";printf("%.1lf\n",sx);
    cout<<"钱数:"<<mony<<endl;
    cout<<"防御:";printf("%.1lf\n",fy);
    cout<<"装备:";
    if(wq==" ")cout<<"无"<<endl;
    else cout<<wq<<endl;
    cout<<"攻击力:"<<gj<<endl;
    cout<<"按任意键退出"<<endl;
    getch();
}
void bl(){
	qp();
	long long qs=time(0);
	cout<<"正在捕猎中...\n按任意键结束\n";
	while(1){
		if(kbhit()){
			break;
		}else{
			if(time(0)-qs>200){
				cout<<"你已经筋疲力尽了.."<<endl;
				getch();
				break;
			}
		}
	}
	long long zz=time(0)-qs,hd=0;
	if(gj<=200){
    	hd=zz/6;
    }else{
        hd=zz/5;
    }
	r+=hd;
	qp();
	cout<<"您捕到了"<<hd<<"块肉"<<endl;Sleep(1000);
	getch();
}
void zd(){
    int fw;
    int dxn,dgj,dfy=fy;
    if(sx<=50){
        dxn=rand()%50+1;dgj=rand()%25+1;
    }else if(sx>50&&sx<100||gj>50&&gj<=100){
        dxn=rand()%100+50;dgj=rand()%50+1;
    }
    else if(sx>100&&sx<=250||gj>100&&gj<=250){
        dxn=rand()%250+100;dgj=rand()%100+50;
    }else{
        dxn=rand()%1000+500,dgj=rand()%500+150;
    }
	sd:
    qp();
    cout<<"1.扫荡\n2.状态\n0.返回\n";
    char c=getch();
    if(c=='2'){
    	zt();
    	goto sd;
	}
	if(c=='0'){
		goto tc;
	}
    else if(c!='1'){
        goto sd;
    }
    for(int i=1;1;++i){
        getch();
        qp();
        cout<<"我方血量:"<<xn<<"     "<<"敌方血量:"<<dxn<<endl<<"我方攻击:"<<gj<<"     "<<"敌方攻击:"<<dgj<<endl<<"我方防御:"<<fy<<"     "<<"敌方防御:"<<dfy<<endl;
        cout<<"\n1.逃跑\n2.继续\n";
        char d=getch();
        if(d=='1')break;
        else qp();
        cout<<"    ***********   "<<endl;
        cout<<"    ***第"<<i<<"次***   "<<endl;
        cout<<"    ***********   "<<endl;
        string t="攻击",tdg="攻击",dfs="防御",fs="防御";
        int kx=gj,dkx=dgj,tdf=dfy,tf=fy;
        if(rand()%4==0){
            tdg="暴击";
            dkx+=rand()%5;
        }
        if(rand()%3==0){
            t="暴击";
            kx+=rand()%5;
        }
        if(rand()%4==0){
            tdf+=rand()%3+1;
            dfs="铁壁";
        }
        if(rand()%3==0){
            tf+=rand()%3+1;
            fs="铁壁";
        }
        cout<<"我方使用"<<t<<",敌方使用"<<dfs<<"抵消"<<tdf<<"点血"<<"      "<<"我方扣除敌方";
        dxn-=(kx-tdf);
        if(kx-tdf<=0){
            cout<<0<<endl;
        } 
        else{
            cout<<kx-tdf<<endl;
        }
        if(dxn<=0){
            int jjjjj=300+rand()%40,jjx=rand()%10;
            cout<<"敌方剩余血量为0\n"<<"我方胜利!!\n"<<"恭喜你获得"<<jjjjj<<"金币,增加2点血量上限\n"<<"你还剩"<<xn<<"滴血\n";
            mony+=jjjjj,sx+=2;
            if(xn+jjx>=sx)xn=sx; 
            else xn+=jjx;
            cout<<"按任意键退出\n";
            getch();
            break;
        }
        cout<<"敌方使用"<<tdg<<",我方使用"<<fs<<"抵消"<<tf<<"点血"<<"      "<<"敌方扣除我方";
        if(xn-(dkx-tf)<=0){
            cout<<0<<endl;xn=0;
        }
        else{
            cout<<dkx-tf<<endl;
            xn-=(dkx-tf);
        }
        if(xn<=0){
            sl=0;
            qp();
            cout<<"我方剩余血量为0\n"<<"敌方胜利!!\n"<<"敌方还剩"<<dxn<<"滴血\n";
            cout<<"GAME OVER!\n";
            getch();
            break;
        } 
    }
	tc:
	getch();
}
void hx(){
    while(1){
        cs:
        f=0;
        qp();
        cout<<name<<"\n您现在的血量为";
        printf("%.1lf",xn);
        cout<<','<<"血量上限为:";
        printf("%.1lf\n",sx);
        cout<<"您有:"<<endl;
        cout<<"1.小型药水:"<<xx<<endl; 
        cout<<"2.中型药水:"<<zx<<endl; 
        cout<<"3.大型药水:"<<dx<<endl; 
        cout<<"4.肉:"<<r<<endl; 
        cout<<"0.退出"<<endl; 
        int n;
        cin>>n;
        if(xn==sx&&n!=0){
            cout<<"您是满血,无法回血";
            Sleep(1000);
            continue;
        }
        switch(n){
            case 1:
                if(xx==0){
                    qp();
                    cout<<"数量不够!!!";
                    getch();break;
                }
                if(xx>0){
                    xx--;
                    if(xn+7>sx)xn=sx;
                    else xn+=7;break;
                }break;
            case 2:
                if(zx==0){
                    qp();
                    cout<<"数量不够!!!";
                    getch();break;
                }
                if(zx>0){
                    zx--;
                    if(xn+10>sx)xn=sx;
                    else xn+=10;break;
                }break;
            case 3:
                if(dx==0){
                    qp();
                    cout<<"数量不够!!!";
                    getch();break;
                }
                if(dx>0){
                    dx--;
                    if(xn+20>sx)xn=sx;
                    else xn+=20;break;
                }break;
            case 4:
            	if(r==0){
            		qp();
                    cout<<"数量不够!!!";
                    getch();break;
				}else{
					r--;
					if(xn+5>sx)xn=sx;
                    else xn+=5;break;
				}
            case 0:
                f=1;
                break;
            default:goto cs;
        }if(f)break;
    }
}
void bm(){
	long long qs=time(0);
	cout<<"正在挖矿中...\n按任意键结束\n";
	while(1){
		if(kbhit()){
			break;
		}else{
			if(time(0)-qs>250){
				cout<<"你已经筋疲力尽了.."<<endl;
				getch();
				break;
			}
		}
	}
	long long zz=time(0)-qs,hd=0;
	if(zz>=3){
		hd=zz/3*2;
		mony+=hd;
	}
	qp();
	cout<<"您挖到了"<<hd<<"元"<<endl;Sleep(1000);
	getch();
} 
void jjb(int &a){
    qp();
    cout<<"是否使用?(y or n)";
    char ch=getche();
    qp();
    if(ch=='y'){
        if(a>0){
            cout<<"救济成功!!";
            mony+=500; 
            a--;
        }else{
            cout<<"次数不足!";
        }   
    }else{
        cout<<"再见";
    }cout<<endl;
    getch();
}
int main(){
	system("title existence game 1.5");
	int ks,js,ks1,js1;
    SetFileAttributes("1.txt",FILE_ATTRIBUTE_HIDDEN);
    srand(time(0));
    int feee=1,d=115;mony=500;
    print("生存游戏1.5:\n作者:Accteped\n按任意键开始");
    getch();
    cout<<"\n提示:请勿输入Accteped为名字!";
    Sleep(1000); 
    cw:
    qp();
    v:
    printf("1.新建存档(如果以前有现在会被覆盖)\n2.加载存档(玩过就点)\n");
    char c=getch();
    qp();
    if(c=='1'){
        SetFileAttributes("1.txt",FILE_ATTRIBUTE_NORMAL); 
        system("del 1.txt");
        qp();
        printf("请输入您的名字:");
        cin>>name;mony=600;
        ofstream ofil;
        ofil.open("1.txt");
        ofil<<name<<' '<<mony<<' '<<xn<<' '<<sx<<' '<<gj<<' '<<fy<<' '<<jb<<' '<<xx<<' '<<zx<<' '<<dx<<' '<<r<<' '<<wq;
        ofil.close();
        SetFileAttributes("1.txt",FILE_ATTRIBUTE_HIDDEN);
    }
    else if(c=='2'){
        SetFileAttributes("1.txt",FILE_ATTRIBUTE_HIDDEN);
        ifstream ifile;
        ifile.open("1.txt");
        ifile>>name>>mony>>xn>>sx>>gj>>fy>>jb>>xx>>zx>>dx>>r;
        getline(ifile,wq);
        ifile.close();
    }else{
        goto v;
    }
    if(name=="Accteped"){
        qp();
        cout<<"你竟想冒犯作者!!";
        mony=0;
        getch();
    }
    if(name=="hxx"&&c!='2'){
        qp();
        cout<<"你是作者吗\n请输入密码:";int tm;cin>>tm;
        qp();
        if(tm==d){
            cout<<"欢迎你,作者!";
            qp();
            cout<<"请输入您要的属性值(血,钱,攻击):"<<endl;
            cin>>xn>>mony>>gj;
            sx=xn;
        }else{
            qp();
            cout<<"你竟敢冒犯作者!!";
            mony=0;
            getch();
        }
    }
    qp();
    print("欢迎你:");
    print(name);
    cout<<endl;
    getch();
    while(1){
        qp();
        cout<<name<<"请问你要干什么"<<endl;
        cout<<"1.战斗  2.商店  3.回血  4.状态  5.金币救助(还剩"<<jb<<"次)  6.挖矿  7.捕猎  8.保存"<<endl;
        cs:
        char c=getch();
        switch(c){
            case '1':
                zd();
                if(sl==0){
                    shu:
                    cout<<"1.重玩\n0.退出\n";
                    char d2=getch();
                    if(d2=='1')goto cw;
                    if(d2=='0'){
                        qp();
                        cout<<"欢迎下次再来!";
                        feee=0;
                        break;
                    }else goto shu;
                }
                break;
            case '2':sd();break;
            case '3':hx();break;
            case '4':zt();break;
            case '8':break;
            case '7':js=time(0);if(js-ks>=400){bl();ks=js;}else{qp();cout<<"你还是筋疲力尽!"<<endl<<"还剩"<<400-(js-ks)<<"秒\n";getch();qp();};break;
            case '6':qp();js1=time(0);if(js1-ks1>=260){bm();ks1=js1;}else{qp();cout<<"你还是筋疲力尽!"<<endl<<"还剩"<<260-js1+ks1<<"秒\n";;getch();qp();};break;
            case '5':jjb(jb);break;
            default:goto cs;
        }if(!feee)break;
        if(c=='8'){
			SetFileAttributes("1.txt",FILE_ATTRIBUTE_NORMAL); 
            ofstream ofil;
            ofil.open("1.txt");
            ofil<<name<<' '<<mony<<' '<<xn<<' '<<sx<<' '<<gj<<' '<<fy<<' '<<jb<<' '<<xx<<' '<<zx<<' '<<dx<<' '<<r<<' '<<wq;
            ofil.close();
            qp();
            cout<<"保存成功!!";
			SetFileAttributes("1.txt",FILE_ATTRIBUTE_HIDDEN);
            Sleep(1000);
        }
        if(sx>1000){
            qp();
            cout<<"YOU WIN!"<<endl<<"您的得分是:"<<(sx+gj+mony)*100<<endl;
            cout<<"欢迎下次再来!";
            Sleep(1000);
            exit(0);
        }
    }
}

原文为:点这

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#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; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值