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!
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!
oh yeah! remember to maximize the console window and scroll all the way when you play
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.
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!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 )
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:
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.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 }
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:
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.Code:for (int x=0; x<52; x++) swap deck[x] with deck[rand()%52];
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...
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.