This commit is contained in:
@@ -26,16 +26,16 @@ public class SudokuSelector {
|
|||||||
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
||||||
private final List<ImBoolean> contraints = new ArrayList<>();
|
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;
|
|
||||||
|
|
||||||
private final ImInt sudokuSize = new ImInt(3);
|
private final ImInt sudokuSize = new ImInt(3);
|
||||||
|
|
||||||
private final ImInt sudokuWidth = new ImInt(3);
|
private final ImInt sudokuWidth = new ImInt(3);
|
||||||
private final ImInt sudokuHeight = new ImInt(3);
|
private final ImInt sudokuHeight = new ImInt(3);
|
||||||
|
|
||||||
public SudokuSelector(boolean canGenEmptyGrid) {
|
private final String confirmMessage;
|
||||||
|
|
||||||
|
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
|
||||||
this.canGenEmptyGrid = canGenEmptyGrid;
|
this.canGenEmptyGrid = canGenEmptyGrid;
|
||||||
|
this.confirmMessage = confirmMessage;
|
||||||
initConstraints();
|
initConstraints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class SudokuSelector {
|
|||||||
switch (currentType.getMakerParamCount()) {
|
switch (currentType.getMakerParamCount()) {
|
||||||
case 1:
|
case 1:
|
||||||
ImGui.inputInt("Taille", sudokuSize);
|
ImGui.inputInt("Taille", sudokuSize);
|
||||||
if (ImGui.button("Résoudre un sudoku")) {
|
if (ImGui.button(confirmMessage)) {
|
||||||
selectSudoku(currentType.createDoku(getConstraints(), sudokuSize.get()), false);
|
selectSudoku(currentType.createDoku(getConstraints(), sudokuSize.get()), false);
|
||||||
}
|
}
|
||||||
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
if (canGenEmptyGrid && ImGui.button("Générer une grille vide")) {
|
||||||
@@ -109,7 +109,7 @@ public class SudokuSelector {
|
|||||||
case 2:
|
case 2:
|
||||||
ImGui.inputInt("Largeur", sudokuHeight);
|
ImGui.inputInt("Largeur", sudokuHeight);
|
||||||
ImGui.inputInt("Longueur", sudokuWidth);
|
ImGui.inputInt("Longueur", sudokuWidth);
|
||||||
if (ImGui.button("Résoudre un sudoku")) {
|
if (ImGui.button(confirmMessage)) {
|
||||||
selectSudoku(currentType.createDoku(getConstraints(), sudokuWidth.get(), sudokuHeight.get()),
|
selectSudoku(currentType.createDoku(getConstraints(), sudokuWidth.get(), sudokuHeight.get()),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
package gui.menu;
|
package gui.menu;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import game.Player;
|
import game.Player;
|
||||||
|
import gui.SudokuSelector;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import network.client.Client;
|
import network.client.Client;
|
||||||
import network.server.Server;
|
import network.server.Server;
|
||||||
import sudoku.constraint.Constraint;
|
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.SudokuFactory;
|
|
||||||
|
|
||||||
public class MultiPlayerView extends BaseView {
|
public class MultiPlayerView extends BaseView {
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
|
|
||||||
|
private final SudokuSelector selector;
|
||||||
|
|
||||||
|
private MultiDoku doku = null;
|
||||||
|
|
||||||
public MultiPlayerView(StateMachine stateMachine, Client client, Server server) {
|
public MultiPlayerView(StateMachine stateMachine, Client client, Server server) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
this.selector = new SudokuSelector(false, "Sélectionner le sudoku");
|
||||||
|
this.selector.onSelect.connect(this::onSelected);
|
||||||
this.client.onDisconnect.connect(this::onDisconnect);
|
this.client.onDisconnect.connect(this::onDisconnect);
|
||||||
this.client.onGameStarted
|
this.client.onGameStarted
|
||||||
.connect(() -> this.stateMachine.pushState(new MultiPlayerDokuView(stateMachine, client, server)));
|
.connect(() -> this.stateMachine.pushState(new MultiPlayerDokuView(stateMachine, client, server)));
|
||||||
@@ -34,15 +37,22 @@ public class MultiPlayerView extends BaseView {
|
|||||||
this.stateMachine.popState();
|
this.stateMachine.popState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onSelected() {
|
||||||
|
this.doku = this.selector.getDoku();
|
||||||
|
}
|
||||||
|
|
||||||
public void renderGameStatus() {
|
public void renderGameStatus() {
|
||||||
if (this.server == null) {
|
if (this.server == null) {
|
||||||
ImGui.text("En attente de l'administrateur du serveur ...");
|
ImGui.text("En attente de l'administrateur du serveur ...");
|
||||||
} else {
|
} else {
|
||||||
|
if (this.doku == null)
|
||||||
|
ImGui.beginDisabled();
|
||||||
if (ImGui.button("Démarrer")) {
|
if (ImGui.button("Démarrer")) {
|
||||||
// temp
|
this.server.startGame(this.doku);
|
||||||
MultiDoku doku = SudokuFactory.createBasicXShapedMultidoku(3, Arrays.asList(Constraint.Diagonal));
|
|
||||||
this.server.startGame(doku);
|
|
||||||
}
|
}
|
||||||
|
if (this.doku == null)
|
||||||
|
ImGui.endDisabled();
|
||||||
|
selector.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class SoloMenu extends BaseView {
|
|||||||
|
|
||||||
public SoloMenu(StateMachine stateMachine) {
|
public SoloMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
this.sudokuSelector = new SudokuSelector(true);
|
this.sudokuSelector = new SudokuSelector(true, "Résoudre le sudoku");
|
||||||
this.sudokuSelector.onSelect.connect(this::pushSudokuState);
|
this.sudokuSelector.onSelect.connect(this::pushSudokuState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user