Thread: Help with Black Jack Game

  1. #1
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004

    * SOLVED* Help with Black Jack Game

    *Code Deleted For Protection*
    Last edited by Frantic-; 02-03-2005 at 09:04 PM.

  2. #2
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Are player and computer global variables?
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  3. #3
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Yes both are global.

    here is a list of all my global vars

    int CStay;           //COMPUTER STAYS
    int PStay;             //PLAYER STAYS
    int Played;            //TOTAL GAMES PLAYED
    int Player;            //PLAYER TOTAL CARDS
    int Computer;         //COMPUTER TOTAL CARDS
    int Won = 0;           //GAMES WON
    int Lost = 0;          //GAMES LOST
    int Tie = 0;            //GAMES TIED
    int PAgain;           //PLAY AGAIN INPUT FROM PLAYER
    int Again = 1;      //PLAY AGAIN
    int Cont;             //CONTINUE?

  4. #4
    People Love Me
    Join Date
    Jan 2003
    It looks like you have a few too many calls to other functions in main(). And also, you don't need the "do" statements at all. The best thing is to have a simple WHILE loop control whether or not your program is running:

    while (Exit == false)

    ....for example. If you can contain everything in a nice while or for loop, you can avoid writing extra lines where you make calls to the same functions again and again. Also, the use of global variables is generally frowned on because ANY function can alter them, which defeats the purpose of encapsulating data and hiding it from functions that do not need to be tampering with it.

  5. #5
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    im pretty new to functions, this was an exercise from my book, only it wasnt in as great detail as im making it, i added many features to the game.

    ive pin pointed the problem to be (like i think you said) my int main function, where i call all the other functions. tomorrow, im going to write a new int main function on some paper, and then try that out.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    try a structure closer to this for starters:
    int main(void)
        cout<<"PRESS ENTER TO BEGIN THE GAME\n\n";
        getch(); //WAIT FOR USER TO PRESS RETURN
        system("cls"); //CLEAR SCREEN
            NewGame(); //since it's a new game, clear card value
            FirstDeal(); //CALL FIRSTDEAL FUNCTION
                HitStay(); //HIT OR STAY?
                Check(); //CHECK FOR A WINNER
                AI();   //AI's turn (presumably)
                Check(); //check for a winner
            }while(Cont == 1);
        }while(Again == 1);
        cout<<"\n\nThank you for playing Black Jack";
        getch(); //WAIT FOR USER TO PRESS RETURN
        return(0); //Doesn't confirm anything - only a return value that can be used
                    //to confirm something
    I'm not sure if that's how you intended your logic, but I'm pretty sure that's how it is... then again I did get kinda lost in your code a few times...
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 11:03 AM
  3. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  5. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of
    Replies: 28
    Last Post: 12-20-2003, 12:12 PM