Need help with Java!
•
5 Apr 2008, 22:29
•
Journals
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)
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)
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. :)
Anyways, it would work, and would be possible to implement in any OOP language :P
And the latter one isn't that complicated imo.
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
"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