Allow dynamic creation of game states

This commit is contained in:
Manuel Thalmann 2022-12-13 11:20:21 +01:00
parent 87f078da13
commit be4956f360
No known key found for this signature in database
GPG key ID: 5FD9AD3CCDDBD27B
2 changed files with 11 additions and 5 deletions

View file

@ -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();
}

View file

@ -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} */ (""));
}));
}