Create a dedicated draw method

This commit is contained in:
Manuel Thalmann 2022-12-13 11:04:17 +01:00
parent 6faeae8b66
commit 63bfb5375e
No known key found for this signature in database
GPG key ID: 5FD9AD3CCDDBD27B

View file

@ -53,6 +53,14 @@ export class Game
* Initializes the game. * Initializes the game.
*/ */
initialize() initialize()
{
this.draw();
}
/**
* Replaces the content of the board with the current state.
*/
draw()
{ {
let board = document.getElementById(this.id); let board = document.getElementById(this.id);
board.innerHTML = ""; board.innerHTML = "";
@ -86,7 +94,7 @@ export class Game
{ {
this.board[i][j] = this.state.currentPlayer; this.board[i][j] = this.state.currentPlayer;
this.state.turnCount++; this.state.turnCount++;
this.initialize(); this.draw();
}; };
board.appendChild(field); board.appendChild(field);