Browse Source

it is possible now to load an easy game from file to the model and testing this

remotes/origin/develop
fdai6499 2 years ago
parent
commit
1ec161933c
  1. 34
      src/main/java/src/Model.java
  2. 6
      src/test/java/ModelTest.java

34
src/main/java/src/Model.java

@ -14,6 +14,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class Model {
private static int SIZE = 9;
@ -40,6 +42,7 @@ public class Model {
return difficulty;
}
//1=easy, 2=medium, 3=hard
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
@ -121,15 +124,35 @@ public class Model {
}
public void loadNewEasy() {
String s = loadAllData();
JSONParser jsonParser = new JSONParser();
public void loadNewEasy(int p) {
String data = Model.loadAllData();
setDifficulty(1);
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
JSONObject parse = (JSONObject) jsonParser.parse(s);
jsonObject = (JSONObject) parser.parse(data);
} catch (ParseException e) {
throw new RuntimeException(e);
assertTrue(false, "parsing went wrong");
}
try {
JSONArray easyGame = (JSONArray) jsonObject.get("easyGame");
JSONObject jsonObjectEasyGame = (JSONObject) easyGame.get(p);
// Model modelEasy = new Model(jsonObjectEasyGame, new GameField(360));
// System.out.println(modelEasy);
jsonToModel(jsonObjectEasyGame);
} catch (IndexOutOfBoundsException e) {
throw e;
}
}
public void loadNewMedium() {
@ -301,7 +324,6 @@ public class Model {
JSONArray jsonArrayHard = new JSONArray();
jsonArrayHard.add(jsonObjectHard);
jsonObjectRoot.put("easyGame", jsonArrayEasy);
jsonObjectRoot.put("mediumGame", jsonArrayMedium);
jsonObjectRoot.put("hardGame", jsonArrayHard);

6
src/test/java/ModelTest.java

@ -217,7 +217,11 @@ public class ModelTest extends MainFrame {
@Test
public void test_loadNewEasy() {
GameField gameField = new GameField(360);
Model model = new Model(new GameField(360));
model.loadNewEasy(0);
int field = model.getField(0, 0);
assertEquals(1, field, "the first game has a 1 at (0,0)");
System.out.println(model);
}
@Test

Loading…
Cancel
Save