Case grisée quand grille importé dans SudokuGame + sa Javadoc
This commit is contained in:
parent
0c81953d8d
commit
aecb28232e
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
# List of Java source files
|
# List of Java source files
|
||||||
SRCS := Cell.java GenerateGrid.java Grid.java Sudoku.java SudokuButtonListener.java SudokuSolver.java SudokuUI.java SudokuCreator.java
|
SRCS := Cell.java GenerateGrid.java Grid.java Sudoku.java SudokuButtonListener.java SudokuSolver.java SudokuUI.java SudokuCreator.java SudokuGame.java
|
||||||
|
|
||||||
# Directory to store compiled class files
|
# Directory to store compiled class files
|
||||||
BUILD_DIR := build
|
BUILD_DIR := build
|
||||||
|
@ -6,25 +6,41 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* La classe SudokuGame étend la classe SudokuUI et représente une application de jeu de Sudoku avec des fonctionnalités supplémentaires telles que le chargement de grilles et la résolution automatique.
|
||||||
|
*/
|
||||||
public class SudokuGame extends SudokuUI {
|
public class SudokuGame extends SudokuUI {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur de la classe SudokuGame.
|
||||||
|
* @param sudoku La grille de Sudoku à utiliser pour le jeu.
|
||||||
|
*/
|
||||||
public SudokuGame(Sudoku sudoku) {
|
public SudokuGame(Sudoku sudoku) {
|
||||||
super(sudoku);
|
super(sudoku);
|
||||||
createAdditionalButtons();
|
createAdditionalButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour obtenir le texte du titre de l'interface utilisateur.
|
||||||
|
* @return Le texte du titre.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String getTitleText() {
|
protected String getTitleText() {
|
||||||
return "Sudoku Game";
|
return "Sudoku Game";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour créer les boutons de chargement et de résolution et redimensionner la fenêtre.
|
||||||
|
*/
|
||||||
protected void createAdditionalButtons() {
|
protected void createAdditionalButtons() {
|
||||||
createLoadButton();
|
createLoadButton();
|
||||||
createSolveButton();
|
createSolveButton();
|
||||||
pack(); // Redimensionner la fenêtre pour s'adapter aux nouveaux boutons
|
pack(); // Redimensionner la fenêtre pour s'adapter aux nouveaux boutons
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour créer le bouton de résolution.
|
||||||
|
*/
|
||||||
private void createSolveButton() {
|
private void createSolveButton() {
|
||||||
JButton solveButton = new JButton("Résoudre");
|
JButton solveButton = new JButton("Résoudre");
|
||||||
solveButton.addActionListener(new ActionListener() {
|
solveButton.addActionListener(new ActionListener() {
|
||||||
@ -51,6 +67,9 @@ public class SudokuGame extends SudokuUI {
|
|||||||
add(buttonPanel, BorderLayout.SOUTH);
|
add(buttonPanel, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour créer le bouton de chargement.
|
||||||
|
*/
|
||||||
private void createLoadButton() {
|
private void createLoadButton() {
|
||||||
JButton loadButton = new JButton("Charger");
|
JButton loadButton = new JButton("Charger");
|
||||||
loadButton.addActionListener(new ActionListener() {
|
loadButton.addActionListener(new ActionListener() {
|
||||||
@ -73,16 +92,24 @@ public class SudokuGame extends SudokuUI {
|
|||||||
add(buttonPanel, BorderLayout.NORTH);
|
add(buttonPanel, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour mettre à jour les valeurs des boutons de la grille après un chargement ou une résolution.
|
||||||
|
*/
|
||||||
private void updateGrid() {
|
private void updateGrid() {
|
||||||
Grid grid = sudoku.getGrid();
|
Grid grid = sudoku.getGrid();
|
||||||
for (int row = 0; row < 9; row++) {
|
for (int row = 0; row < 9; row++) {
|
||||||
for (int col = 0; col < 9; col++) {
|
for (int col = 0; col < 9; col++) {
|
||||||
int value = grid.getCell(row, col).getValue();
|
int value = grid.getCell(row, col).getValue();
|
||||||
buttons[row][col].setText(value == 0 ? "" : String.valueOf(value));
|
buttons[row][col].setText(value == 0 ? "" : String.valueOf(value));
|
||||||
|
buttons[row][col].setEnabled(value == 0); // Désactive les boutons pour les cellules déjà remplies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode principale pour démarrer le jeu de Sudoku.
|
||||||
|
* @param args Les arguments de la ligne de commande (non utilisés).
|
||||||
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Sudoku sudoku = new Sudoku();
|
Sudoku sudoku = new Sudoku();
|
||||||
new SudokuGame(sudoku);
|
new SudokuGame(sudoku);
|
||||||
|
BIN
build/Cell.class
BIN
build/Cell.class
Binary file not shown.
Binary file not shown.
BIN
build/Grid.class
BIN
build/Grid.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/SudokuGame$1.class
Normal file
BIN
build/SudokuGame$1.class
Normal file
Binary file not shown.
BIN
build/SudokuGame$2.class
Normal file
BIN
build/SudokuGame$2.class
Normal file
Binary file not shown.
BIN
build/SudokuGame.class
Normal file
BIN
build/SudokuGame.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user