Это мой код: < /p>
Код: Выделить всё
Scanner sc = new Scanner(System.in);
Random r = new Random();
int mapSize = 10;
int[][] map = new int[mapSize][mapSize];
char[] ABC = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
boolean boom = false;
boolean validInput;
int fields = 0;
int mineCount = 0;
for (int i = 0; i < mapSize; i++) {
for (int j = 0; j < mapSize; j++) {
map[i][j] = r.nextInt(-3, 1);
if (map[i][j] == 0) {
mineCount++;
}
}
}
int totalFields = (mapSize * mapSize) - mineCount;
do {
System.out.print("\t");
for (char letter : ABC) {
System.out.printf("%2c\t", letter);
}
System.out.println();
for (int i = 0; i < mapSize; i++) {
System.out.printf("%d\t", i);
for (int j = 0; j < mapSize; j++) {
if (map[i][j] == 5) {
System.out.print("[*]\t");
} else if (map[i][j] == 2) {
System.out.print("[-]\t");
} else {
System.out.print("[ ]\t");
}
}
System.out.println();
}
// double prozent = (totalFields / 100) * mineFound;; --> alt Eingabe der Prozent berechnung
double percentChecked;
if (totalFields > 0) {
percentChecked = ((fields / (double) totalFields) * 100);
} else {
percentChecked = 100;
}
String result = String.format("%.2f", percentChecked);
System.out.println("\nDu hast " + fields + "/" + totalFields + " (" + result + "%) der sicheren Felder überprüft.");
System.out.println("Es bleiben noch " + mineCount + " Minen versteckt.");
validInput = false;
int x = -1, y = -1;
while (!validInput) {
System.out.println("Wo willst du nach Minen suchen? (z.B. A1 bis J9)");
String inputUser = sc.next().toUpperCase();
if (inputUser.length() == 2 && inputUser.charAt(0) >= 'A' && inputUser.charAt(0) = '0' && inputUser.charAt(1)
Подробнее здесь: [url]https://stackoverflow.com/questions/79423309/how-can-i-loop-through-one-last-time-after-finding-a-mine-in-my-mindsweeper-game[/url]