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