Store the id of the board in the Game class

This commit is contained in:
Manuel Thalmann 2022-12-13 11:02:56 +01:00
parent f542319b43
commit 6faeae8b66
No known key found for this signature in database
GPG key ID: 5FD9AD3CCDDBD27B
2 changed files with 18 additions and 10 deletions

View file

@ -15,10 +15,21 @@ export class Game
#state;
/**
* Initializes a new instance of the {@link Game `Game`} class.
* The id of the element to add the board to.
*
* @type {string}
*/
constructor()
id;
/**
* Initializes a new instance of the {@link Game `Game`} class.
*
* @param {string} id
* The id of the element to add the board to.
*/
constructor(id)
{
this.id = id;
this.#state = new State();
}
@ -40,13 +51,10 @@ export class Game
/**
* Initializes the game.
*
* @param {string} id
* The id of the element to add the board to.
*/
initialize(id)
initialize()
{
let board = document.getElementById(id);
let board = document.getElementById(this.id);
board.innerHTML = "";
for (let i = 0; i < 6; i++)
@ -78,7 +86,7 @@ export class Game
{
this.board[i][j] = this.state.currentPlayer;
this.state.turnCount++;
this.initialize(id);
this.initialize();
};
board.appendChild(field);

View file

@ -12,8 +12,8 @@ let game;
*/
function initialize()
{
game = new Game();
game.initialize("board");
game = new Game("board");
game.initialize();
}
initialize();