Fix #4
All checks were successful
Linux arm64 / Build (push) Successful in 38s

This commit is contained in:
2025-01-29 18:32:50 +01:00
parent c16f2b8f5a
commit ff85cbef01
2 changed files with 21 additions and 2 deletions

View File

@@ -1,9 +1,12 @@
package gui.menu;
import java.util.Arrays;
import game.Player;
import imgui.ImGui;
import network.client.Client;
import network.server.Server;
import sudoku.constraint.Constraint;
import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
@@ -37,7 +40,7 @@ public class MultiPlayerView extends BaseView {
} else {
if (ImGui.button("Démarrer")) {
// temp
MultiDoku doku = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
MultiDoku doku = SudokuFactory.createBasicXShapedMultidoku(3, Arrays.asList(Constraint.Diagonal));
this.server.startGame(doku);
}
}

View File

@@ -10,6 +10,7 @@ import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import sudoku.constraint.Constraint;
import sudoku.structure.Block;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
@@ -73,6 +74,7 @@ public class SudokuSerializer {
JSONObject jsonSudoku = new JSONObject();
JSONArray cellsJsonArray = new JSONArray();
JSONArray blocksJsonArray = new JSONArray();
JSONArray constraintsJsonArray = new JSONArray();
Sudoku sudoku = multidoku.getSubGrid(i);
@@ -90,6 +92,13 @@ public class SudokuSerializer {
blocksJsonArray.put(blockID);
}
// serialize constraints
for (Constraint cons : sudoku.getConstraints()) {
constraintsJsonArray.put(cons.ordinal());
}
jsonSudoku.put("constraints", constraintsJsonArray);
jsonSudoku.put("cells", cellsJsonArray);
jsonSudoku.put("blocks", blocksJsonArray);
jsonSudoku.put("blockWidth", sudoku.getBlockWidth());
@@ -211,9 +220,11 @@ public class SudokuSerializer {
JSONObject sudokuJsonObject = multidokuJsonObject.getJSONObject(i);
JSONArray sudokuCellsJsonArray = sudokuJsonObject.getJSONArray("cells");
JSONArray sudokuBlocksJsonArray = sudokuJsonObject.getJSONArray("blocks");
JSONArray sudokuConstraintsJsonArray = sudokuJsonObject.getJSONArray("constraints");
List<Cell> sudokuCells = new ArrayList<>();
List<Block> sudokuBlocks = new ArrayList<>();
List<Constraint> sudokuConstraints = new ArrayList<>();
for (int j = 0; j < sudokuCellsJsonArray.length(); j++) {
int cellID = sudokuCellsJsonArray.getInt(j);
@@ -225,7 +236,12 @@ public class SudokuSerializer {
sudokuBlocks.add(blocks.get(blockID));
}
Sudoku s = new Sudoku(sudokuCells, sudokuBlocks, SudokuFactory.DEFAULT_CONSTRAINTS);
for (int j = 0; j < sudokuConstraintsJsonArray.length(); j++) {
int constraintID = sudokuConstraintsJsonArray.getInt(j);
sudokuConstraints.add(Constraint.values()[constraintID]);
}
Sudoku s = new Sudoku(sudokuCells, sudokuBlocks, sudokuConstraints);
s.setBlockWidth(sudokuJsonObject.getInt("blockWidth"));
sudokus.add(s);
}