C++ Project for beginners-Game Programming in C++ by making a text game

C++ Project for beginners-Game Programming in C++ by making a text game

#include<iostream>
#include<stdlib.h>
using namespace std;
#include<time.h>
void ShowIntroScreen(void);

void ShowInformation(unsigned long Money);
short GetBet(void);
short DoDiceThrow(void);
unsigned short DoMoneyCalc(short Dice,short Bet,short BetMoney);
unsigned long GetAmount(void);

main(void)
{

    unsigned long MoneyEarned;
short DiceValue;
short Bet;
short BetMoney;
unsigned long Money;
//show intro and setup game
ShowIntroScreen();
Money=1000;
//play while player has money
//keep 100 dollars for the cab home



    do
    {
        ShowInformation(Money);

        Bet=GetBet();
        BetMoney=GetAmount();
        DiceValue=DoDiceThrow();
        MoneyEarned=DoMoneyCalc(DiceValue,Bet,BetMoney);
        Money -=BetMoney;
        if(MoneyEarned==0)
        {

            cout<<"you lost,nuber was"<<DiceValue;
            cout<<endl<<endl;
        }
        else
        {

            cout<<"you won"<<MoneyEarned-BetMoney;
            cout<<"dollars..number was"<<DiceValue;
            cout<<endl<<endl;
            Money=Money+MoneyEarned;
        }
    }
    while(Money>100);
    cout<<"game over..keep $"<<Money<<"for ride home";
    cout<<endl;
    return 0;
}
void ShowIntroScreen(void)
{

    cout<<"Welcome to craps";
    cout<<endl<<endl;
    cout<<"here are the rules";
    cout<<endl<<endl;

    cout<<"you have 1000 dollars to start gambling";
    cout<<endl<<endl;

    cout<<"you can do three diffrenet betes..you can bet on";
    cout<<"2 and 12 which will give win ratio of 5 to 1 if you win.";
    cout<<"you can bet on numbers 4:";
    cout<<"and 10";
    cout<<"it will give you a win ratio of 2.5 to 1";
    cout<<endl;
    cout<<"last bet is on  6";
    cout<<"and 8 which will give you a win ration of 1.5 to 1";
    cout<<endl;

}
void ShowInformation(unsigned long Money)
{

    cout<<"you have"<<Money<<"dollars";
    cout<<endl;
}
short GetBet(void)
{

    unsigned short BetType;
    cout<<"enter type of bet (1='6/8' 2='4/10'3='2/12'):";
    cin>>BetType;

    if((BetType==1)||(BetType==2)||(BetType==3))
       {

           return BetType;
       }
       else
        {

            return 1;

        }
}

short DoDiceThrow(void)
{

    short DiceValue;
    srand(time(NULL));
    DiceValue=(rand()%11)+2;

    if((DiceValue==4||DiceValue==10))
    {

        srand(time(NULL));
        DiceValue=(rand()%12)+1;
    }
    if((DiceValue==2)||(DiceValue==12))
    {

        srand (time(NULL));
        DiceValue=(rand()%12)+1;

        return DiceValue;
    }
}
unsigned short DoMoneyCalc(short Dice,short Bet,short BetMoney)
{

    unsigned long MoneyEarned=0;
    //see which type of bet player made
    switch(Bet)
    {

    case 1:
        if((Dice==6)||(Dice==8))
        {

            MoneyEarned=BetMoney*1.5;

        }
        break;
        break;
    case 2:
        if((Dice==10)||(Dice==4))
        {


            MoneyEarned=BetMoney*2.5;

        }
        break;break;
        /*2/12 pay amount of 5:1*/
    case 3:
        if((Dice==2)||(Dice==12))
        {
            MoneyEarned=BetMoney*5;
        }
        break;
    default:
        MoneyEarned=0;
        break;

        }
        return MoneyEarned;

}


unsigned long GetAmount(void)
    {

        unsigned short BetAmount;
        cout<<"enter the amount to bet(10-100";
        cin>>BetAmount;
        if(BetAmount<10)
        {

            BetAmount=10;
        }
        if(BetAmount>100)
        {

            BetAmount=100;
        }
        return BetAmount;
    }


 

Leave a Comment

Your email address will not be published. Required fields are marked *