From f9ce68b64a18eb99d6a44f8a2a2191ea712ea555 Mon Sep 17 00:00:00 2001 From: sstanham <46492804+sstanham@users.noreply.github.com> Date: Sat, 14 Nov 2020 14:45:02 -0500 Subject: [PATCH] Update ShipPlanner.java This push is to fix the error that a player can start the game without placing their last ship. This is done by clicking anywhere a ship cannot be placed. I fixed this by adding a check in line 217, checking if the mouseclick is a valid location, and only recording the action if it is valid. --- src/main/java/com/battleship/gui/ShipPlanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/battleship/gui/ShipPlanner.java b/src/main/java/com/battleship/gui/ShipPlanner.java index ff61d9e..879b3ea 100644 --- a/src/main/java/com/battleship/gui/ShipPlanner.java +++ b/src/main/java/com/battleship/gui/ShipPlanner.java @@ -214,7 +214,7 @@ public void mouseClicked(MouseEvent e) { // TODO: refactor for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { - if (source == positions[i][j]) { + if (source == positions[i][j] && isValidPosition(i,j,i,j)) { int comboBoxItemCount = comboBoxShipSelector.getItemCount();