| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2721 人关注过本帖
标题:一个自己变得游戏,名叫《流浪汉致富之路》,大家可以看一下
只看楼主 加入收藏
hzr
Rank: 2
等 级:论坛游民
威 望:3
帖 子:53
专家分:76
注 册:2017-8-24
结帖率:33.33%
收藏
 问题点数:0 回复次数:9 
一个自己变得游戏,名叫《流浪汉致富之路》,大家可以看一下
#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("cls");
        cout<<"第"<<t<<"天"<<"    ";
        cout<<ss<<endl;
        cout<<"钱:"<<q<<"元"<<endl;
        cout<<"1.去买东西"<<endl;
        cout<<"2.去卖东西"<<endl;
        cout<<"3.查看物品"<<endl;
        cout<<"4.存档并退出"<<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)
        {
            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;
}
搜索更多相关主题的帖子: include int rand cout cin 
2018-05-30 20:04
hzr
Rank: 2
等 级:论坛游民
威 望:3
帖 子:53
专家分:76
注 册:2017-8-24
收藏
得分:0 
如果有什么建议,大家可以提出来
2018-06-02 17:07
卖糖法师
Rank: 1
来 自:安徽安庆
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-6-20
收藏
得分:0 
你定义q的时候用了两个long
2018-06-20 11:04
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:0 
switch语句代替一长串的if
2018-06-23 22:39
何尕强
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-6-24
收藏
得分:0 
回复 楼主 hzr
玩到后面面包价格有负数存在了
图片附件: 游客没有浏览图片的权限,请 登录注册
,买了东西钱还变多了

[此贴子已经被作者于2018-6-24 10:11编辑过]



F_RL8$U54Y3S(T}%JFZHN4F.png (23.59 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
2018-06-24 10:08
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
收藏
得分:0 
首先, 贴出代码肯定是让别人能看的
但是
你这个代码
暂且不说你没有写注释, 因为有些代码不需要注释也可以看懂
就只说说你这个变量名
aa bb cc
怕不是对我们有什么意见
2018-06-24 16:05
Myloop
Rank: 2
来 自:湖北随州
等 级:论坛游民
威 望:2
帖 子:18
专家分:27
注 册:2017-10-21
收藏
得分:0 
不错,但是还有诸多不足需要修改,希望你能保持一颗平常心继续完善下去,做最好自己的就够了,提升自己的能力才是王道

Myloop
Speak is cheap,show me the code.
2018-06-26 23:17
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
收藏
得分:0 
很不错嘛
2018-07-17 10:11
拉拉面
Rank: 1
来 自:广州
等 级:新手上路
帖 子:26
专家分:5
注 册:2018-9-22
收藏
得分:0 
bug有点多啊,,那个书本的钱有时候变成负数了,结果越买越有钱希望改进

哈哈哈哈哈啦啦啦
2018-10-05 14:33
rohalloway
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:97
专家分:405
注 册:2018-9-28
收藏
得分:0 
楼主的命名风格起到了加密的作用  
2018-10-05 15:45
快速回复:一个自己变得游戏,名叫《流浪汉致富之路》,大家可以看一下
数据加载中...
 
   



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

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