This commit is contained in:
@@ -12,36 +12,41 @@ import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import sudoku.Block;
|
||||
import sudoku.Cell;
|
||||
import sudoku.MultiDoku;
|
||||
import sudoku.Sudoku;
|
||||
|
||||
public class SudokuRenderer {
|
||||
|
||||
private final Sudoku sudoku;
|
||||
private final MultiDoku doku;
|
||||
private Sudoku currentSudoku;
|
||||
private int currentIndex = -1;
|
||||
private final Map<Block, Color> colorPalette;
|
||||
|
||||
public SudokuRenderer(Sudoku sudoku) {
|
||||
this.sudoku = sudoku;
|
||||
this.colorPalette = new HashMap<>();
|
||||
initColors();
|
||||
public SudokuRenderer(MultiDoku doku) {
|
||||
this.doku = doku;
|
||||
this.currentSudoku = doku.getSubGrid(0);
|
||||
this.colorPalette = initColors();
|
||||
}
|
||||
|
||||
private void initColors() {
|
||||
List<Color> colors = ColorGenerator.greatPalette(sudoku.getSize());
|
||||
private Map<Block, Color> initColors() {
|
||||
List<Color> colors = ColorGenerator.greatPalette(currentSudoku.getSize());
|
||||
Map<Block, Color> colorPalette = new HashMap<>();
|
||||
int index = 0;
|
||||
for (Block block : sudoku.getBlocks()) {
|
||||
for (Block block : currentSudoku.getBlocks()) {
|
||||
colorPalette.put(block, colors.get(index));
|
||||
index++;
|
||||
}
|
||||
return colorPalette;
|
||||
}
|
||||
|
||||
private void renderPopup() {
|
||||
if (ImGui.beginPopup("editPopup")) {
|
||||
for (int i = 1; i < sudoku.getSize() + 1; i++) {
|
||||
if (i % (int) (Math.sqrt(sudoku.getSize())) != 1)
|
||||
for (int i = 1; i < currentSudoku.getSize() + 1; i++) {
|
||||
if (i % (int) (Math.sqrt(currentSudoku.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);
|
||||
this.currentSudoku.setCellSymbol(currentIndex % currentSudoku.getSize(),
|
||||
currentIndex / currentSudoku.getSize(), i - 1);
|
||||
ImGui.closeCurrentPopup();
|
||||
}
|
||||
}
|
||||
@@ -50,13 +55,12 @@ public class SudokuRenderer {
|
||||
}
|
||||
|
||||
public void render() {
|
||||
ImGui.begin("Sudoku Window");
|
||||
for (int y = 0; y < sudoku.getSize(); y++) {
|
||||
for (int x = 0; x < sudoku.getSize(); x++) {
|
||||
for (int y = 0; y < currentSudoku.getSize(); y++) {
|
||||
for (int x = 0; x < currentSudoku.getSize(); x++) {
|
||||
if (x > 0)
|
||||
ImGui.sameLine();
|
||||
int index = y * sudoku.getSize() + x;
|
||||
Cell cell = sudoku.getCell(x, y);
|
||||
int index = y * currentSudoku.getSize() + x;
|
||||
Cell cell = currentSudoku.getCell(x, y);
|
||||
int symbol = cell.getSymbolIndex();
|
||||
Color blockColor = colorPalette.get(cell.getBlock());
|
||||
ImGui.pushStyleVar(ImGuiStyleVar.SelectableTextAlign, new ImVec2(0.5f, 0.5f));
|
||||
@@ -73,7 +77,6 @@ public class SudokuRenderer {
|
||||
}
|
||||
}
|
||||
renderPopup();
|
||||
ImGui.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,8 +14,14 @@ public abstract class BaseView {
|
||||
|
||||
public void cleanResources() {}
|
||||
|
||||
public void closeMenu(int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
this.stateMachine.popState();
|
||||
}
|
||||
}
|
||||
|
||||
public void closeMenu() {
|
||||
this.stateMachine.popState();
|
||||
closeMenu(1);
|
||||
}
|
||||
|
||||
protected void renderReturnButton() {
|
||||
|
||||
38
app/src/main/java/gui/menu/MultiPlayerDokuView.java
Normal file
38
app/src/main/java/gui/menu/MultiPlayerDokuView.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package gui.menu;
|
||||
|
||||
import gui.SudokuRenderer;
|
||||
import imgui.ImGui;
|
||||
import network.client.Client;
|
||||
import network.server.Server;
|
||||
import sudoku.MultiDoku;
|
||||
|
||||
public class MultiPlayerDokuView extends BaseView{
|
||||
|
||||
private final Client client;
|
||||
private final Server server;
|
||||
private final SudokuRenderer sudokuRenderer;
|
||||
|
||||
public MultiPlayerDokuView(StateMachine stateMachine, Client client, Server server) {
|
||||
super(stateMachine);
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.sudokuRenderer = new SudokuRenderer(this.client.getGame().getDoku());
|
||||
this.client.onDisconnect.connect(this::onDisconnect);
|
||||
}
|
||||
|
||||
public void onDisconnect() {
|
||||
if (server == null) {
|
||||
closeMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
this.sudokuRenderer.render();
|
||||
if (ImGui.button("Quitter")) {
|
||||
this.client.stop();
|
||||
this.closeMenu(3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import game.Player;
|
||||
import imgui.ImGui;
|
||||
import network.client.Client;
|
||||
import network.server.Server;
|
||||
import sudoku.MultiDoku;
|
||||
import sudoku.SudokuFactory;
|
||||
|
||||
public class MultiPlayerView extends BaseView {
|
||||
|
||||
@@ -15,6 +17,7 @@ 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)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,7 +35,9 @@ public class MultiPlayerView extends BaseView {
|
||||
ImGui.text("En attente de l'administrateur du serveur ...");
|
||||
} else {
|
||||
if (ImGui.button("Démarrer")) {
|
||||
// start the game
|
||||
// temp
|
||||
MultiDoku doku = SudokuFactory.createBasicEmptySquareSudoku(5);
|
||||
this.server.startGame(doku);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user