From be4956f36010627256c39c5d62e39c03749d67f2 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 13 Dec 2022 11:20:21 +0100 Subject: [PATCH] Allow dynamic creation of game states --- src/js/Game.js | 4 ++-- src/js/State.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/js/Game.js b/src/js/Game.js index a3003d5..a2b0d8c 100644 --- a/src/js/Game.js +++ b/src/js/Game.js @@ -40,7 +40,7 @@ export class Game constructor(id) { this.id = id; - this.#state = new State(); + this.#state = new State(Game.#width, Game.#height); } /** @@ -72,7 +72,7 @@ export class Game */ reset() { - this.#state = new State(); + this.#state = new State(Game.#width, Game.#height); this.draw(); } diff --git a/src/js/State.js b/src/js/State.js index f015fc4..4464872 100644 --- a/src/js/State.js +++ b/src/js/State.js @@ -17,14 +17,20 @@ export class State /** * Initializes a new instance of the {@link State `State`} class. + * + * @param {number} width + * The width of the board. + * + * @param {number} height + * The height of the board. */ - constructor() + constructor(width, height) { this.#board = /** @type {Board} */ ( - Array(6).fill("").map( + Array(height).fill("").map( () => { - return Array(7).fill( + return Array(width).fill( /** @type {CellOwner} */ ("")); })); }