小游戏(不喜勿喷)

· · 休闲·娱乐

#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
#include<cmath>
using namespace std;
int now = 10000;
int du(int m, bool brs){  //m为马内,brs是否是大
    srand(time(0));
    int tou = (rand() % (6)) + 1; // 就为了改这个耗了我半小时... 
    cout << "点数为" << tou << endl;
    if(tou > 3){
        if(brs){
            return m; 
        }
        else{
            return -m;
        }
    }
    else{
        if(brs){
            return -m;
        }
        else{
            return m;
        }
    }
}

int manei(){
    double duj;
    cout << "赌金多少(小数向上取值)?"<< endl;
    cin >> duj;
    duj = ceil(duj);
    if(duj > now){
        cout << "赌金比自己的本金多,本金为" << now << "元。" << endl;
        return manei();
    }
    else if(duj < 5000){
        cout << "赌金太少,至少为5000元。" << endl;
        return manei();
    }
    else{
        return duj;
    }
}

int dujin(){
    int m;
    string bs;
    bool brs;
    cout << "请问赌大赌小(大或小)?" << endl;
    cin >> bs;
    if (bs == "大"){
        brs = true;
    } 
    else if (bs == "小"){
        brs = false;
    } 
    else{
        cout << "输入不正确,请重新输入。" << endl;
        return dujin(); 
    }
    m = manei();
    return du(m, brs);
}

void yesorno(){
    int m;
    cout << "您有赌金" << now << "元,请问是否继续(是或否)?" << endl;
    string yrn;
    cin >> yrn;
    if(yrn == "是"){
        m = dujin();
        now += m;
        if (m > 0){
            cout << "您现有" << now << "元,赌前有" << now-m << "元,资金浮动+" << m << "元" << endl;
        }
        else{
            cout << "您现有" << now << "元,赌前有" << now-m << "元,资金浮动" << m << "元" << endl;
        }
        if(now < 5000){
            cout << "您的本金比起赌金少,您失败了!Num提醒您,道路千万条,Cplus第一条,再见!"; 
        }
        else{
            yesorno();
        } 
    } 
    else if (yrn != "否"){
        cout << "输入不正确,请重新输入。" << endl;
        yesorno();
    }
    else{
        cout << "欢迎您下次光临!";
    } 
}

int main(){
    cout << "游戏规则:开局获得10000元,每局赌大或小,押入赌金,系统自动掷骰,点数为1-3为小,4-6为大。" << endl;
    yesorno();
    return 0;
}

/*
本文件由Norsuman371(编写)和2011FYCCCTA(debug)共同制作,转载请表明,谢谢! 
*/

鸣谢@2011FYCCCTA debug!