Auto
This commit is contained in:
parent
3c29242a61
commit
1333177f88
BIN
Enter$1.class
BIN
Enter$1.class
Binary file not shown.
BIN
Enter.class
BIN
Enter.class
Binary file not shown.
34
Enter.java
34
Enter.java
@ -36,8 +36,12 @@ public class Enter extends JPanel {
|
|||||||
String valueStr = JOptionPane.showInputDialog(null, "Enter value for the selected cell:");
|
String valueStr = JOptionPane.showInputDialog(null, "Enter value for the selected cell:");
|
||||||
try {
|
try {
|
||||||
int value = Integer.parseInt(valueStr);
|
int value = Integer.parseInt(valueStr);
|
||||||
|
if (isValidValue(value, selectedRow, selectedCol)) {
|
||||||
grid[selectedRow][selectedCol] = value;
|
grid[selectedRow][selectedCol] = value;
|
||||||
repaint();
|
repaint();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Not possible.");
|
||||||
|
}
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
JOptionPane.showMessageDialog(null, "Invalid input. Please enter a number.");
|
JOptionPane.showMessageDialog(null, "Invalid input. Please enter a number.");
|
||||||
}
|
}
|
||||||
@ -53,6 +57,34 @@ public class Enter extends JPanel {
|
|||||||
return initialGrid;
|
return initialGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidValue(int value, int row, int col) {
|
||||||
|
// Vérifier la ligne
|
||||||
|
for (int i = 0; i < grid[row].length; i++) {
|
||||||
|
if (grid[row][i] == value && i != col) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier la colonne
|
||||||
|
for (int i = 0; i < grid.length; i++) {
|
||||||
|
if (grid[i][col] == value && i != row) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier la région
|
||||||
|
int regionRow = row / REGION_SIZE * REGION_SIZE;
|
||||||
|
int regionCol = col / REGION_SIZE * REGION_SIZE;
|
||||||
|
for (int i = regionRow; i < regionRow + REGION_SIZE; i++) {
|
||||||
|
for (int j = regionCol; j < regionCol + REGION_SIZE; j++) {
|
||||||
|
if (grid[i][j] == value && (i != row || j != col)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
@ -85,6 +117,4 @@ public class Enter extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BIN
Main$1.class
BIN
Main$1.class
Binary file not shown.
BIN
Main.class
BIN
Main.class
Binary file not shown.
BIN
Reset.class
BIN
Reset.class
Binary file not shown.
BIN
Resolve.class
BIN
Resolve.class
Binary file not shown.
BIN
SudokuDraw.class
BIN
SudokuDraw.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user