Browse Source

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

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

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

@ -33,7 +33,7 @@ public class GameLogic extends JPanel {
// GUI stuff
private ArrayList<JPanel> fields;
private JLabel matchfieldValue;
private JLabel moveValue;
private JLabel stateValue;
private JLabel own2Ship;
private JLabel own3Ship;
private JLabel own4Ship;
@ -172,11 +172,11 @@ public class GameLogic extends JPanel {
matchfieldValue = new JLabel("-");
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 y = 0; y < 10; y++) {
@ -201,7 +201,11 @@ public class GameLogic extends JPanel {
int coordX = coords[0];
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;
}
public JLabel getMoveValue() {
return moveValue;
public JLabel getStateValue() {
return stateValue;
}
public JLabel getOwn2Ship() {
@ -282,7 +286,7 @@ public class GameLogic extends JPanel {
coordinatePanel.setBackground(new Color(0, 94, 184));
break;
case Coordinate.HIT:
coordinatePanel.setBackground(new Color(0, 94, 184));
coordinatePanel.setBackground(new Color(91, 58, 41));
coordinatePanel.add(new JLabel("x"));
break;
}
@ -293,11 +297,16 @@ public class GameLogic extends JPanel {
// set game infos
if (this.playerMove) {
if (this.gameState == GameLogic.PREPARATION) {
this.getMatchfieldValue().setText("Eigenes");
this.getStateValue().setText("Vorbereiten...");
} else {
this.getMatchfieldValue().setText("Gegner");
this.getMoveValue().setText("Du");
this.getStateValue().setText("Du bist am Zug");
}
} else {
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
this.gameState = GameLogic.RUNNING;
this.nextMove();
}
@ -357,8 +367,27 @@ public class GameLogic extends JPanel {
if (this.playerMove) {
gui.updateField(this.playerMove, this.enemyMatchfield);
// waiting for mouse click event....
} else {
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