Browse Source

Added shoot() function to panel click for general game loop

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
a42df0aac2
  1. 53
      src/main/java/de/tims/fleetstorm/gui/GameLogic.java

53
src/main/java/de/tims/fleetstorm/gui/GameLogic.java

@ -33,7 +33,7 @@ public class GameLogic extends JPanel {
// GUI stuff // GUI stuff
private ArrayList<JPanel> fields; private ArrayList<JPanel> fields;
private JLabel matchfieldValue; private JLabel matchfieldValue;
private JLabel moveValue;
private JLabel stateValue;
private JLabel own2Ship; private JLabel own2Ship;
private JLabel own3Ship; private JLabel own3Ship;
private JLabel own4Ship; private JLabel own4Ship;
@ -172,11 +172,11 @@ public class GameLogic extends JPanel {
matchfieldValue = new JLabel("-"); matchfieldValue = new JLabel("-");
gameInfoContentPanel.add(matchfieldValue); gameInfoContentPanel.add(matchfieldValue);
JLabel moveLabel = new JLabel("Am Zug");
gameInfoContentPanel.add(moveLabel);
JLabel stateLabel = new JLabel("Status");
gameInfoContentPanel.add(stateLabel);
moveValue = new JLabel("-");
gameInfoContentPanel.add(moveValue);
stateValue = new JLabel("-");
gameInfoContentPanel.add(stateValue);
for (int x = 0; x < 10; x++) { for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
@ -201,7 +201,11 @@ public class GameLogic extends JPanel {
int coordX = coords[0]; int coordX = coords[0];
int coordY = coords[1]; int coordY = coords[1];
// TODO add shoot function
boolean shotSuccess = enemyMatchfield.getField(coordX, coordY).shoot();
gui.updateField(playerMove, enemyMatchfield);
if (!shotSuccess)
nextMove();
} }
}); });
} }
@ -217,8 +221,8 @@ public class GameLogic extends JPanel {
return matchfieldValue; return matchfieldValue;
} }
public JLabel getMoveValue() {
return moveValue;
public JLabel getStateValue() {
return stateValue;
} }
public JLabel getOwn2Ship() { public JLabel getOwn2Ship() {
@ -282,7 +286,7 @@ public class GameLogic extends JPanel {
coordinatePanel.setBackground(new Color(0, 94, 184)); coordinatePanel.setBackground(new Color(0, 94, 184));
break; break;
case Coordinate.HIT: case Coordinate.HIT:
coordinatePanel.setBackground(new Color(0, 94, 184));
coordinatePanel.setBackground(new Color(91, 58, 41));
coordinatePanel.add(new JLabel("x")); coordinatePanel.add(new JLabel("x"));
break; break;
} }
@ -293,11 +297,16 @@ public class GameLogic extends JPanel {
// set game infos // set game infos
if (this.playerMove) { if (this.playerMove) {
this.getMatchfieldValue().setText("Gegner");
this.getMoveValue().setText("Du");
if (this.gameState == GameLogic.PREPARATION) {
this.getMatchfieldValue().setText("Eigenes");
this.getStateValue().setText("Vorbereiten...");
} else {
this.getMatchfieldValue().setText("Gegner");
this.getStateValue().setText("Du bist am Zug");
}
} else { } else {
this.getMatchfieldValue().setText("Eigenes"); this.getMatchfieldValue().setText("Eigenes");
this.getMoveValue().setText("Gegner");
this.getStateValue().setText("Dein Gegner ist am Zug");
} }
} }
@ -349,6 +358,7 @@ public class GameLogic extends JPanel {
} }
// enter game loop // enter game loop
this.gameState = GameLogic.RUNNING;
this.nextMove(); this.nextMove();
} }
@ -357,8 +367,27 @@ public class GameLogic extends JPanel {
if (this.playerMove) { if (this.playerMove) {
gui.updateField(this.playerMove, this.enemyMatchfield); gui.updateField(this.playerMove, this.enemyMatchfield);
// waiting for mouse click event....
} else { } else {
gui.updateField(this.playerMove, this.matchfield); gui.updateField(this.playerMove, this.matchfield);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Coordinate aiChosenField = this.aiLogic.chooseField();
aiChosenField.shoot();
gui.updateField(this.playerMove, this.matchfield);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.nextMove();
} }
} }

Loading…
Cancel
Save