From 6faeae8b66b9e696d3844d9fe489de103d8cd768 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 13 Dec 2022 11:02:56 +0100 Subject: [PATCH] Store the id of the board in the `Game` class --- src/js/Game.js | 24 ++++++++++++++++-------- src/js/main.js | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/js/Game.js b/src/js/Game.js index 6995882..8b254dd 100644 --- a/src/js/Game.js +++ b/src/js/Game.js @@ -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); diff --git a/src/js/main.js b/src/js/main.js index c00150e..36ea495 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -12,8 +12,8 @@ let game; */ function initialize() { - game = new Game(); - game.initialize("board"); + game = new Game("board"); + game.initialize(); } initialize();