Browse Source

load a easy game to the gamefield

remotes/origin/develop
fdai6499 2 years ago
parent
commit
f7eff66f44
  1. 29
      src/main/java/src/MainFrame.java
  2. 1
      src/main/java/src/Model.java
  3. 2
      src/main/java/src/sudoku.json

29
src/main/java/src/MainFrame.java

@ -1,5 +1,10 @@
package src;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
@ -12,6 +17,9 @@ public class MainFrame extends JFrame {
private GameField gameField;
private JSONArray currentGameDifficulty;
private Model currentModel;
public void run() {
this.setLayout(null);
@ -36,7 +44,6 @@ public class MainFrame extends JFrame {
gameField.setBounds(70, 50, 360, 360);
rootPanel.add(gameField);
int j = 0;
JPanel boxPanel = setupJPanel();
@ -138,7 +145,6 @@ public class MainFrame extends JFrame {
return jPanel;
}
public JPanel setupJPanel() {
JPanel panel = new JPanel();
panel.setBounds(100, 450, 300, 30);
@ -173,6 +179,10 @@ public class MainFrame extends JFrame {
return jPanel;
}
private void loadDataToGameField(JSONObject jsonObject) {
currentModel = new Model(jsonObject, gameField);
}
private JMenuBar setupMenuBar() {
JMenuBar menu_mb=new JMenuBar();
@ -184,6 +194,21 @@ public class MainFrame extends JFrame {
JMenuItem menu_i1=new JMenuItem("Nochmal");
JMenuItem menu_i2=new JMenuItem("Tipp");
JMenuItem menu_i4=new JMenuItem("Einfach");
menu_i4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String data = Model.loadAllData();
JSONObject object = null;
try {
object = (JSONObject)new JSONParser().parse(data);
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
currentGameDifficulty = (JSONArray) object.get("easyGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
}
});
JMenuItem menu_i5=new JMenuItem("Mittel");
JMenuItem menu_i6=new JMenuItem("Schwer");

1
src/main/java/src/Model.java

@ -370,6 +370,7 @@ public class Model {
JSONArray mediumArray = (JSONArray) object.get("mediumGame");
JSONArray hardArray = (JSONArray) object.get("hardGame");
System.out.println();
if (difficulty.equals("easy")) {

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

Loading…
Cancel
Save