Click to See Complete Forum and Search --> : Java - Poker game memory madness
mart_man00
08-26-2004, 09:54 PM
Right now im trying to write a program to play some cards(probally something easy likeblackjack at first).
I made a object for the deck, indivual cards and the hand.
Im wondering how i should go about using them.
I was thinking to just mark the cards in the deck as used then create the same card in the hand, but seems kind of waste ful(too more or less identical objects).
Im wondering if theres a better approach. I have no ideas since i cant use a good old pointer:P
Thanks
mart_man00
08-26-2004, 10:01 PM
Sorry, ment to put this in the programming section, dont know how i manged to pull this one off....
Mod-ly Help anychance?
aNoob
08-27-2004, 05:04 AM
Why not use a Vector?
You create an object called Card with property cardStatus which can be IN_STACK , IN_HAND,IS_DRAWN. Another property isUsed which will change value based on the first one i.e cardStatus = IN_HAND if inHand or cardStatus = IS_DRAWN and false if cardStatus = IN_STACK.
Then you either make your own object Stack which should extend Vector class or directly use Vector class.
Then you create a Vector of Cards.
fiske
08-27-2004, 08:39 AM
I just recently took data structures so my experience is
limited and I don't know how practical this is, but could you
have card be as object. Then inside the game's class create
the deck as a stack, of cards initially sized at 52. Then
when you deal you'd pop the deck and put it inside an array
hand
ph34r
08-27-2004, 09:01 AM
When I wrote a poker game for a VB class, I made the deck of cards just an array with 52 spaces - each space contained a number 1-52. 1 == 2 of spades, 13 == ace of spades, 14 == 2 of clubs, etc.
Pick random numbers 1-52, check to make sure they've not been picked already, and there's your dealt hand - put it in an array. Sort the array. Then if card 1 val == card 2 val + 13, and cards 3-5 are different, you have a pair in hte first position. LOTS of convoluted if-thens later, you can figure out what hand you have.
mart_man00
08-27-2004, 10:43 PM
hmmmm
guessing i should look into vectors and stacks, thanks
cant believe there wasnt a single person on irc that could of just said that....
fatTrav
08-28-2004, 04:27 PM
I think a stack is perhaps the best solution presented. A stack mimics a card deck the best. Deal a card off the top, pop an item off a stack.
Although a Stack is just a vector with a few extra methods in Java. Might be trickey to randomize it though. An ArrayList might also be a good idea.