Browse Source

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

remotes/origin/develop
fdai6040 2 years ago
parent
commit
3747c932f4
  1. 10
      src/main/java/src/GameField.java
  2. 66
      src/main/java/src/MainFrame.java
  3. 2
      src/main/java/src/Model.java
  4. 3
      src/main/java/src/SandboxFrame.java
  5. 5
      src/test/java/ModelTest.java

10
src/main/java/src/GameField.java

@ -122,8 +122,14 @@ public class GameField extends JPanel {
public void setValue(int x, int y, int value) {
JLabel jLabel = gameField[y][x].getjLabel();
jLabel.setText(String.valueOf(value));
jLabel.setVisible(true);
if (value <= 0) {
jLabel.setText("0");
jLabel.setVisible(false);
} else {
jLabel.setText(String.valueOf(value));
jLabel.setVisible(true);
}
}

66
src/main/java/src/MainFrame.java

@ -19,6 +19,8 @@ public class MainFrame extends JFrame {
private JSONArray currentGameDifficulty;
private Model currentModel;
private JLabel currentGameLabel;
private int currentPosition;
public void run() {
@ -79,10 +81,37 @@ public class MainFrame extends JFrame {
JButton back = new JButton();
back.setVisible(true);
back.setBounds(5, 5, 100, 25);
back.setBounds(120, 525, 100, 25);
rootPanel.add(back);
back.setText("Back");
currentGameLabel = new JLabel();
currentGameLabel.setVisible(true);
currentGameLabel.setBounds(250, 525, 40, 25);
currentGameLabel.setText("0/0");
rootPanel.add(currentGameLabel);
JButton next = new JButton();
next.setVisible(true);
next.setBounds(280, 525, 100, 25);
rootPanel.add(next);
next.setText("Next");
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentPosition+1 < currentGameDifficulty.size()) {
currentPosition++;
} else {
currentPosition = 0;
}
JSONObject jsonObject = (JSONObject) currentGameDifficulty.get(currentPosition);
loadDataToGameField(jsonObject);
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JButton newButton = new JButton();
newButton.setVisible(true);
newButton.setBounds(395, 5, 100, 25);
@ -206,11 +235,46 @@ public class MainFrame extends JFrame {
}
currentGameDifficulty = (JSONArray) object.get("easyGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JMenuItem menu_i5=new JMenuItem("Mittel");
menu_i5.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("mediumGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
JMenuItem menu_i6=new JMenuItem("Schwer");
menu_i6.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("hardGame");
loadDataToGameField((JSONObject) currentGameDifficulty.get(0));
currentPosition = 0;
currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size());
}
});
m_menu.add(menu_i1);
m_menu.add(menu_i2);

2
src/main/java/src/Model.java

@ -207,7 +207,7 @@ public class Model {
JSONObject jsonObject = new JSONObject();
jsonObject.put("x", j);
jsonObject.put("y", i);
jsonObject.put("value", getField(i, j));
jsonObject.put("value", getField(j, i));
values.add(jsonObject);
}

3
src/main/java/src/SandboxFrame.java

@ -23,7 +23,6 @@ public class SandboxFrame extends JFrame {
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setupLayout();
}
private void setupLayout() {
@ -58,6 +57,7 @@ public class SandboxFrame extends JFrame {
}
private JButton setupSaveButton() {
JButton save = new JButton("Save");
save.setVisible(true);
@ -72,6 +72,7 @@ public class SandboxFrame extends JFrame {
}
});
return save;
}

5
src/test/java/ModelTest.java

@ -46,6 +46,7 @@ public class ModelTest extends MainFrame {
"8 | 8 8 8 8 8 8 8 8 8\n";
assertEquals(model.toString(), staticCase, "tested Overridden toString of Model.class");
}
@ -247,7 +248,7 @@ public class ModelTest extends MainFrame {
GameField gameField = new GameField(360);
for (int i = 0, k = 13; i < 9; i++) {
for (int j = 0, l = 17; j < 9; j++) {
gameField.setValue(i, j, (i*l+j*k)%9);
gameField.setValue(j, i, (i*l+j*k)%9);
}
}
Model model = new Model(gameField);
@ -273,7 +274,7 @@ public class ModelTest extends MainFrame {
GameField gf = new GameField(360);
for (int i = 0, k = 13; i < 9; i++) {
for (int j = 0, l = 17; j < 9; j++) {
gf.setValue(i, j, (i*l+j*k)%9);
gf.setValue(j, i, (i*l+j*k)%9);
}
}
Model m = new Model(gf);

Loading…
Cancel
Save