This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user