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() { 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; clearedLeft = true;
clearedRight = true; clearedRight = true;
sinkShip(); 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.... // waiting for mouse click event....
} else { } else {
Coordinate aiChosenField = this.aiLogic.chooseField();
Coordinate aiChosenField = null;
while (aiChosenField == null) {
aiChosenField = this.aiLogic.chooseField();
}
aiChosenField.print(); aiChosenField.print();
aiChosenField.shoot(); aiChosenField.shoot();
gui.updateFields(); gui.updateFields();
boolean aiHasNextMove = aiChosenField.getState() == Coordinate.HIT;
boolean aiHasNextMove = aiChosenField.getState() != Coordinate.HIT;
this.nextMove(aiHasNextMove); this.nextMove(aiHasNextMove);
} }

Loading…
Cancel
Save