Need help with Java!

Pew pew \o/...

I'm doing a poker game, but I don't know really how to deal the gards : (.
I know that you can do it with a list or with tables but I've never done anything with list and I don't know what to write to the code when the program need to deal so that it doesn't deal a card twice or how to change cards..

So if there is some lad who wants to code me a list of the cardpack and how to deal and/or how to change cards || the same, but with tables, please /msg sandi @ q-net or write the code here as a comment.

ps. I've already searched from google a little, but couldn't find anything usefull ;(
ps2. I would add you to my friend list! (lol)
Comments
11
Long time since I used java, but from the top of my head:
Make a class Card, with the attributes "flavor", "color", and a bool for wether or not it has been dealt. Then make a class for the carddeck, basically consisting of an array of 52 cards. Write a function within this class to deal a card by generating a random number between 0 and 51, check wether or not the card it landed at has already been dealt (by using the boolean for dealt or not), if it has been dealt, just do it over again. If it hasn't been dealt, deal it and set the bool to true.

However, the more cards you deal the more inefficient this will be. Then maybe you could have two arrays, one for cards that has been dealt and one for cards that has not been dealt.
OR, you can simply randomize the array and draw from the top of it.

And no, i'm not gonna write it for you. I don't remember a jack shit of Java, and you're the one who're supposed to learn it. :)
2 complicated. Just make an ArrayList<Card>() and get a random number modulo the card count left in your deck. Move into the list to that position and remove it.
Parent
Oke. As I said, long time since I used Java, and I was only 12 back then(NERD ALERT) so I guess there's a lot of stuff I never really understood, and I don't really know what tools Java has to offer.

Anyways, it would work, and would be possible to implement in any OOP language :P
And the latter one isn't that complicated imo.
Parent
sounds like you want someone else to code the game for you :p
True :(, I know how its supposed to be done, but I just don't know how to code it :d
Parent
ive hearet its a island
True... But the issue here is about efficeny. If one can remove a card in O(1) (52*O(1) worst case) why do it by calling the randomization function an unkown amount of times?
Sandi go on java.sun.com and look for the java se tutorials. Theyll help u understand oop and java pretty fast. Gl
ps: im on a mobile phone now. Low reply skills
I was thinking as I was writing, and in the end of writing it I realized that it would suck, so I wrote

"However, the more cards you deal the more inefficient this will be. Then maybe you could have two arrays, one for cards that has been dealt and one for cards that has not been dealt.
OR, you can simply randomize the array and draw from the top of it." <-- this.

In the first one, you'd only get one random nr generation per draw. In fact, it's kinda similar to the one you said, only that the second array would be kinda pointless come to think about it. It would require some kind of dynamic array, and since I didn't know jack shit about java I didn't want to assume that such an array were present.

In the last one you'll get an overhead upon shuffling the deck, but then even faster card draws. Not that anybody cares about that übersmallpiconanosecond though. It would "feel" more right though, as that's how they do it in RL :P
Parent
If you can't manage this, I doubt it will be much of a pokergame :--d
Back to top