Skip to content

Commit

Permalink
Update GameBoard.java (#39)
Browse files Browse the repository at this point in the history
Addressed the issue where the last successful hit wouldn't change to the correct color, turning orange instead of red. This was resolved by manually setting the color of the last position to red before displaying the message. In the original code, when someone got a correct hit, the tile would turn red. The problem stemmed from this code turning the tile red wouldn't occur when someone won due to the if-else structure of this part of the code. As such, manually setting the tile to red when displaying the victory screen resolves this issue.
  • Loading branch information
sstanham authored Dec 8, 2020
1 parent 82c002d commit 74ece8d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/battleship/gui/GameBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ private void handleData(Object data) {
enemyPositions[posToAttack[1]][posToAttack[2]].setBackground(Color.RED);
setPlayerTurn(true);
} else if (posToAttack[0] == GAME_WON) {
//Player has won, set the position to be red and display victory message
enemyPositions[posToAttack[1]][posToAttack[2]].setBackground(Color.RED);
JOptionPane.showMessageDialog(frame,
"You won!",
"Congratulations",
Expand Down Expand Up @@ -392,4 +394,4 @@ private void testPrint(Object src) {
}


}
}

0 comments on commit 74ece8d

Please sign in to comment.