| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 866 人关注过本帖
标题:哪位朋友那有个c++编的小游戏源代码 谢谢了
只看楼主 加入收藏
hzr
Rank: 2
等 级:论坛游民
威 望:3
帖 子:53
专家分:76
注 册:2017-8-24
收藏
得分:0 
#include<fstream>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
int a1,b1,c1,d1,e1,f1,g1,h1,i1;
int a2,b2,c2,d2,e2,f2,g2,h2,i2;
int aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,qq,tt;
int jjj=0,jjjj=0;
char s[1001];
char ss[1001];
long long q=1000;
int main()
{   
    int t=1;
    int a=15,b=15,c=100,d=100,e=40,f=35,g=6000,h=100000,i=1000000;
    int x,y,z,n,m;
    srand((unsigned)time(NULL));
    fstream fip("temp.txt",ios::in);
    fip>>ss>>jjjj;
    fip>>tt;
    fip>>qq;
    fip>>aa>>bb>>cc>>dd>>ee>>ff>>gg>>hh>>ii;
    fip>>a2>>b2>>c2>>d2>>e2>>f2>>g2>>h2>>i2;
    fip.close();
    t=tt;
    jjj=jjjj;
    if(jjj==0) q=1000;
    else
    {
    q=qq/101;
    a=aa;
    b=bb;
    c=cc;
    d=dd;
    e=ee;
    f=ff;
    g=gg;
    h=hh;
    i=ii;   
    }
    a1=a2;
    b1=b2;
    c1=c2;
    d1=d2;
    e1=e2;
    f1=f2;
    g1=g2;
    h1=h2;
    i1=i2;
    if(jjj==0)
    {
    cout<<"输入你的名字:";
    jjj=1;
    cin>>ss;
    cout<<"你是一名流浪汉。你还有1000元。去交易物品赚钱吧!"<<endl;
    for(int i=0;i<500000000;i++)
    i=i;
    }
    for(;;t++)
    {
        system("color 3E");
        system("cls");
        cout<<"第"<<t<<"天"<<"    ";
        cout<<ss<<endl;
        cout<<"钱:"<<q<<"元"<<endl;
        cout<<"1.去买东西"<<endl;
        cout<<"2.去卖东西"<<endl;
        cout<<"3.查看物品"<<endl;
        cout<<"4.猜数游戏"<<endl;
        cout<<"5.存档并退出"<<endl;
        cin>>x;
        //////////////////////////////
        if(x==1)
        {
            system("cls");
            cout<<"价格表:"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"1.书本 "<<"|"<<"单价:"<<a<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"2.钢笔 "<<"|"<<"单价:"<<b<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"3.衣服 "<<"|"<<"单价:"<<c<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"4.鞋子 "<<"|"<<"单价:"<<d<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"5.面包 "<<"|"<<"单价:"<<e<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"6.啤酒 "<<"|"<<"单价:"<<f<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"7.电脑 "<<"|"<<"单价:"<<g<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"8.汽车 "<<"|"<<"单价:"<<h<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"9.房子 "<<"|"<<"单价:"<<i<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"你要买什么:";
            cin>>y;
            cout<<"买的个数:";
            cin>>z;
            if(y==1)
            {
                q-=a*z;
                a1+=z;
            }
            if(y==2)
            {
                q-=b*z;
                b1+=z;
            }
            if(y==3)
            {
                q-=c*z;
                c1+=z;
            }
            if(y==4)
            {
                q-=d*z;
                d1+=z;
            }
            if(y==5)
            {
                q-=e*z;
                e1+=z;
            }
            if(y==6)
            {
                q-=f*z;
                f1+=z;
            }
            if(y==7)
            {
                q-=g*z;
                g1+=z;
            }
            if(y==8)
            {
                q-=h*z;
                h1+=z;
            }
            if(y==9)
            {
                q-=i*z;
                i1+=z;
            }
        }
        /////////////////////////////////
        if(x==2)
        {
            system("cls");
            cout<<"价格表:"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"1.书本 "<<"|"<<"单价:"<<a<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"2.钢笔 "<<"|"<<"单价:"<<b<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"3.衣服 "<<"|"<<"单价:"<<c<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"4.鞋子 "<<"|"<<"单价:"<<d<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"5.面包 "<<"|"<<"单价:"<<e<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"6.啤酒 "<<"|"<<"单价:"<<f<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"7.电脑 "<<"|"<<"单价:"<<g<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"8.汽车 "<<"|"<<"单价:"<<h<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"9.房子 "<<"|"<<"单价:"<<i<<"元"<<endl;
            cout<<"-------"<<"|"<<"---------------"<<endl;
            cout<<"你要卖什么:";
            cin>>y;
            cout<<"卖的个数:";
            cin>>z;
            if( y==1 && z<=a1 )
            {   
                q+=a*z;
                a1-=z;
            }
            if( y==2 && z<=b1 )
            {   
                q+=b*z;
                b1-=z;
            }
            if( y==3 && z<=c1 )
            {
                q+=c*z;
                c1-=z;
            }
            if( y==4 && z<=d1 )
            {
                q+=d*z;
                d1-=z;  
            }
            if( y==5 && z<=e1 )
            {
                q+=e*z;
                e1-=z;
            }
            if( y==6 && z<=f1 )
            {
                q+=f*z;
                f1-=z;
            }
            if( y==7 && z<=g1 )
            {
                q+=g*z;
                g1-=z;
            }
            if( y==8 && z<=h1 )
            {
                q+=h*z;
                h1-=z;
                }
            if( y==9 && z<=i1 )
            {
                q+=i*z;  
                i1-=z;
            }
        }
        ///////////////////////////////////
        if(x==3)
        {
            system("cls");
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"书本 "<<"|"<<"你有:"<<a1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"钢笔 "<<"|"<<"你有:"<<b1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"衣服 "<<"|"<<"你有:"<<c1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"鞋子 "<<"|"<<"你有:"<<d1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"面包 "<<"|"<<"你有:"<<e1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"啤酒 "<<"|"<<"你有:"<<f1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"电脑 "<<"|"<<"你有:"<<g1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"汽车 "<<"|"<<"你有:"<<h1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"房子 "<<"|"<<"你有:"<<i1<<"个"<<endl;
            cout<<"-----"<<"|"<<"--------------"<<endl;
            cout<<"1.退出";
            cin>>y;
            t--;
            continue;
        }
        ///////////////////////////////
        if(x==4)
        {
            cout<<"1.easy"<<endl;
            cout<<"2.hard"<<endl;
            cout<<"3.very hard"<<endl;
            cout<<"4.impossible"<<endl;
            cin>>y;
            int ygs;
            int l;
            int q1;
            if(y==1)
            {
                ygs=rand()%100;   
                l=10;
                q1=50;
            }
            if(y==2)
            {
                ygs=rand()%1000;
                l=20;
                q1=100;
            }
            if(y==3)
            {
                ygs=rand()%5000;
                l=30;
                q1=200;
            }
            if(y==4)
            {
                ygs=rand()%10000;
                l=50;
                q1=400;
            }
            system("cls");
            for(int i=0;;i++)
            {
                cin>>z;
                if(z==ygs&&i<l)
                {
                    cout<<"猜对了!"<<"获得了"<<q1<<"元钱!"<<endl;
                    q+=q1;
                    for(int i=0;i<300000000;i++)
                    {
                        i=i;
                    }
                    break;
                }
                else if(i>l)
                {
                    cout<<"次数用完了!"<<endl;
                    for(int i=0;i<500000000;i++)
                    {
                        i=i;   
                    }
                    break;
                }
                else
                {
                    if(z>ygs) cout<<"猜大了!"<<endl;
                    if(z<ygs) cout<<"猜小了!"<<endl;
                    cout<<"还剩"<<l-i<<"机会!"<<endl;
                }
            }
        }
        ///////////////////////////////
        if(x==5)
        {
            fstream fop("temp.txt",ios::out);
            fop<<ss<<endl<<jjj<<endl;
            fop<<t<<endl;
            fop<<q*101<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<" "<<h<<" "<<i<<" "<<endl;
            fop<<a1<<" "<<b1<<" "<<c1<<" "<<d1<<" "<<e1<<" "<<f1<<" "<<g1<<" "<<h1<<" "<<i1<<" "<<endl;
            fop.close();
            cout<<"存档成功!"<<endl;
            cout<<"如果要删除存档请把桌面上或者文件夹中的temp删除!"<<endl;
            t--;
            break;
        }
        ///////////////////////////////
        n=rand()%6;
        m=rand()%2;
        if(m==0) a+=n;
        else a-=n;
        n=rand()%6;
        m=rand()%2;
        if(m==0) b+=n;
        else b-=n;
        n=rand()%11;
        m=rand()%2;
        if(m==0) c+=n;
        else c-=n;
        n=rand()%11;
        m=rand()%2;
        if(m==0) d+=n;
        else d-=n;
        n=rand()%11;
        m=rand()%2;
        if(m==0) e+=n;
        else e-=n;
        n=rand()%11;
        m=rand()%2;
        if(m==0) f+=n;
        else f-=n;
        n=rand()%501;
        m=rand()%2;
        if(m==0) g+=n;
        else g-=n;
        n=rand()%1001;
        m=rand()%2;
        if(m==0) h+=n;
        else h-=n;
        n=rand()%10001;
        m=rand()%2;
        if(m==0) i+=n;
        else i-=n;
        ////////////////////
        n=rand()%6;
        q-=n;
        cout<<"今天吃饭花了"<<n<<"元。"<<endl;
        for(int i=0;i<200000000;i++)
        {
            i=i;
        }
        if(q<=0)
        {
            cout<<"你破产,饿死了!";
            break;
        }
    }
    return 0;
}
一个自己编得小游戏
2018-06-06 19:58
快速回复:哪位朋友那有个c++编的小游戏源代码 谢谢了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021818 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved