henrylin03 / battleship

Battleship game in your browser, written in JavaScript
http://henrylin.io/battleship/
MIT License
0 stars 0 forks source link

use modal for win announcement rather than just an alert in the browser #9

Open henrylin03 opened 2 months ago

henrylin03 commented 2 months ago

for some reason, the alert shows before the board is reprinted even though it's not ordered that way in the if condition block in updateGrids() method of the screen controller factory (createScreenController)

current code:

//createScreenController.js

function updateScreen() {
  ...

  // run
  createGrids();
  updateGrids();

  if (game.activePlayerWins()) {
    disableClicksOnOpponentsBoard();

    const activePlayer = game.getActivePlayer();
    const alertText = activePlayer.isComputer() ? "Computer wins" : "You win";

    return alert(alertText);
  }
}
henrylin03 commented 2 months ago

can use a similar modal in tic-tac-toe project: https://github.com/henrylin03/tic-tac-toe