Java扑克 - 比较手牌

时间:2016-02-02 00:56:00

标签: java

我可能还有其他一些错误,但我无法弄清楚为什么我的手比较不起作用。我无法得到任何类型的匹配,我知道我可以进入两个for循环,但我无法进入:

if (currentHand1[i][1] == currentHand1[j][1]) {
    matches++;
}

我只是需要帮助。如何比较卡的价值。拜托,谢谢。

public static void disPlayIntro()
{
    String prompt = "This program will generate \n"+
            " two hands of poker.\n\n"+
            " Both hands will be displayed\n\n"+
            " You will be asked if you wish to\n"+
            " have two more hands generated?\n"+
            " Enter anything but no to quit\n";;

            JOptionPane.showMessageDialog(null, prompt,"Generate Poker Hands",1);

}

public static void main(String[] args)
{
    disPlayIntro();
    int [][] deck        = new int[13][4];
    int [][] currentHand1 = new int[5][2];
    int [][] currentHand2 = new int[5][2];
    int [][] found = new int [5][5];
    int foundCounter = 0;
    int suit = 0;
    int card = 0;

    String howWon = "";
    int matches = 0;

    String[] suits = {"Hearts", "Spades","Diamonds","Clubs"};
    String[] cards = {"Ace", "2","3","4","5","6","7","8","9","10","Jack","Queen","King"};

    Random randGen = new Random();
    do
    {
        String hand1 = "";
        //dealing hand 1
        for(int dex = 0; dex < currentHand1.length; dex++)
        {
            boolean goodCard = false;
            while(!goodCard)
            {
                int suit = randGen.nextInt(4);
                int card = randGen.nextInt(13);

                if( deck[card][suit] == 0)
                {
                    goodCard = true;
                    deck[card][suit] = 1;
                    currentHand1[dex][0] = suit;
                    currentHand1[dex][1] = card;


                    //start loop through hand
                    for(int i = 0; i < currentHand1[1].length-1;i++){
                        if(cards[card].equals(cards[card])){

                        }
                        //Start counting pairs
                        matches = 0;
                        for(int j = i+1; j < currentHand1[1].length; j++){
                            if(currentHand1[i][1] == currentHand1[j][1]){

                                //add later:
                                //before incrementing matches, verify that this card has not been found

                                matches++;
                            }

                        }

                        //find high card



                    }

                    hand1 += "     "+cards[card]+" of "+suits[suit]+"\n";
                    JOptionPane.showMessageDialog(null, matches, "matches", 1);
                }
            }
        }


        String hand2 = "";
        //dealing hand 1
        for(int dex = 0; dex < currentHand2.length; dex++)
        {
            boolean goodCard = false;
            while(!goodCard)
            {
                suit = randGen.nextInt(4);
                card = randGen.nextInt(13);

                if( deck[card][suit] == 0)
                {
                    goodCard = true;
                    deck[card][suit] = 1;
                    currentHand2[dex][0] = suit;
                    currentHand2[dex][1] = card;

                    hand2 += "     "+cards[card]+" of "+suits[suit]+"\n";
                }
            }
        }



        /*if(matches == 2){
            howWon = "a pair: ";
        }
        else if (matches == 3){
            howWon = "3 of a kind: ";
        }
        else if (matches == 4){
            howWon = "4 of a kind: ";
        }*/



        String results = "The first hand of cards:\n\n"+hand1+"\n\n\n";
        results += "The second hand of cards:\n\n"+hand2+"\n";
        results += "Do you want another two hands?\nenter 'Y'  or 'N'";
        String ans = JOptionPane.showInputDialog(null,results,"Show hands",1);

        //  System.out.println(howWon);

        if(!ans.toUpperCase().equals("Y"))
        {
            JOptionPane.showMessageDialog(null, "Program terminating!","Generate Poker Hands",1);
            System.exit(0);
        }

    }while(true);
}   

0 个答案:

没有答案