|
|
@ -26,7 +26,7 @@ public class GameLogic extends JPanel { |
|
|
|
|
|
|
|
public static final int PREPARATION = 1; |
|
|
|
public static final int RUNNING = 2; |
|
|
|
public static final int OVER = 3; |
|
|
|
public static final int GAME_OVER = 3; |
|
|
|
|
|
|
|
// GUI stuff |
|
|
|
private ArrayList<JPanel> playerFields; |
|
|
@ -38,13 +38,13 @@ public class GameLogic extends JPanel { |
|
|
|
|
|
|
|
setSize(640, 480); |
|
|
|
|
|
|
|
JPanel fieldWrapper = new JPanel(); |
|
|
|
fieldWrapper = new JPanel(); |
|
|
|
fieldWrapper.setBounds(10, 11, 305, 458); |
|
|
|
fieldWrapper.setLayout(null); |
|
|
|
setLayout(null); |
|
|
|
add(fieldWrapper); |
|
|
|
|
|
|
|
JPanel enemyFieldWrapper = new JPanel(); |
|
|
|
enemyFieldWrapper = new JPanel(); |
|
|
|
enemyFieldWrapper.setLayout(null); |
|
|
|
enemyFieldWrapper.setBounds(326, 11, 305, 458); |
|
|
|
add(enemyFieldWrapper); |
|
|
@ -94,6 +94,12 @@ public class GameLogic extends JPanel { |
|
|
|
|
|
|
|
boolean shotSuccess = chosenField.shoot(); |
|
|
|
|
|
|
|
boolean areAllShipsHit = enemyMatchfield.areAllShipsHit(); |
|
|
|
if (areAllShipsHit) { |
|
|
|
gameOver(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (shotSuccess && chosenField.getState() != Coordinate.HIT) { |
|
|
|
nextMove(false); |
|
|
|
} else { |
|
|
@ -163,6 +169,8 @@ public class GameLogic extends JPanel { |
|
|
|
* This function is only for testing |
|
|
|
*/ |
|
|
|
private static GameLogic gui; |
|
|
|
private JPanel fieldWrapper; |
|
|
|
private JPanel enemyFieldWrapper; |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
JFrame frame = new JFrame("Test GUI"); |
|
|
@ -223,12 +231,22 @@ public class GameLogic extends JPanel { |
|
|
|
|
|
|
|
gui.updateFields(); |
|
|
|
|
|
|
|
boolean areAllShipsHit = this.matchfield.areAllShipsHit(); |
|
|
|
if (areAllShipsHit) { |
|
|
|
this.gameOver(false); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
boolean aiHasNextMove = aiChosenField.getState() != Coordinate.HIT; |
|
|
|
this.nextMove(aiHasNextMove); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected void gameOver(boolean playerWinner) { |
|
|
|
this.gameState = GameLogic.GAME_OVER; |
|
|
|
} |
|
|
|
|
|
|
|
public int getGameState() { |
|
|
|
return gameState; |
|
|
|
} |
|
|
|