This commit is contained in:
97
app/src/main/java/gui/SudokuSelector.java
Normal file
97
app/src/main/java/gui/SudokuSelector.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
import common.Signal;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImInt;
|
||||||
|
import sudoku.structure.Difficulty;
|
||||||
|
import sudoku.structure.MultiDoku;
|
||||||
|
import sudoku.structure.SudokuFactory;
|
||||||
|
|
||||||
|
public class SudokuSelector {
|
||||||
|
|
||||||
|
public final Signal onSelect = new Signal();
|
||||||
|
private MultiDoku doku;
|
||||||
|
|
||||||
|
private final boolean canGenEmptyGrid;
|
||||||
|
|
||||||
|
private final ImInt sudokuType = new ImInt(0);
|
||||||
|
|
||||||
|
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
||||||
|
private final String[] difficulties;
|
||||||
|
|
||||||
|
private static final String[] sudokuTypes = { "Carré", "Rectangle", "Multidoku" };
|
||||||
|
private static final int SQUARE = 0, RECTANGLE = 1, MULTIDOKU = 2;
|
||||||
|
|
||||||
|
private final ImInt sudokuSize = new ImInt(3);
|
||||||
|
|
||||||
|
private final ImInt sudokuWidth = new ImInt(3);
|
||||||
|
private final ImInt sudokuHeight = new ImInt(3);
|
||||||
|
|
||||||
|
public SudokuSelector(boolean canGenEmptyGrid) {
|
||||||
|
this.canGenEmptyGrid = canGenEmptyGrid;
|
||||||
|
Difficulty[] diffs = Difficulty.values();
|
||||||
|
difficulties = new String[diffs.length];
|
||||||
|
for (int i = 0; i < diffs.length; i++) {
|
||||||
|
difficulties[i] = diffs[i].getDisplayName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectSudoku(MultiDoku doku, boolean empty) {
|
||||||
|
this.doku = doku;
|
||||||
|
if (!empty) {
|
||||||
|
try {
|
||||||
|
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.onSelect.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render() {
|
||||||
|
ImGui.combo("Type de Sudoku", sudokuType, sudokuTypes);
|
||||||
|
ImGui.combo("Difficulté", difficulty, difficulties);
|
||||||
|
switch (sudokuType.get()) {
|
||||||
|
case SQUARE:
|
||||||
|
ImGui.inputInt("Taille", sudokuSize);
|
||||||
|
if (ImGui.button("Résoudre un sudoku")) {
|
||||||
|
selectSudoku(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), false);
|
||||||
|
}
|
||||||
|
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||||
|
selectSudoku(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RECTANGLE:
|
||||||
|
ImGui.inputInt("Largeur", sudokuHeight);
|
||||||
|
ImGui.inputInt("Longueur", sudokuWidth);
|
||||||
|
if (ImGui.button("Résoudre un sudoku")) {
|
||||||
|
selectSudoku(
|
||||||
|
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||||
|
selectSudoku(
|
||||||
|
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()), true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MULTIDOKU:
|
||||||
|
ImGui.inputInt("Taille", sudokuSize);
|
||||||
|
if (ImGui.button("Résoudre un sudoku")) {
|
||||||
|
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), false);
|
||||||
|
}
|
||||||
|
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||||
|
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiDoku getDoku() {
|
||||||
|
return doku;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,88 +1,26 @@
|
|||||||
package gui.menu;
|
package gui.menu;
|
||||||
|
|
||||||
|
import gui.SudokuSelector;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImInt;
|
|
||||||
import sudoku.structure.Difficulty;
|
|
||||||
import sudoku.structure.MultiDoku;
|
|
||||||
import sudoku.structure.SudokuFactory;
|
|
||||||
|
|
||||||
public class SoloMenu extends BaseView {
|
public class SoloMenu extends BaseView {
|
||||||
|
|
||||||
private final ImInt sudokuType = new ImInt(0);
|
private final SudokuSelector sudokuSelector;
|
||||||
|
|
||||||
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
|
||||||
private final String[] difficulties;
|
|
||||||
|
|
||||||
private static final String[] sudokuTypes = { "Carré", "Rectangle", "Multidoku" };
|
|
||||||
private static final int SQUARE = 0, RECTANGLE = 1, MULTIDOKU = 2;
|
|
||||||
|
|
||||||
private final ImInt sudokuSize = new ImInt(3);
|
|
||||||
|
|
||||||
private final ImInt sudokuWidth = new ImInt(3);
|
|
||||||
private final ImInt sudokuHeight = new ImInt(3);
|
|
||||||
|
|
||||||
public SoloMenu(StateMachine stateMachine) {
|
public SoloMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
Difficulty[] diffs = Difficulty.values();
|
this.sudokuSelector = new SudokuSelector(true);
|
||||||
difficulties = new String[diffs.length];
|
this.sudokuSelector.onSelect.connect(this::pushSudokuState);
|
||||||
for (int i = 0; i < diffs.length; i++) {
|
|
||||||
difficulties[i] = diffs[i].getDisplayName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushSudokuState(MultiDoku doku, boolean empty) {
|
private void pushSudokuState() {
|
||||||
if (!empty) {
|
this.stateMachine.pushState(new SudokuView(stateMachine, this.sudokuSelector.getDoku()));
|
||||||
try {
|
|
||||||
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.stateMachine.pushState(new SudokuView(stateMachine, doku));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
ImGui.text("Solo");
|
ImGui.text("Solo");
|
||||||
ImGui.combo("Type de Sudoku", sudokuType, sudokuTypes);
|
sudokuSelector.render();
|
||||||
ImGui.combo("Difficulté", difficulty, difficulties);
|
|
||||||
switch (sudokuType.get()) {
|
|
||||||
case SQUARE:
|
|
||||||
ImGui.inputInt("Taille", sudokuSize);
|
|
||||||
if (ImGui.button("Résoudre un sudoku")) {
|
|
||||||
pushSudokuState(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), false);
|
|
||||||
}
|
|
||||||
if (ImGui.button("Générer une grille vide")) {
|
|
||||||
pushSudokuState(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RECTANGLE:
|
|
||||||
ImGui.inputInt("Largeur", sudokuHeight);
|
|
||||||
ImGui.inputInt("Longueur", sudokuWidth);
|
|
||||||
if (ImGui.button("Résoudre un sudoku")) {
|
|
||||||
pushSudokuState(
|
|
||||||
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
if (ImGui.button("Générer une grille vide")) {
|
|
||||||
pushSudokuState(
|
|
||||||
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()), true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MULTIDOKU:
|
|
||||||
ImGui.inputInt("Taille", sudokuSize);
|
|
||||||
if (ImGui.button("Résoudre un sudoku")) {
|
|
||||||
pushSudokuState(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), false);
|
|
||||||
}
|
|
||||||
if (ImGui.button("Générer une grille vide")) {
|
|
||||||
pushSudokuState(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
renderReturnButton();
|
renderReturnButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public class SudokuSerializer {
|
|||||||
for (Cell cell : sudoku.getCells()) {
|
for (Cell cell : sudoku.getCells()) {
|
||||||
if (!cellIds.contains(cell)) {
|
if (!cellIds.contains(cell)) {
|
||||||
cellIds.add(cell);
|
cellIds.add(cell);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Block block = cell.getBlock();
|
Block block = cell.getBlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user