Forum of the Tyrant Clan, PhoenixLords.


    A Little Programming

    Nighttiger
    Nighttiger
    Admin
    Admin

    Posts : 189
    Join date : 2011-10-22
    Location : North Carolina, USA

    A Little Programming Empty A Little Programming

    Post by Nighttiger on Mon Jan 02, 2012 7:59 pm

    So I made this a few days ago... as a little fun. I've wanted to mess around with dice game for a bit anyway.

    Spoiler:
    // Dice Game Upgraded.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <string>
    #include <cstdlib>
    #include <ctime> //used to identify time as current time. Can be used in seeding a RNG.
    #include <iostream>
    #include <stdlib.h>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
    int gameMode;
    char playAgain,shopAccess;
    int greatLess, newTotal, playerCoins, bet;

    cout<<"Select Game Mode:"<<endl;
    cout<<"1. Standard"<<endl<<"2. Risky"<<endl<<"3. Blind"<<endl<<"4. Easy"<<endl<<endl;
    cin>>gameMode;

    //initializes variables
    shopAccess='n';
    newTotal=0;
    playerCoins=20;
    playAgain='y';


    if(gameMode==1)
    {
    cout<<endl<<"DICE GAME STANDARD!"<<endl<<"Nothing is special about this mode. Just basic dice!"<<endl<<endl<<"Ready to play?"<<endl;
    system("pause");
    system("cls");


    while (playAgain== 'y')
    {
    if (playerCoins==0)
    {
    cout<<"You're out of money! GAME OVER!"<<endl<<endl;
    system ("pause");
    system ("cls");
    break;
    }
    srand(static_cast<unsigned int>(time(0)));
    int myNumber = rand();
    int myDie = (myNumber %6)+1;
    cout<<"I rolled a "<<myDie<<endl;
    cout<<"Will your number roll be more, less, or equal to mine?"<<endl<<"1 for more, 2 for less. If it's equal, it's a tie"<<endl;
    cin>>greatLess;
    cout<<endl<<"You have: "<<playerCoins<<" coins"<<endl<<"How many coins would you like to bet?"<<endl;
    cin>>bet;
    if (bet > playerCoins)
    {
    cout<<"You tried to bet more that you have. You will bet your maximum number of coins."<<endl;
    bet=playerCoins;
    }
    cout<<endl;
    srand(static_cast<unsigned int>(time(0)));
    int yourNumber = rand();
    int yourDie = (yourNumber %6)+1;
    cout<<"Ready to compare?"<<endl<<endl<<endl;
    system("pause");
    system("cls");
    cout<<"I rolled a: "<<myDie<<endl;
    cout<<"You rolled a: "<<yourDie<<endl<<endl<<endl;
    if (yourDie > myDie && greatLess==1)
    {
    cout<<yourDie<<">"<<myDie<<endl<<"You win!"<<endl;
    newTotal = playerCoins + bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie && greatLess==2)
    {
    cout<<yourDie<<"<"<<myDie<<endl<<"You win!"<<endl;
    newTotal = playerCoins + bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie > myDie &&greatLess==2)
    {
    cout<<yourDie <<"<"<< myDie<<" is not true"<<endl<<"You lose."<<endl;
    newTotal = playerCoins - bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie &&greatLess==1)
    {
    cout<<yourDie <<">"<< myDie<<" is not true."<<endl<<"You lose."<<endl;
    newTotal = playerCoins- bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie == myDie)
    {
    cout<<"They're equal. Tie! No coins for either side."<<endl;
    cout<<"Your new coin total is: "<<playerCoins<<endl;
    playerCoins=newTotal;
    }
    system ("pause");
    system("cls");
    playerCoins=newTotal;
    newTotal=playerCoins;
    cout<<"Your coins total is: "<<playerCoins<<endl<<endl;
    cout<<"Would you like to access shop? (y/n)"<<endl;
    cin>>shopAccess;
    if (shopAccess=='y')
    {
    system ("cls");
    cout<<"Welcome to the shop! What would you like to buy?"<<endl<<"Type the number of the item you wish to buy."<<endl<<endl<<"The shop is empty!"<<endl;
    system ("pause");
    }
    shopAccess='n';
    system ("cls");
    cout<<"Would you like to play again? (y/n)"<<endl<<"Play again? ";
    cin>>playAgain;
    system("CLS");


    }

    }

    else if (gameMode==2)
    {
    cout<<endl<<"DICE GAME RISKY!"<<endl<<"In this mode, you always bet all your coins! If you run out, you get 10 more."<<endl<<endl<<"Ready to play?"<<endl;

    system("pause");
    system("cls");

    while (playAgain== 'y')
    {
    if(playerCoins==0)
    {
    cout<<"You're out of money! Risky Mode is enabled, so +10 coins."<<endl;
    newTotal=playerCoins+10;
    playerCoins=newTotal;
    system ("pause");
    system ("cls");
    }
    srand(static_cast<unsigned int>(time(0)));
    int myNumber = rand();
    int myDie = (myNumber %6)+1;
    cout<<"I rolled a "<<myDie<<endl;
    cout<<"Will your number roll be more, less, or equal to mine?"<<endl<<"1 for more, 2 for less. If it's equal, it's a tie"<<endl;
    cin>>greatLess;
    cout<<endl<<"You have: "<<playerCoins<<" coins"<<endl;
    cout<<"Risky Mode enabled! You will bet all your coins."<<endl;
    bet=playerCoins;

    cout<<endl;
    srand(static_cast<unsigned int>(time(0)));
    int yourNumber = rand();
    int yourDie = (yourNumber %6)+1;
    cout<<"Ready to compare?"<<endl<<endl<<endl;
    system("pause");
    system("cls");
    cout<<"I rolled a: "<<myDie<<endl;
    cout<<"You rolled a: "<<yourDie<<endl<<endl<<endl;
    if (yourDie > myDie &&greatLess==2)
    {
    cout<<yourDie <<"<"<< myDie<<" is not true"<<endl<<"You lose."<<endl;
    newTotal = playerCoins - bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie &&greatLess==1)
    {
    cout<<yourDie <<">"<< myDie<<" is not true."<<endl<<"You lose."<<endl;
    newTotal = playerCoins- bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie == myDie)
    {
    cout<<"They're equal. Tie! No coins for either side."<<endl;
    cout<<"Your new coin total is: "<<playerCoins<<endl;
    playerCoins=newTotal;
    }
    else if (yourDie > myDie && greatLess==1)
    {
    cout<<yourDie<<">"<<myDie<<endl<<"You win!"<<endl;
    newTotal = 2*(playerCoins + bet);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie && greatLess==2)
    {
    cout<<yourDie<<"<"<<myDie<<endl<<"You win!"<<endl;
    newTotal = 2*(playerCoins + bet);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    system ("pause");
    system("cls");
    playerCoins=newTotal;
    newTotal=playerCoins;
    cout<<"Your coins total is: "<<playerCoins<<endl<<endl;
    cout<<"Would you like to access shop? (y/n)"<<endl;
    cin>>shopAccess;
    if (shopAccess=='y')
    {
    system ("cls");
    cout<<"Welcome to the shop! What would you like to buy?"<<endl<<"Type the number of the item you wish to buy."<<endl<<endl;
    system ("pause");
    }
    shopAccess='n';
    system ("cls");
    cout<<"Would you like to play again? (y/n)"<<endl<<"Play again? ";
    cin>>playAgain;
    system("CLS");

    }

    }
    else if(gameMode==3)
    {
    cout<<endl<<"DICE GAME BLIND!"<<endl<<"In this mode, you can't see what number the computer rolled."<<endl<<endl<<"Ready to play?"<<endl;
    system("pause");
    system("cls");


    while (playAgain== 'y')
    {
    if (playerCoins==0)
    {
    cout<<"You're out of money! GAME OVER!"<<endl<<endl;
    system ("pause");
    system ("cls");
    break;
    }
    srand(static_cast<unsigned int>(time(0)));
    int myNumber = rand();
    int myDie = (myNumber %6)+1;
    cout<<"I rolled a (BLINDED)"<<endl;
    cout<<"Will your number roll be more, less, or equal to mine?"<<endl<<"1 for more, 2 for less. If it's equal, it's a tie"<<endl;
    cin>>greatLess;
    cout<<endl<<"You have: "<<playerCoins<<" coins"<<endl<<"How many coins would you like to bet?"<<endl;
    cin>>bet;
    if (bet > playerCoins)
    {
    cout<<"You tried to bet more that you have. You will bet your maximum number of coins."<<endl;
    bet=playerCoins;
    }
    cout<<endl;
    srand(static_cast<unsigned int>(time(0)));
    int yourNumber = rand();
    int yourDie = (yourNumber %6)+1;
    cout<<"Ready to compare?"<<endl<<endl<<endl;
    system("pause");
    system("cls");
    cout<<"I rolled a: "<<myDie<<endl;
    cout<<"You rolled a: "<<yourDie<<endl<<endl<<endl;
    if (yourDie > myDie && greatLess==1)
    {
    cout<<yourDie<<">"<<myDie<<endl<<"You win!"<<endl;
    newTotal = playerCoins + bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie && greatLess==2)
    {
    cout<<yourDie<<"<"<<myDie<<endl<<"You win!"<<endl;
    newTotal = playerCoins + bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie > myDie &&greatLess==2)
    {
    cout<<yourDie <<"<"<< myDie<<" is not true"<<endl<<"You lose."<<endl;
    newTotal = playerCoins - bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie &&greatLess==1)
    {
    cout<<yourDie <<">"<< myDie<<" is not true."<<endl<<"You lose."<<endl;
    newTotal = playerCoins- bet;
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie == myDie)
    {
    cout<<"They're equal. Tie! No coins for either side."<<endl;
    cout<<"Your new coin total is: "<<playerCoins<<endl;
    playerCoins=newTotal;
    }
    system ("pause");
    system("cls");
    playerCoins=newTotal;
    newTotal=playerCoins;
    cout<<"Your coins total is: "<<playerCoins<<endl<<endl;
    cout<<"Would you like to access shop? (y/n)"<<endl;
    cin>>shopAccess;
    if (shopAccess=='y')
    {
    system ("cls");
    cout<<"Welcome to the shop! What would you like to buy?"<<endl<<"Type the number of the item you wish to buy."<<endl<<endl<<"The shop is empty!"<<endl;
    system ("pause");
    }
    shopAccess='n';
    system ("cls");
    cout<<"Would you like to play again? (y/n)"<<endl<<"Play again? ";
    cin>>playAgain;
    system("CLS");


    }
    }
    if(gameMode==4)
    {
    cout<<endl<<"DICE GAME Easy!"<<endl<<"In this mode, you win many more coins than your bet, and lose much less!"<<endl<<endl<<"Ready to play?"<<endl;
    system("pause");
    system("cls");


    while (playAgain== 'y')
    {
    if (playerCoins==0)
    {
    cout<<"You're out of money! GAME OVER!"<<endl<<endl;
    system ("pause");
    system ("cls");
    break;
    }
    srand(static_cast<unsigned int>(time(0)));
    int myNumber = rand();
    int myDie = (myNumber %6)+1;
    cout<<"I rolled a "<<myDie<<endl;
    cout<<"Will your number roll be more, less, or equal to mine?"<<endl<<"1 for more, 2 for less. If it's equal, it's a tie"<<endl;
    cin>>greatLess;
    cout<<endl<<"You have: "<<playerCoins<<" coins"<<endl<<"How many coins would you like to bet?"<<endl;
    cin>>bet;
    if (bet > playerCoins)
    {
    cout<<"You tried to bet more that you have. You will bet your maximum number of coins."<<endl;
    bet=playerCoins;
    }
    cout<<endl;
    srand(static_cast<unsigned int>(time(0)));
    int yourNumber = rand();
    int yourDie = (yourNumber %6)+1;
    cout<<"Ready to compare?"<<endl<<endl<<endl;
    system("pause");
    system("cls");
    cout<<"I rolled a: "<<myDie<<endl;
    cout<<"You rolled a: "<<yourDie<<endl<<endl<<endl;
    if (yourDie > myDie && greatLess==1)
    {
    cout<<yourDie<<">"<<myDie<<endl<<"You win!"<<endl;
    newTotal = 4*(playerCoins + bet);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie && greatLess==2)
    {
    cout<<yourDie<<"<"<<myDie<<endl<<"You win!"<<endl;
    newTotal = 4*(playerCoins + bet);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie > myDie &&greatLess==2)
    {
    cout<<yourDie <<"<"<< myDie<<" is not true"<<endl<<"You lose."<<endl;
    newTotal = playerCoins - (bet/2);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie < myDie &&greatLess==1)
    {
    cout<<yourDie <<">"<< myDie<<" is not true."<<endl<<"You lose."<<endl;
    newTotal = playerCoins- (bet/2);
    cout<<"Your new coin total is: "<<newTotal<<endl;
    }
    else if (yourDie == myDie)
    {
    cout<<"They're equal. Tie! No coins for either side."<<endl;
    cout<<"Your new coin total is: "<<playerCoins<<endl;
    playerCoins=newTotal;
    }
    system ("pause");
    system("cls");
    playerCoins=newTotal;
    newTotal=playerCoins;
    cout<<"Your coins total is: "<<playerCoins<<endl<<endl;
    cout<<"Would you like to access shop? (y/n)"<<endl;
    cin>>shopAccess;
    if (shopAccess=='y')
    {
    system ("cls");
    cout<<"Welcome to the shop! What would you like to buy?"<<endl<<"Type the number of the item you wish to buy."<<endl<<endl<<"The shop is empty!"<<endl;
    system ("pause");
    }
    shopAccess='n';
    system ("cls");
    cout<<"Would you like to play again? (y/n)"<<endl<<"Play again? ";
    cin>>playAgain;
    system("CLS");


    }

    }

    cout<<"Thanks for playing!"<<endl;
    cout<<"Your grand coin total was: "<<playerCoins<<endl;
    return 0;

    }

    NOTE: A lot of that code is the 3 extra modes. I could have made it a lot more efficient and shorter, but I was lazy and just copy-pasted the original code with slight changes...


    May as well post it, =P
    You can try it if you want, but you need to copy paste the code into a compiler, language is C++.

    So basically what it does in picture form: (This is from running it)
    A Little Programming DGU1
    Asks for what mode you want to play. In all of the pictures I'm doing standard.

    A Little Programming DGU2
    Little description of game mode, blah blah blah.

    A Little Programming DGU25
    Shows what computer rolled. Player has to choose if their roll be be more or less. Classic kind of thing.

    A Little Programming DGU3
    Yup, betting. Player inputs the number of coins they want to bet. If they try to be more than they have it puts it at max.

    A Little Programming DGU4
    Message if you tie. You get your bet back.

    A Little Programming DGU5
    Message if you win. You get back double your bet.

    A Little Programming DGU6
    Message if you lose. (Sucker!)

    A Little Programming DGU7
    Asks to access shop...

    A Little Programming DGU9
    But said shop is currently empty. Maybe I'll add something sometime.

    A Little Programming DGU8
    And asks if you want to play again. If yes, it loops the process until you say no or X it out.

    A Little Programming DGU10
    And if you do say no, then it says bye and also how much you got.



    Phew, there. I was wondering if any of you had any suggestions? And I like to post random stuff I do.
    IcyHaze02
    IcyHaze02
    PhoenixLord
    PhoenixLord

    Posts : 251
    Join date : 2011-10-23
    Age : 33
    Location : California

    A Little Programming Empty Re: A Little Programming

    Post by IcyHaze02 on Mon Jan 02, 2012 10:13 pm

    "Greetings Professor Falken. Shall we play a game? Wouldn't you prefer a good game of chest?"

    Hehehe. Sorry, guess that is not constructive input. This just reminded me of WarGames for some odd reason. Ah, I miss '80s movies.
    avatar
    miller
    Elder Phoenix
    Elder Phoenix

    Posts : 62
    Join date : 2011-11-19

    A Little Programming Empty Re: A Little Programming

    Post by miller on Tue Jan 03, 2012 3:07 pm

    Ah... I actually put bad ideas in NightTiger's head about online casinos.

    Don't do it... online casinos are a favorite of hackers. I personality don't feel any remorse if I can cheat a online casino... but I'd never actually want to operate one with all the issues involved. I believe the U.S. government even shut down some poker sites awhile ago (i.e. Party Poker) because the government wasn't getting their cut.

    But it does seem like Night is a computer science student indeed.

    Tip: Work on any independent project on .NET and you'll get a job easily.
    Nighttiger
    Nighttiger
    Admin
    Admin

    Posts : 189
    Join date : 2011-10-22
    Location : North Carolina, USA

    A Little Programming Empty Re: A Little Programming

    Post by Nighttiger on Tue Jan 03, 2012 6:08 pm

    Haha, I never planned to actually do a casino....

    Sponsored content

    A Little Programming Empty Re: A Little Programming

    Post by Sponsored content


      Current date/time is Tue May 21, 2019 2:19 pm