2014-12-04 60 views
1

我正在用java製作一個小型紙牌遊戲。現在,我正在進行手頭分類。但是,當我運行方法'handclassifier'時,我什麼也沒得到。以下是對Eclispe的輸出到控制檯的例子:Java方法在運行後不打印任何東西

標準輸出

Your hand: 6 of Spades, Queen of Spades 
Creek: 10 of Spades, 9 of Spades, Queen of Clubs 
Current value: 

正如你所看到的,handclassifier方法完全不返回任何東西,甚至當一對的要求得到滿足。我已經在前兩種方法之後運行,以便卡片可以加載並通過該方法進行分類。比較代碼中有錯嗎?

主代碼段

package Deck; 
import java.util.*; 
public class creek { 
    public static int i, ii; 
    public static boolean stop = false; 
    public static String card1, card2, fcard1, fcard2, fcard3, cv1, cv2, cs1, cs2, fv1, fv2, fv3,  fs1, fs2, fs3; 
    public static String[] rank = {"Ace", "2", "3", "4", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}; 
    public static String[] suit = {"Spades", "Hearts", "Clubs", "Diamonds"}; 

    public static void hand() { 
     Random ran = new Random(); 
     int counter = 0; 

     for(counter = 0; counter < 1; counter++) { 
      i = ran.nextInt(12); 
      ii = ran.nextInt(3); 
      cv1 = rank[i]; 
      cs1 = suit[ii]; 
      card1 = rank[i] + " of " + suit[ii] ; 
     } 
     for(counter = 1; counter < 2; counter++) { 
      i = ran.nextInt(12); 
      ii = ran.nextInt(3); 
      cv2 = rank[i]; 
      cs2 = suit[ii]; 
      card2 = rank[i] + " of " + suit[ii]; 
     } 
     if (card1.equals(card2)) { 
      while(card1.equals(card2)) { 
       i = ran.nextInt(12); 
       ii = ran.nextInt(3); 
       card2 = rank[i] + " of " + suit[ii]; 
       cv2 = rank[i]; 
       cs2 = suit[ii]; 
      } 
     } 
     counter = 0; 
     System.out.printf("Your hand: %s, %s",card1,card2); 
    } 
    public static void flop() { 
     Random ran = new Random(); 
     int counter = 0; 

     for(counter = 0; counter < 1; counter++) { 
      i = ran.nextInt(12); 
      ii = ran.nextInt(3); 
      fcard1 = rank[i] + " of " + suit[ii]; 
      fv1 = rank[i]; 
      fs1 = suit[ii]; 
     } 
     for(counter = 1; counter < 2; counter++) { 
      i = ran.nextInt(12); 
      ii = ran.nextInt(3); 
      fcard2 = rank[i] + " of " + suit[ii]; 
      fv2 = rank[i]; 
      fs2 = suit[ii]; 
     } 
     for(counter = 2; counter < 3; counter++) { 
      i = ran.nextInt(12); 
      ii = ran.nextInt(3); 
      fcard3 = rank[i] + " of " + suit[ii]; 
      fv3 = rank[i]; 
      fs3 = suit[ii]; 
     } 
     if (fcard1 .equals(card1) || fcard1.equals(card2) || fcard1.equals(fcard2) || fcard1.equals(fcard3)) { 
      while(fcard1.equals(card1) || fcard1.equals(card2) || fcard1.equals(fcard2) || fcard1.equals(fcard3)) { 
       i = ran.nextInt(12); 
       ii = ran.nextInt(3); 
       fcard1 = rank[i] + " of " + suit[ii]; 
       fv1 = rank[i]; 
       fs1 = suit[ii]; 
      } 
     } 
     if (fcard2.equals(card1) || fcard2.equals(card2) || fcard2.equals(fcard1) || fcard2.equals(fcard3)) { 
      while(fcard2.equals(card1) || fcard2.equals(card2) || fcard2.equals(fcard1) || fcard2.equals(fcard3)) { 
       i = ran.nextInt(12); 
       ii = ran.nextInt(3); 
       fcard2 = rank[i] + " of " + suit[ii]; 
       fv2 = rank[i]; 
       fs2 = suit[ii]; 
      } 
     } 
     if (fcard3.equals(card1) || fcard3.equals(card2) || fcard3.equals(fcard1) || fcard3.equals(fcard2)) { 
      while(fcard3.equals(card1) || fcard3.equals(card2) || fcard3.equals(fcard1) || fcard3.equals(fcard2)) { 
       i = ran.nextInt(12); 
       ii = ran.nextInt(3); 
       fcard3 = rank[i] + " of " + suit[ii]; 
       fv3 = rank[i]; 
       fs3 = suit[ii]; 
      } 
     } 
     System.out.printf("\nCreek: %s, %s, %s \n", fcard1, fcard2, fcard3); 
    } 
    public static void handclassifier() { 
     while(stop = false) { 
      if(cv1.equals(cv2) || cv1.equals(fv2) || cv1.equals(fv2) || cv1.equals(fv3) || cv2.equals(fv1) || cv2.equals(fv2) || cv2.equals(fv3) || fv1.equals(fv2)|| fv1.equals(fv3) || fv2.equals(fv3)) { 
       if(cv1.equals(cv2) && cv1.equals(fv1) || cv1.equals(cv2) && cv1.equals(fv2) || cv1.equals(cv2) && cv1.equals(fv3) || cv1.equals(fv1) && cv1.equals(fv2) || cv1.equals(fv2) && cv1.equals(fv3) || cv2.equals(fv1) && fv1.equals(fv2) || cv2.equals(fv2) && fv2.equals(fv3) || fv1.equals(fv2) && fv2.equals(fv3)) { 
        if(cv1.equals(cv2) && cv2.equals(fv1) && fv1.equals(fv2) || cv1.equals(cv2) && cv2.equals(fv1) && fv1.equals(fv3) || cv1.equals(cv2) && cv2.equals(fv2) && fv2.equals(fv3) || cv1.equals(fv1) && fv1.equals(fv2) && fv2.equals(fv3) || cv2.equals(fv1) && cv2.equals(fv2) && cv2.equals(fv3)) { 
         System.out.println("Four of a Kind"); 
         stop = true; 
        } 
        System.out.println("Three of a Kind"); 
        stop = true; 
       } 
       System.out.println("Pair"); 
       stop = true; 
      } 
     } 
    } 

    public static void main(String[] args) { 
     hand(); 
     flop(); 
     System.out.println("Current value: "); 
     handclassifier(); 
    } 
} 

回答

7
while(stop = false) { 

應該

while(!stop) { 

while(stop == false) { 

您比較它的分配falsestop變量,而不是目前的價值爲false

+0

謝謝。這解決了它。 – Monstarules 2014-12-04 13:39:27