[help] Need to deal cards
Author |
Message |
syxxone
|
Posted: Fri Jan 16, 2009 10:24 am Post subject: [help] Need to deal cards |
|
|
Hey for my final project im makign the card game 'war' but i dont know how i can get all the cards dealt randomly to 2 people. can anyone help? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
jbking
|
Posted: Fri Jan 16, 2009 1:47 pm Post subject: RE:[help] Need to deal cards |
|
|
What more do you need beyond this:
Card (Which has suit and rank)
Player Deck (Which is merely a queue of Cards which is slightly different than an array)
Then you can simply take the top cards of each deck and whoever wins, just add those cards to the queue. |
|
|
|
|
|
saltpro15
|
Posted: Fri Jan 16, 2009 3:18 pm Post subject: RE:[help] Need to deal cards |
|
|
wikipedia/google the phrases "queuing" and "intstr" assuming you're using Turing. They will help you get the idea |
|
|
|
|
|
DemonWasp
|
Posted: Fri Jan 16, 2009 3:50 pm Post subject: RE:[help] Need to deal cards |
|
|
You need to shuffle the "deck" of cards, then give each player half. OR, you could just give each player random cards out of a group of cards until all the cards are gone.
The second looks like this:
1. Make a List (cough ArrayList cough) and insert all of the cards. You could store them as Card objects that have both suit and value, or you could just use an integer: make the hundreds digit the suit and the ones/tens the value: 107 is Seven of Hearts, etc. Doesn't matter.
2. While there are still cards in the deck, take one card out of the List from step 1 (completely at random) and put that into the Queue that represents each player's deck.
3. When there are no more cards, the players should have a random selection of cards in a random order. |
|
|
|
|
|
|
|