Browse Source

Fixed that AI has next move when ship was hit

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
629063b5ff
  1. 6
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 8
      src/main/java/de/tims/fleetstorm/gui/GameLogic.java

6
src/main/java/de/tims/fleetstorm/ai/Logic.java

@ -93,8 +93,10 @@ public class Logic {
}
public void isShipOnYAxis() {
if ((clearedAbove && clearedBelow) && ((matchfield.getAbove(lastShot).getState() == Coordinate.HIT)
|| (matchfield.getBelow(lastShot).getState() == Coordinate.HIT))) {
if ((clearedAbove && clearedBelow) && ((matchfield.getAbove(lastShot) == null
|| (matchfield.getAbove(lastShot).getState() == Coordinate.HIT))
|| (matchfield.getBelow(lastShot) == null
|| (matchfield.getBelow(lastShot).getState() == Coordinate.HIT)))) {
clearedLeft = true;
clearedRight = true;
sinkShip();

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

@ -216,12 +216,16 @@ public class GameLogic extends JPanel {
// waiting for mouse click event....
} else {
Coordinate aiChosenField = this.aiLogic.chooseField();
Coordinate aiChosenField = null;
while (aiChosenField == null) {
aiChosenField = this.aiLogic.chooseField();
}
aiChosenField.print();
aiChosenField.shoot();
gui.updateFields();
boolean aiHasNextMove = aiChosenField.getState() == Coordinate.HIT;
boolean aiHasNextMove = aiChosenField.getState() != Coordinate.HIT;
this.nextMove(aiHasNextMove);
}

Loading…
Cancel
Save