Compare commits
3 Commits
a10d2eda9a
...
a616ab63e4
| Author | SHA1 | Date | |
|---|---|---|---|
| a616ab63e4 | |||
| 00866256a7 | |||
| ed9b636b58 |
@@ -77,7 +77,7 @@ public class SudokuRenderer {
|
|||||||
if (offsetX > 0) {
|
if (offsetX > 0) {
|
||||||
ImGui.setCursorPosX(offsetX);
|
ImGui.setCursorPosX(offsetX);
|
||||||
}
|
}
|
||||||
ImGui.beginChild(1, new ImVec2(cellSize.x * doku.getWidth(), cellSize.y * doku.getHeight()), ImGuiWindowFlags.HorizontalScrollbar);
|
ImGui.beginChild(1, new ImVec2(cellSize.x * doku.getWidth(), cellSize.y * doku.getHeight()));
|
||||||
|
|
||||||
ImGui.pushStyleVar(ImGuiStyleVar.FrameBorderSize, 2.0f);
|
ImGui.pushStyleVar(ImGuiStyleVar.FrameBorderSize, 2.0f);
|
||||||
ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, new ImVec2(0.0f, 0.0f));
|
ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, new ImVec2(0.0f, 0.0f));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.concurrent.CancellationException;
|
|||||||
import gui.SudokuRenderer;
|
import gui.SudokuRenderer;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.ImGuiStyle;
|
import imgui.ImGuiStyle;
|
||||||
|
import sudoku.io.SudokuSerializer;
|
||||||
import sudoku.solver.Solver;
|
import sudoku.solver.Solver;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ public class SudokuView extends BaseView {
|
|||||||
private final SudokuRenderer sudokuRenderer;
|
private final SudokuRenderer sudokuRenderer;
|
||||||
private Thread resolveThread;
|
private Thread resolveThread;
|
||||||
private final MultiDoku doku;
|
private final MultiDoku doku;
|
||||||
|
private String lastSavePath = null;
|
||||||
|
|
||||||
private boolean resolved = false;
|
private boolean resolved = false;
|
||||||
|
|
||||||
@@ -94,10 +96,23 @@ public class SudokuView extends BaseView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renderSaveButton() {
|
||||||
|
if (ImGui.button("Sauvegarder l'état de la grille")) {
|
||||||
|
lastSavePath = SudokuSerializer.saveMultiDoku(doku);
|
||||||
|
ImGui.openPopup("saveDone");
|
||||||
|
}
|
||||||
|
if (ImGui.beginPopup("saveDone")) {
|
||||||
|
ImGui.text("Sudoku sauvegardé dans ");
|
||||||
|
ImGui.text(lastSavePath);
|
||||||
|
ImGui.endPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
sudokuRenderer.render();
|
sudokuRenderer.render();
|
||||||
renderSolveButton();
|
renderSolveButton();
|
||||||
|
renderSaveButton();
|
||||||
renderCancelButton();
|
renderCancelButton();
|
||||||
renderReturnButton();
|
renderReturnButton();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ public class SudokuSerializer {
|
|||||||
/**
|
/**
|
||||||
* Save a serialized MultiDoku in a JSON file.
|
* Save a serialized MultiDoku in a JSON file.
|
||||||
* @param doku MultiDoku, MultiDoku to save.
|
* @param doku MultiDoku, MultiDoku to save.
|
||||||
* @return int, number of the save.
|
* @return String, the path of the save.
|
||||||
*/
|
*/
|
||||||
public static int saveMultiDoku(final MultiDoku doku) {
|
public static String saveMultiDoku(final MultiDoku doku) {
|
||||||
|
|
||||||
JSONObject jsonRoot = serializeSudoku(doku);
|
JSONObject jsonRoot = serializeSudoku(doku);
|
||||||
|
|
||||||
@@ -123,9 +123,9 @@ public class SudokuSerializer {
|
|||||||
try (FileWriter file = new FileWriter(f)) {
|
try (FileWriter file = new FileWriter(f)) {
|
||||||
file.write(jsonRoot.toString(3));
|
file.write(jsonRoot.toString(3));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.fillInStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return i;
|
return f.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import java.util.Random;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import sudoku.io.SudokuPrinter;
|
|
||||||
import sudoku.io.SudokuSerializer;
|
import sudoku.io.SudokuSerializer;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.SudokuFactory;
|
import sudoku.structure.SudokuFactory;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class SudokuSerializerTest {
|
public class SudokuSerializerTest {
|
||||||
|
|
||||||
void testSerializeWithSize(int blockWidth, int blockHeight) {
|
void testSerializeWithSize(int blockWidth, int blockHeight) {
|
||||||
@@ -24,10 +20,10 @@ public class SudokuSerializerTest {
|
|||||||
|
|
||||||
void testSaveWithSize(int blockWidth, int blockHeight) {
|
void testSaveWithSize(int blockWidth, int blockHeight) {
|
||||||
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||||
int saveNumber = SudokuSerializer.saveMultiDoku(doku);
|
String savePath = SudokuSerializer.saveMultiDoku(doku);
|
||||||
MultiDoku otherDoku = null;
|
MultiDoku otherDoku = null;
|
||||||
try {
|
try {
|
||||||
otherDoku = SudokuSerializer.getSavedMultiDoku(saveNumber);
|
otherDoku = SudokuFactory.fromfile(savePath);
|
||||||
assert (otherDoku != null);
|
assert (otherDoku != null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -41,18 +37,15 @@ public class SudokuSerializerTest {
|
|||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
int testCount = 5;
|
int testCount = 5;
|
||||||
for (int i = 0; i < testCount; i++) {
|
for (int i = 0; i < testCount; i++) {
|
||||||
int blockWidth = r.nextInt(20) + 1;
|
int blockWidth = r.nextInt(10) + 1;
|
||||||
int blockHeight = r.nextInt(20) + 1;
|
int blockHeight = r.nextInt(10) + 1;
|
||||||
testSerializeWithSize(blockWidth, blockHeight);
|
testSerializeWithSize(blockWidth, blockHeight);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < testCount; i++) {
|
for (int i = 0; i < testCount; i++) {
|
||||||
int blockWidth = r.nextInt(20) + 1;
|
int blockWidth = r.nextInt(10) + 1;
|
||||||
int blockHeight = r.nextInt(20) + 1;
|
int blockHeight = r.nextInt(10) + 1;
|
||||||
testSaveWithSize(blockWidth, blockHeight);
|
testSaveWithSize(blockWidth, blockHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user