Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Help Thread
#7
Please pardon the syntax errors. I don't have Netbeans installed that I can change this.

Code:
public static Card[] drawPokerHand() {
        static final int numCards = 5;
        Set pokerValues = new HashSet<Block>();
        Card[] pokerHand = new Card[5];
        Random gen = new Random();
        int randNum;
        
        while(pokerValues.size() + 1 < numCards)
        {
            randNum = gen.nextInt(52)+1;
            pokerValues.add(randNum)
        }
        
        //From here take the values from the HashSet and put it in the pokerHand array.
        
        return pokerHand;
    }

http://download.oracle.com/javase/6/docs...l/Set.html

The other option is to create a "Deck" singleton object, then have the "Poker" class draw from the Deck object to add unique values. Otherwise you could have multiple players that draw the same card twice. So you could have two different straight heart flushes with the same cards.

So, the Deck class would have the following methods:

public GenerateDeck
public ShuffleCards
public DrawCard

And the following properties:

private cards
Reply


Messages In This Thread
Coding Help Thread - by Kalovale - 2011-05-21, 11:11 PM
Coding Help Thread - by Tykian - 2011-05-21, 11:18 PM
Coding Help Thread - by Kalovale - 2011-05-21, 11:30 PM
Coding Help Thread - by Spaz - 2011-05-22, 12:28 AM
Coding Help Thread - by Unauthorized Intruder - 2011-05-22, 12:34 AM
Coding Help Thread - by Kalovale - 2011-05-22, 12:40 AM
Coding Help Thread - by Fiel - 2011-05-22, 01:18 AM
Coding Help Thread - by Fiel - 2011-05-22, 01:44 AM
Coding Help Thread - by Kalovale - 2011-05-22, 01:52 AM
Coding Help Thread - by Luacake - 2011-05-22, 01:43 PM
Coding Help Thread - by Kalovale - 2011-05-23, 06:26 PM
Coding Help Thread - by Fiel - 2011-05-23, 10:47 PM
Coding Help Thread - by Kalovale - 2011-05-23, 11:14 PM
Coding Help Thread - by Fiel - 2011-05-23, 11:48 PM
Coding Help Thread - by Kalovale - 2011-05-24, 03:07 AM
Coding Help Thread - by Stereo - 2011-05-24, 04:05 AM
Coding Help Thread - by Kalovale - 2011-05-26, 10:11 AM
Coding Help Thread - by Fiel - 2011-05-26, 12:39 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)