feat: dynamic constraints (Fixes #8)
All checks were successful
Linux arm64 / Build (push) Successful in 37s
All checks were successful
Linux arm64 / Build (push) Successful in 37s
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import common.Signal;
|
||||
import gui.ColorGenerator.Color;
|
||||
@@ -11,10 +13,11 @@ import imgui.ImVec2;
|
||||
import imgui.ImVec4;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.structure.Block;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class SudokuRenderer {
|
||||
|
||||
@@ -24,13 +27,28 @@ public class SudokuRenderer {
|
||||
|
||||
private static final ImVec4 BLACK = new ImVec4(0, 0, 0, 1);
|
||||
private static final ImVec4 TRANSPARENT = new ImVec4();
|
||||
private static final ImVec4 WHITE = new ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
private static final ImVec2 cellSize = new ImVec2(50, 50);
|
||||
|
||||
private final Set<Cell> diagonals = new HashSet<>();
|
||||
|
||||
public final Signal onResolve = new Signal();
|
||||
|
||||
public SudokuRenderer(MultiDoku doku) {
|
||||
this.doku = RenderableMultidoku.fromMultidoku(doku);
|
||||
this.colorPalette = initColors();
|
||||
initDiagonals();
|
||||
}
|
||||
|
||||
private void initDiagonals() {
|
||||
for (Sudoku sudoku : this.doku.getDoku().getSubGrids()) {
|
||||
if (sudoku.hasConstraint(Constraint.Diagonal)) {
|
||||
for (int i = 0; i < sudoku.getSize(); i++) {
|
||||
this.diagonals.add(sudoku.getCell(i, i));
|
||||
this.diagonals.add(sudoku.getCell(sudoku.getSize() - i - 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Block, Color> initColors() {
|
||||
@@ -92,12 +110,15 @@ public class SudokuRenderer {
|
||||
ImGui.pushStyleColor(ImGuiCol.Button, TRANSPARENT);
|
||||
ImGui.button("##" + index, cellSize);
|
||||
} else {
|
||||
ImGui.pushStyleColor(ImGuiCol.Border, BLACK);
|
||||
if (diagonals.contains(cell)) {
|
||||
ImGui.pushStyleColor(ImGuiCol.Border, WHITE);
|
||||
} else {
|
||||
ImGui.pushStyleColor(ImGuiCol.Border, BLACK);
|
||||
}
|
||||
int symbol = cell.getSymbolIndex();
|
||||
Color blockColor = colorPalette.get(cell.getBlock());
|
||||
if (!cell.isMutable()) {
|
||||
blockColor = new Color(blockColor.r - 0.20f, blockColor.g - 0.20f, blockColor.b - 0.20f);
|
||||
} else {
|
||||
}
|
||||
ImGui.pushStyleColor(ImGuiCol.Button, new ImVec4(blockColor.r, blockColor.g, blockColor.b, 1.0f));
|
||||
String cellText = "";
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import common.Signal;
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.imguifiledialog.ImGuiFileDialog;
|
||||
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
|
||||
import imgui.type.ImBoolean;
|
||||
import imgui.type.ImInt;
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
@@ -19,7 +24,7 @@ public class SudokuSelector {
|
||||
private final ImInt sudokuType = new ImInt(0);
|
||||
|
||||
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
||||
private final String[] difficulties;
|
||||
private final List<ImBoolean> contraints = new ArrayList<>();
|
||||
|
||||
private static final String[] sudokuTypes = { "Carré", "Rectangle", "Multidoku" };
|
||||
private static final int SQUARE = 0, RECTANGLE = 1, MULTIDOKU = 2;
|
||||
@@ -31,10 +36,21 @@ public class SudokuSelector {
|
||||
|
||||
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();
|
||||
initConstraints();
|
||||
}
|
||||
|
||||
private List<Constraint> getConstraints() {
|
||||
List<Constraint> constraints = new ArrayList<>();
|
||||
for (int i = 0; i < this.contraints.size(); i++) {
|
||||
if (this.contraints.get(i).get())
|
||||
constraints.add(Constraint.values()[i]);
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
private void initConstraints() {
|
||||
for (Constraint cons : Constraint.values()) {
|
||||
contraints.add(new ImBoolean(SudokuFactory.DEFAULT_CONSTRAINTS.contains(cons)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,15 +87,21 @@ public class SudokuSelector {
|
||||
|
||||
public void render() {
|
||||
ImGui.combo("Type de Sudoku", sudokuType, sudokuTypes);
|
||||
ImGui.combo("Difficulté", difficulty, difficulties);
|
||||
ImGui.combo("Difficulté", difficulty, Difficulty.getDifficultyNames());
|
||||
if (ImGui.treeNode("Constraintes")) {
|
||||
for (Constraint cons : Constraint.values()) {
|
||||
ImGui.checkbox(cons.getDisplayName(), contraints.get(cons.ordinal()));
|
||||
}
|
||||
ImGui.treePop();
|
||||
}
|
||||
switch (sudokuType.get()) {
|
||||
case SQUARE:
|
||||
ImGui.inputInt("Taille", sudokuSize);
|
||||
if (ImGui.button("Résoudre un sudoku")) {
|
||||
selectSudoku(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), false);
|
||||
selectSudoku(SudokuFactory.createBasicEmptySquareDoku(sudokuSize.get(), getConstraints()), false);
|
||||
}
|
||||
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||
selectSudoku(SudokuFactory.createBasicEmptySquareSudoku(sudokuSize.get()), true);
|
||||
selectSudoku(SudokuFactory.createBasicEmptySquareDoku(sudokuSize.get(), getConstraints()), true);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -88,22 +110,25 @@ public class SudokuSelector {
|
||||
ImGui.inputInt("Longueur", sudokuWidth);
|
||||
if (ImGui.button("Résoudre un sudoku")) {
|
||||
selectSudoku(
|
||||
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()),
|
||||
SudokuFactory.createBasicEmptyRectangleDoku(sudokuWidth.get(), sudokuHeight.get(),
|
||||
getConstraints()),
|
||||
false);
|
||||
}
|
||||
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||
selectSudoku(
|
||||
SudokuFactory.createBasicEmptyRectangleSudoku(sudokuWidth.get(), sudokuHeight.get()), true);
|
||||
SudokuFactory.createBasicEmptyRectangleDoku(sudokuWidth.get(), sudokuHeight.get(),
|
||||
getConstraints()),
|
||||
true);
|
||||
}
|
||||
break;
|
||||
|
||||
case MULTIDOKU:
|
||||
ImGui.inputInt("Taille", sudokuSize);
|
||||
if (ImGui.button("Résoudre un sudoku")) {
|
||||
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), false);
|
||||
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get(), getConstraints()), false);
|
||||
}
|
||||
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get()), true);
|
||||
selectSudoku(SudokuFactory.createBasicXShapedMultidoku(sudokuSize.get(), getConstraints()), true);
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
@@ -17,7 +17,8 @@ public class MultiPlayerView extends BaseView {
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.client.onDisconnect.connect(this::onDisconnect);
|
||||
this.client.onGameStarted.connect(() -> this.stateMachine.pushState(new MultiPlayerDokuView(stateMachine, client, server)));
|
||||
this.client.onGameStarted
|
||||
.connect(() -> this.stateMachine.pushState(new MultiPlayerDokuView(stateMachine, client, server)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +37,7 @@ public class MultiPlayerView extends BaseView {
|
||||
} else {
|
||||
if (ImGui.button("Démarrer")) {
|
||||
// temp
|
||||
MultiDoku doku = SudokuFactory.createBasicXShapedMultidoku(3);
|
||||
MultiDoku doku = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
this.server.startGame(doku);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user