ajout de petit correctifs
This commit is contained in:
parent
812d9d7a26
commit
b31d0f0dbb
@ -99,8 +99,6 @@ public class Resolver implements ActionListener {
|
|||||||
JOptionPane.showMessageDialog(null, "Grille terminé en " + df.format(durée) + " secondes", "Résolution automatique", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Grille terminé en " + df.format(durée) + " secondes", "Résolution automatique", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
private int row;
|
private int row;
|
||||||
private int col;
|
private int col;
|
||||||
private ArrayList<Integer> bad_numbers = new ArrayList<Integer>();
|
private ArrayList<Integer> bad_numbers = new ArrayList<Integer>();
|
||||||
private boolean errorDetected = true;
|
private boolean errorDetected = false;
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
public TextFilter (JTextField t,int GRID_SIZE, JTextField[][] grid, int i, int j, int status) {
|
public TextFilter (JTextField t,int GRID_SIZE, JTextField[][] grid, int i, int j, int status) {
|
||||||
@ -37,6 +37,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
|
|
||||||
char chiffre = e.getKeyChar();
|
char chiffre = e.getKeyChar();
|
||||||
int taille = this.Text.getText().length();
|
int taille = this.Text.getText().length();
|
||||||
|
boolean end_game = true;
|
||||||
|
|
||||||
// Si la longueur du texte est égale à 3 après l'ajout du chiffre, définir la taille de la police à 20
|
// Si la longueur du texte est égale à 3 après l'ajout du chiffre, définir la taille de la police à 20
|
||||||
if (taille > 1) {
|
if (taille > 1) {
|
||||||
@ -52,7 +53,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
|
|
||||||
// Vérifier le statut (1 == concepteur,2 == joueur)
|
// Vérifier le statut (1 == concepteur,2 == joueur)
|
||||||
if (status == 2){
|
if (status == 2){
|
||||||
if (errorDetected) {
|
if (!errorDetected) {
|
||||||
if ((chiffre >= '1') && (chiffre <= '9')) {
|
if ((chiffre >= '1') && (chiffre <= '9')) {
|
||||||
GrilleValide(chiffre);
|
GrilleValide(chiffre);
|
||||||
}
|
}
|
||||||
@ -78,13 +79,35 @@ public class TextFilter extends KeyAdapter {
|
|||||||
while (!bad_numbers.isEmpty()) {
|
while (!bad_numbers.isEmpty()) {
|
||||||
grid[bad_numbers.removeFirst()][bad_numbers.removeFirst()].setBackground(Color.white);
|
grid[bad_numbers.removeFirst()][bad_numbers.removeFirst()].setBackground(Color.white);
|
||||||
}
|
}
|
||||||
errorDetected = true; // Réinitialiser errorDetected après avoir corrigé les erreurs
|
errorDetected = false; // Réinitialiser errorDetected après avoir corrigé les erreurs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Défini la taille maiximum par case
|
// Défini la taille maiximum par case
|
||||||
if ( taille >= 4) {
|
if ( taille >= 4) {
|
||||||
e.consume();
|
e.consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Test si toutes les cases sont remplies et affiche un message de fin
|
||||||
|
if (!errorDetected) {
|
||||||
|
for (int row = 0; row < GRID_SIZE; row++) {
|
||||||
|
for (int col = 0; col < GRID_SIZE; col++) {
|
||||||
|
|
||||||
|
String value = grid[row][col].getText();
|
||||||
|
// Vérifier si la case contient plus d'un chiffre
|
||||||
|
if (value.length() > 1) {
|
||||||
|
end_game = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grid[row][col].getText().isEmpty()) {
|
||||||
|
end_game = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (end_game) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Bravo vous avez terminé la grille !", "Fin du jeu", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if(status == 1){
|
} else if(status == 1){
|
||||||
// Traite la saisie pour savoir si le chiffer peut être posé
|
// Traite la saisie pour savoir si le chiffer peut être posé
|
||||||
if ( taille > 1 && ((chiffre >= '1') && (chiffre <= '9')) && (chiffre != KeyEvent.VK_ENTER)) {
|
if ( taille > 1 && ((chiffre >= '1') && (chiffre <= '9')) && (chiffre != KeyEvent.VK_ENTER)) {
|
||||||
@ -123,7 +146,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
this.grid[row][col].setBackground(Color.red);
|
this.grid[row][col].setBackground(Color.red);
|
||||||
this.bad_numbers.add(row2);
|
this.bad_numbers.add(row2);
|
||||||
this.bad_numbers.add(col);
|
this.bad_numbers.add(col);
|
||||||
errorDetected = false;
|
errorDetected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +158,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
this.grid[row][col].setBackground(Color.red);
|
this.grid[row][col].setBackground(Color.red);
|
||||||
this.bad_numbers.add(row2);
|
this.bad_numbers.add(row2);
|
||||||
this.bad_numbers.add(col);
|
this.bad_numbers.add(col);
|
||||||
errorDetected = false;
|
errorDetected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +172,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
this.grid[row][col].setBackground(Color.red);
|
this.grid[row][col].setBackground(Color.red);
|
||||||
this.bad_numbers.add(row);
|
this.bad_numbers.add(row);
|
||||||
this.bad_numbers.add(col2);
|
this.bad_numbers.add(col2);
|
||||||
errorDetected = false;
|
errorDetected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +184,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
this.grid[row][col].setBackground(Color.red);
|
this.grid[row][col].setBackground(Color.red);
|
||||||
this.bad_numbers.add(row);
|
this.bad_numbers.add(row);
|
||||||
this.bad_numbers.add(col2);
|
this.bad_numbers.add(col2);
|
||||||
errorDetected = false;
|
errorDetected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +202,7 @@ public class TextFilter extends KeyAdapter {
|
|||||||
this.grid[row][col].setBackground(Color.red);
|
this.grid[row][col].setBackground(Color.red);
|
||||||
this.bad_numbers.add(row2);
|
this.bad_numbers.add(row2);
|
||||||
this.bad_numbers.add(col2);
|
this.bad_numbers.add(col2);
|
||||||
errorDetected = false;
|
errorDetected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user