所有的代码都在主要的方法中。所以我打印了一个宾果板,我必须检查一个垂直的胜利。在主方法的if语句结束时,我已经将检查放在一起,但由于某种原因,当我运行程序时,我得到一个无限循环。有人可以向我解释为什么我的错误或错误在哪里,你会怎么做?
package bingo;
import static bingo.Bingo.gameCounter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Bingotake2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] card1 = new int[5][5];
int[] random = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75};
int x = 0, get = 0, gameCount = 0, gameCount2 = 0, county = 0;
int[] columncounter = new int[5];
boolean turn = true, gameOver = true;
System.out.println("PLAYER 1'S CARD");
cardPlayer1(card1);
do {
System.out.println("Enter a positive integer to begin BINGO!/GO AGAIN");
get = input.nextInt();
if (get > 0) {
List l = new ArrayList();
for (int i : random) {
l.add(i);
}
Collections.shuffle(l);
for (int i = 0; i < 1; i++) {
System.out.println(l.get(i));
x = i;
}
System.out.println(" ");
firstPart(columncounter);
for (int k = 0; k < card1.length; k++) {
for (int j = 0; j < card1[k].length; j++) {
county++;
if (card1[k][j] == x) {
columncounter[j]++;
System.out.println("PLAYER 1 CHECK AT " + card1[k][j]);
} else {
//System.out.println("else");
columncounter[j]=0;
}
}
}
for (int p = 0; p < columncounter.length; p++) {
if (columncounter[p] == 5) {
turn = false;
//System.exit (1);
}
}
//System.out.println(random);
} else {
}
} while (turn == true);
System.out.println("PLAYER 1 wins");
// if (gameCount == 5) {
// System.out.println("PLAYER 1 WINS");
// } else {
// System.out.println("PLAYER 2 WINS");
// }
}
public static void cardPlayer1(int[][] card1) {
for (int i = 0; i < card1.length; i++) {
int a, b, c = 0;
for (int j = 0; j < card1[i].length; j++) {
b = (15 * (j + 1));
a = (int) ((b - (b - 14) + 1) * Math.random() + (b - 14));
if (a != card1[0][j] && a != card1[1][j] && a != card1[2][j] && a != card1[3][j] && a != card1[4][j]) {
card1[i][j] = a;
System.out.print("|" + card1[i][j]);
} else {
j--;
}
}
System.out.println(" ");
}
}
public static int[] firstPart(int[] columncounter) {
for (int m = 0; m < columncounter.length; m++) {
columncounter[m] = 0;
}
return columncounter;
}
}