我正在用Java制作一个小纸牌游戏。现在,我正在进行手工分类。但是,当我运行方法'handclassifier'时,我什么都得不到。以下是eclispe输出到控制台的示例:
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();
}
}
答案 0 :(得分:7)
while(stop = false) {
应该是
while(!stop) {
或
while(stop == false) {
您要将false
分配给stop
变量,而不是将其当前值与false
进行比较。