My blackjack game is done!

This is a discussion on My blackjack game is done! within the Game Programming forums, part of the General Programming Boards category; The exe and source code are in the zip... Please play the game before looking at the code too much, ...

  1. #1
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138

    My blackjack game is done!

    The exe and source code are in the zip... Please play the game before looking at the code too much, because im sure the code will change your opinion of the game . Tell me what ya think!
    Attached Files Attached Files

  2. #2
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    oh yeah! remember to maximize the console window and scroll all the way when you play

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I'm impressed.
    Away.

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    you should clear "BLACKJACK!" off the screen after a new hand is dealt. I'm still impressed.

    edit: actually, there are a couple errors there. Check 'em out.
    Last edited by confuted; 06-08-2003 at 06:33 PM.
    Away.

  5. #5
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    the only error I know of is that every once in a while it will take a while to deal out a card because it keeps trying to deal a card that is already there and the rand card keep getting already delt cards (ie there arent 2 ace of spades in a deck of cards )

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by o0obruceleeo0o
    the only error I know of is that every once in a while it will take a while to deal out a card because it keeps trying to deal a card that is already there and the rand card keep getting already delt cards (ie there arent 2 ace of spades in a deck of cards )
    to solve this, why not keep an array of every possible card then randomly chose an index in that array ( between 0 and SIZE where SIZE is the size of the array, initially 52) then after you chose a card, copy the card in the last position (SIZE - 1) to the index of the card you just selected and decrease the size of the array by one!

  7. #7
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I like the graphics, good job!

    My only problem with it is that its played in a two player style instead of a casino style (player vs dealer) which is how it is usually played. It would be kind of cool if you allowed betting, doubling down, splitting etc.

    I looked at the code and I must say that there is a LOT of redundant code. Instead of having huge if statements for every card position drawn, couldn't you have it once? Since the only thing that changes is the x and y position drawn, all you would need to do is pass those variables to the function, something like this:
    Code:
    void drawCard(int xPos, int yPos)
    {
        //draw card at xPos and yPos;
    }
    
    int main()
    {
         // get first card
         drawCard(0,0);
         // get second card
         drawCard(50,0);
         // etc etc
    }
    So you would only need a separate function that draws the upside down card, all other cards could be drawn using the x and y positions and the drawCard function.

    Also, a real easy way to keep track of a deck of cards (and you don't want to use structs or objects) is to simply have an array of ints of size 52. To start off, deck[0]=0, deck[1]=1, deck[2]=2 etc. Then you have a function that shuffles the deck randomly like this:
    Code:
    for (int x=0; x<52; x++)
       swap deck[x] with deck[rand()%52];
    Then just pull cards off the top of the deck, modulus 13 and modulus 4 to find out the card value and suit. Never have to worry about duplicate cards and you could just reshuffle as often as you like and start over with the first card.

  8. #8
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    To be honest, after I realized the problems in my code I did not change it because I got lazy and bored of making the program lol. Right now I am in the part if my book where I start to learn some windows programming, so Im excited to make a game in windows...

  9. #9
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    After the blackjack, it doesn't clear the text for the blackjack off the screen, and it doesn't show the new cards when you deal until the hand after the hand immediately after the blackjack.
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  4. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  5. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21