refactor: improve code comments and app menu
This commit is contained in:
@@ -13,7 +13,7 @@ public class Grille {
|
||||
private final Case[][] cases;
|
||||
private final ArrayList<Bloc> blocs;
|
||||
private ArrayList<Symbole> symbolesPossibles;
|
||||
private final Sudoku sudoku;
|
||||
private final Sudoku sudoku; // Référence à Sudoku
|
||||
private Multidoku multidoku; // Référence à Multidoku
|
||||
private List<String> generatedColors;
|
||||
|
||||
@@ -23,8 +23,6 @@ public class Grille {
|
||||
this.blocs = new ArrayList<>();
|
||||
this.symbolesPossibles = new ArrayList<>();
|
||||
this.sudoku = sudoku;
|
||||
// Pour un sudoku classique, on attend "taille" blocs, donc on génère "taille"
|
||||
// couleurs.
|
||||
initColors();
|
||||
|
||||
// Initialiser les cases
|
||||
@@ -70,7 +68,6 @@ public class Grille {
|
||||
Symbole ancienSymbole = currentCase.getSymbole();
|
||||
currentCase.setSymbole(symbole);
|
||||
|
||||
// Verify constraints including shared cases
|
||||
if (!sudoku.verifierToutesContraintes() ||
|
||||
(multidoku != null && !multidoku.verifierContraintesPartagees())) {
|
||||
currentCase.setSymbole(ancienSymbole);
|
||||
@@ -134,33 +131,28 @@ public class Grille {
|
||||
* Crée des blocs carrés (par exemple pour un sudoku classique).
|
||||
*/
|
||||
public void creerBlocCarre() {
|
||||
try {
|
||||
int blocSize = (int) Math.sqrt(taille);
|
||||
if (blocSize * blocSize != taille) {
|
||||
throw new IllegalArgumentException("La taille de la grille doit être un carré parfait.");
|
||||
}
|
||||
int blocSize = (int) Math.sqrt(taille);
|
||||
if (blocSize * blocSize != taille) {
|
||||
throw new IllegalArgumentException("La taille de la grille doit être un carré parfait.");
|
||||
}
|
||||
|
||||
// Création des blocs en motif (par exemple 3x3 pour un sudoku 9x9)
|
||||
for (int blocRow = 0; blocRow < blocSize; blocRow++) {
|
||||
for (int blocCol = 0; blocCol < blocSize; blocCol++) {
|
||||
List<int[]> positions = new ArrayList<>();
|
||||
// Création des blocs en motif (par exemple 3x3 pour un sudoku 9x9)
|
||||
for (int blocRow = 0; blocRow < blocSize; blocRow++) {
|
||||
for (int blocCol = 0; blocCol < blocSize; blocCol++) {
|
||||
List<int[]> positions = new ArrayList<>();
|
||||
|
||||
// Ajouter toutes les positions pour le bloc courant
|
||||
for (int i = 0; i < blocSize; i++) {
|
||||
for (int j = 0; j < blocSize; j++) {
|
||||
positions.add(new int[] {
|
||||
blocRow * blocSize + i,
|
||||
blocCol * blocSize + j
|
||||
});
|
||||
}
|
||||
// Ajouter toutes les positions pour le bloc courant
|
||||
for (int i = 0; i < blocSize; i++) {
|
||||
for (int j = 0; j < blocSize; j++) {
|
||||
positions.add(new int[] {
|
||||
blocRow * blocSize + i,
|
||||
blocCol * blocSize + j
|
||||
});
|
||||
}
|
||||
|
||||
// Affectation cyclique d'une couleur issue de la palette générée
|
||||
setCouleurBloc(positions);
|
||||
}
|
||||
|
||||
setCouleurBloc(positions);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Console.errorln(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,35 +162,31 @@ public class Grille {
|
||||
* Ne fonctionne pas pour les grilles dont la taille est un carré parfait.
|
||||
*/
|
||||
public void creerBlocRectangulaire(int blocHeight, int blocWidth) {
|
||||
try {
|
||||
if (taille % blocHeight != 0 || taille % blocWidth != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"La taille de la grille doit être divisible par les dimensions des blocs.");
|
||||
}
|
||||
if (taille % blocHeight != 0 || taille % blocWidth != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"La taille de la grille doit être divisible par les dimensions des blocs.");
|
||||
}
|
||||
|
||||
int blocsParLigne = taille / blocWidth;
|
||||
int blocsParColonne = taille / blocHeight;
|
||||
int blocsParLigne = taille / blocWidth;
|
||||
int blocsParColonne = taille / blocHeight;
|
||||
|
||||
// Création des blocs en motif rectangulaire
|
||||
for (int blocRow = 0; blocRow < blocsParColonne; blocRow++) {
|
||||
for (int blocCol = 0; blocCol < blocsParLigne; blocCol++) {
|
||||
List<int[]> positions = new ArrayList<>();
|
||||
// Création des blocs en motif rectangulaire
|
||||
for (int blocRow = 0; blocRow < blocsParColonne; blocRow++) {
|
||||
for (int blocCol = 0; blocCol < blocsParLigne; blocCol++) {
|
||||
List<int[]> positions = new ArrayList<>();
|
||||
|
||||
// Ajouter toutes les positions pour le bloc courant
|
||||
for (int i = 0; i < blocHeight; i++) {
|
||||
for (int j = 0; j < blocWidth; j++) {
|
||||
positions.add(new int[] {
|
||||
blocRow * blocHeight + i,
|
||||
blocCol * blocWidth + j
|
||||
});
|
||||
}
|
||||
// Ajouter toutes les positions pour le bloc courant
|
||||
for (int i = 0; i < blocHeight; i++) {
|
||||
for (int j = 0; j < blocWidth; j++) {
|
||||
positions.add(new int[] {
|
||||
blocRow * blocHeight + i,
|
||||
blocCol * blocWidth + j
|
||||
});
|
||||
}
|
||||
|
||||
setCouleurBloc(positions);
|
||||
}
|
||||
|
||||
setCouleurBloc(positions);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Console.errorln(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,23 +355,23 @@ public class Grille {
|
||||
String cellStr = currentCase.toString();
|
||||
// Calculer le nombre d'espaces à ajouter pour atteindre maxLen
|
||||
int pad = maxLen - cellStr.length();
|
||||
String padding = " ".repeat(pad); // nécessite Java 11 ou ultérieur
|
||||
String padding = " ".repeat(pad);
|
||||
|
||||
Bloc bloc = findBlocForCase(currentCase);
|
||||
|
||||
if (bloc != null) {
|
||||
sb.append(bloc.getCouleur()) // couleur du bloc
|
||||
.append(cellStr)
|
||||
.append(padding)
|
||||
.append(cellStr) // symbole
|
||||
.append(padding) // padding pour aligner les symboles
|
||||
.append("\u001B[0m ") // réinitialiser la couleur
|
||||
.append(" ");
|
||||
} else {
|
||||
} else { // pas de bloc, afficher normalement
|
||||
sb.append(cellStr)
|
||||
.append(padding)
|
||||
.append(" ");
|
||||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
sb.append("\n"); // nouvelle ligne
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user