52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
package sudoku.io;
|
|
|
|
import sudoku.structure.MultiDoku;
|
|
import sudoku.structure.Sudoku;
|
|
|
|
public class SudokuPrinter {
|
|
|
|
public static void printRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight) {
|
|
for (int y = 0; y < s.getSize(); y++) {
|
|
if (y % blockHeight == 0 && y > 0) {
|
|
System.out.println();
|
|
}
|
|
StringBuilder line = new StringBuilder("[ ");
|
|
for (int x = 0; x < s.getSize(); x++) {
|
|
line.append((s.getCell(x, y).getSymbolIndex() + 1)).append(" ");
|
|
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
|
|
line.append("| ");
|
|
}
|
|
}
|
|
line.append("]");
|
|
System.out.println(line);
|
|
}
|
|
}
|
|
|
|
public static String toStringRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight) {
|
|
StringBuilder result = new StringBuilder();
|
|
for (int y = 0; y < s.getSize(); y++) {
|
|
// Ajouter une ligne vide entre les blocs horizontaux
|
|
if (y % blockHeight == 0 && y > 0) {
|
|
result.append("\n");
|
|
}
|
|
StringBuilder line = new StringBuilder("[ ");
|
|
for (int x = 0; x < s.getSize(); x++) {
|
|
// Ajouter la valeur de la cellule
|
|
line.append((s.getCell(x, y).getSymbolIndex() + 1)).append(" ");
|
|
|
|
// Ajouter un séparateur vertical entre les blocs
|
|
if (x % blockWidth == blockWidth - 1 && x != s.getSize() - 1) {
|
|
line.append("| ");
|
|
}
|
|
}
|
|
line.append("]");
|
|
result.append(line).append("\n");
|
|
}
|
|
return result.toString();
|
|
}
|
|
|
|
public static void printMultiDoku(final MultiDoku doku, int blockWidth, int blockHeight){
|
|
// TODO
|
|
}
|
|
}
|