Browse Source

Merge remote-tracking branch 'origin/develop' into develop

remotes/origin/develop
fdai6040 2 years ago
parent
commit
d2d33a3df0
  1. 70
      src/main/java/src/Model.java
  2. 2
      src/main/java/src/sudoku.json

70
src/main/java/src/Model.java

@ -100,7 +100,6 @@ public class Model {
public static String loadAllData() {
File file = new File("src/main/java/src/sudoku.json");
if (file.exists()) {
@ -110,6 +109,7 @@ public class Model {
throw new RuntimeException(e);
}
}
String line = "";
try {
Scanner scanner = new Scanner(file);
@ -120,6 +120,22 @@ public class Model {
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
if (line.equals("")) {
initJsonFile();
}
line = "";
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
line = line + scanner.nextLine();
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return line;
}
@ -155,18 +171,6 @@ public class Model {
}
}
public void loadNewMedium() {
}
public void loadNewHard() {
}
public void safeNewSandboxGame() {
}
@Override
public String toString() {
@ -350,8 +354,46 @@ public class Model {
}
public void createNewGame(String difficulty) {
JSONObject jsonObject = modelToJson();
JSONObject myNewGame = modelToJson();
String s = loadAllData();
JSONObject object = null;
try {
object = (JSONObject) new JSONParser().parse(s);
} catch (ParseException e) {
throw new RuntimeException(e);
}
JSONArray easyArray = (JSONArray) object.get("easyGame");
JSONArray mediumArray = (JSONArray) object.get("mediumGame");
JSONArray hardArray = (JSONArray) object.get("hardGame");
System.out.println();
if (difficulty.equals("easy")) {
easyArray.add(myNewGame);
} else if (difficulty.equals("medium")) {
mediumArray.add(myNewGame);
} else if (difficulty.equals("hard")) {
hardArray.add(myNewGame);
}
String jsonString = object.toJSONString();
try {
FileWriter writer = new FileWriter("src/main/java/src/sudoku.json");
writer.write(jsonString);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

2
src/main/java/src/sudoku.json
File diff suppressed because it is too large
View File

Loading…
Cancel
Save