我是java編程的新手,並創建了一個基於控制檯的Sudoku遊戲作爲練習。回溯算法生成一個完整的數獨,另一種方法'挖洞'到隨機細胞中(關於難度)。現在,值0被設置爲空白單元格,但我不喜歡Sudoku看起來的樣子。董事會中的數字太多了,我認爲空白將是一個不錯的選擇。玩家仍然可以用他自己的猜測替換單元格中的(現在爲'0',後面的空格)。 有沒有辦法在int值爲0時替換int值?算法和digHole方法都在二維數組(座標)上使用setValue方法。Sudoku:將int值顯示爲空白
感謝您的幫助!
這裏是我的板圖中:
public static void drawBoard() {
String[] abc = { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
// i := rows
for (int i = 0; i <= 8; i++) {
// first row
if (i == 0) {
System.out.println("");
// coordinates 1-9
System.out.println(" 1 2 3 4 5 6 7 8 9\n" + " _____________________________________ \n"
+ " | |");
}
// j := columns in row i
for (int j = 0; j <= 8; j++) {
if (j == 0) {
// coordinates A-I and first column
System.out.print(" " + abc[i] + " | " + sudokuCells[i][j].getValue() + " ");
} else if (j == 8) {
// last cell in current row
System.out.print(" " + sudokuCells[i][j].getValue() + " |");
System.out.println("");
} else if (j == 2 || j == 5) {
//frame
System.out.print(" " + sudokuCells[i][j].getValue() + " |");
} else {
//whitespace as seperation
System.out.print(" " + sudokuCells[i][j].getValue() + " ");
}
}
// last row with frame
if (i == 8) {
System.out.println(" |_____________________________________|");
System.out.println();
}
你有任何代碼來給我們你是如何努力實現它的想法?如果在顯示程序中應該足夠簡單的話就是 – cozyconemotel
。 'if(data [x] [y] == 0){display(「」)}'用您用來顯示數據的任何方法替換顯示,並用數據源替換數據。 – HopefullyHelpful
我們不關心你的生成代碼,只是改變你打印數獨的方法到控制檯。 – HopefullyHelpful