diff --git a/Enter$1.class b/Enter$1.class deleted file mode 100644 index be8b132..0000000 Binary files a/Enter$1.class and /dev/null differ diff --git a/Enter.class b/Enter.class deleted file mode 100644 index a429358..0000000 Binary files a/Enter.class and /dev/null differ diff --git a/Enter.java b/Enter.java index d93f60a..36a1403 100644 --- a/Enter.java +++ b/Enter.java @@ -36,8 +36,12 @@ public class Enter extends JPanel { String valueStr = JOptionPane.showInputDialog(null, "Enter value for the selected cell:"); try { int value = Integer.parseInt(valueStr); - grid[selectedRow][selectedCol] = value; - repaint(); + if (isValidValue(value, selectedRow, selectedCol)) { + grid[selectedRow][selectedCol] = value; + repaint(); + } else { + JOptionPane.showMessageDialog(null, "Not possible."); + } } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Invalid input. Please enter a number."); } @@ -50,41 +54,67 @@ public class Enter extends JPanel { } public int[][] getInitialGrid() { - 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 protected void paintComponent(Graphics g) { - super.paintComponent(g); + super.paintComponent(g); - // Dessiner les contours de la grille (en gras) - Graphics2D g2d = (Graphics2D) g; - Stroke oldStroke = g2d.getStroke(); // Sauvegarder le style de ligne précédent - g2d.setStroke(new BasicStroke(4)); // Épaisseur de ligne de 4 pixels + // Dessiner les contours de la grille (en gras) + Graphics2D g2d = (Graphics2D) g; + Stroke oldStroke = g2d.getStroke(); // Sauvegarder le style de ligne précédent + g2d.setStroke(new BasicStroke(4)); // Épaisseur de ligne de 4 pixels - for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) { - if (i % REGION_SIZE == 0) { - g2d.drawLine(0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE, i * CELL_SIZE); - g2d.drawLine(i * CELL_SIZE, 0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE); + for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) { + if (i % REGION_SIZE == 0) { + g2d.drawLine(0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE, i * CELL_SIZE); + g2d.drawLine(i * CELL_SIZE, 0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE); + } } - } - // Rétablir le style de ligne précédent - g2d.setStroke(oldStroke); + // Rétablir le style de ligne précédent + g2d.setStroke(oldStroke); - // Dessiner les cases de la grille - for (int i = 0; i < GRID_SIZE * REGION_SIZE; i++) { - for (int j = 0; j < GRID_SIZE * REGION_SIZE; j++) { - g.setColor(Color.BLACK); - g.drawRect(j * CELL_SIZE, i * CELL_SIZE, CELL_SIZE, CELL_SIZE); - int value = grid[i][j]; - if (value != 0) { - g.drawString(String.valueOf(value), j * CELL_SIZE + CELL_SIZE / 2, i * CELL_SIZE + CELL_SIZE / 2); + // Dessiner les cases de la grille + for (int i = 0; i < GRID_SIZE * REGION_SIZE; i++) { + for (int j = 0; j < GRID_SIZE * REGION_SIZE; j++) { + g.setColor(Color.BLACK); + g.drawRect(j * CELL_SIZE, i * CELL_SIZE, CELL_SIZE, CELL_SIZE); + int value = grid[i][j]; + if (value != 0) { + g.drawString(String.valueOf(value), j * CELL_SIZE + CELL_SIZE / 2, i * CELL_SIZE + CELL_SIZE / 2); + } } } } } - - -} diff --git a/Main$1.class b/Main$1.class deleted file mode 100644 index 1fcd901..0000000 Binary files a/Main$1.class and /dev/null differ diff --git a/Main.class b/Main.class deleted file mode 100644 index 13f8e89..0000000 Binary files a/Main.class and /dev/null differ diff --git a/Reset.class b/Reset.class deleted file mode 100644 index bba0690..0000000 Binary files a/Reset.class and /dev/null differ diff --git a/Resolve.class b/Resolve.class deleted file mode 100644 index 4e532ce..0000000 Binary files a/Resolve.class and /dev/null differ diff --git a/SudokuDraw.class b/SudokuDraw.class deleted file mode 100644 index bff4ac3..0000000 Binary files a/SudokuDraw.class and /dev/null differ diff --git a/SudokuGenerator.class b/SudokuGenerator.class deleted file mode 100644 index 0511a21..0000000 Binary files a/SudokuGenerator.class and /dev/null differ diff --git a/SudokuPanel.class b/SudokuPanel.class deleted file mode 100644 index 4d692d7..0000000 Binary files a/SudokuPanel.class and /dev/null differ