|
|
@ -14,6 +14,20 @@ public class Model { |
|
|
|
public int difficulty; |
|
|
|
private GameField gameField; |
|
|
|
|
|
|
|
public Model(JSONObject mock, GameField gameField) { |
|
|
|
|
|
|
|
this.gameField = gameField; |
|
|
|
|
|
|
|
model = new int[SIZE][]; |
|
|
|
|
|
|
|
for (int i = 0; i < SIZE; i++) { |
|
|
|
model[i] = new int[SIZE]; |
|
|
|
} |
|
|
|
|
|
|
|
jsonToModel(mock); |
|
|
|
modelToGameField(); |
|
|
|
} |
|
|
|
|
|
|
|
public int getDifficulty() { |
|
|
|
return difficulty; |
|
|
|
} |
|
|
@ -141,4 +155,29 @@ public class Model { |
|
|
|
|
|
|
|
return game; |
|
|
|
} |
|
|
|
|
|
|
|
public void jsonToModel(JSONObject jsonObject) { |
|
|
|
|
|
|
|
JSONArray values = (JSONArray) jsonObject.get("values"); |
|
|
|
|
|
|
|
Iterator iterator = values.iterator(); |
|
|
|
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
|
|
|
JSONObject next = (JSONObject) iterator.next(); |
|
|
|
int x = (int) next.get("x"); |
|
|
|
int y = (int) next.get("y"); |
|
|
|
int value = (int) next.get("value"); |
|
|
|
|
|
|
|
setField(x, y, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void modelToGameField() { |
|
|
|
for (int i = 0; i < 9; i++) { |
|
|
|
for (int j = 0; j < 9; j++) { |
|
|
|
gameField.setValue(i, j, getField(i, j)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |