This commit is contained in:
@@ -11,6 +11,7 @@ import imgui.ImVec2;
|
||||
import imgui.ImVec4;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import sudoku.solver.Solver;
|
||||
import sudoku.structure.Block;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -19,34 +20,34 @@ import sudoku.structure.SudokuFactory;
|
||||
|
||||
public class SudokuView extends BaseView {
|
||||
|
||||
private final Sudoku sudoku;
|
||||
private final MultiDoku doku;
|
||||
private int currentIndex = -1;
|
||||
private final Map<Block, Color> colorPalette;
|
||||
|
||||
public SudokuView(StateMachine stateMachine, int width, int height) {
|
||||
super(stateMachine);
|
||||
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleSudoku(width, height);
|
||||
this.sudoku = doku.getSubGrid(0);
|
||||
this.doku = SudokuFactory.createBasicEmptyRectangleSudoku(width, height);
|
||||
this.colorPalette = new HashMap<>();
|
||||
initColors();
|
||||
}
|
||||
|
||||
private void initColors() {
|
||||
List<Color> colors = ColorGenerator.greatPalette(sudoku.getSize());
|
||||
List<Color> colors = ColorGenerator.greatPalette(doku.getSubGrid(0).getSize());
|
||||
int index = 0;
|
||||
for (Block block : sudoku.getBlocks()) {
|
||||
for (Block block : doku.getSubGrid(0).getBlocks()) {
|
||||
colorPalette.put(block, colors.get(index));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPopup() {
|
||||
final Sudoku sudoku = doku.getSubGrid(0);
|
||||
if (ImGui.beginPopup("editPopup")) {
|
||||
for (int i = 1; i < sudoku.getSize() + 1; i++) {
|
||||
if (i % (int) (Math.sqrt(sudoku.getSize())) != 1)
|
||||
ImGui.sameLine();
|
||||
if (ImGui.button(Integer.toString(i), new ImVec2(50, 50))) {
|
||||
this.sudoku.setCellSymbol(currentIndex % sudoku.getSize(), currentIndex / sudoku.getSize(), i - 1);
|
||||
sudoku.setCellSymbol(currentIndex % sudoku.getSize(), currentIndex / sudoku.getSize(), i - 1);
|
||||
ImGui.closeCurrentPopup();
|
||||
}
|
||||
}
|
||||
@@ -56,6 +57,7 @@ public class SudokuView extends BaseView {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final Sudoku sudoku = doku.getSubGrid(0);
|
||||
for (int y = 0; y < sudoku.getSize(); y++) {
|
||||
for (int x = 0; x < sudoku.getSize(); x++) {
|
||||
if (x > 0)
|
||||
@@ -79,7 +81,7 @@ public class SudokuView extends BaseView {
|
||||
}
|
||||
renderPopup();
|
||||
if (ImGui.button("Résoudre")) {
|
||||
// TODO: solve
|
||||
Solver.solve(doku);
|
||||
}
|
||||
renderReturnButton();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user