Allow dynamic creation of game states
This commit is contained in:
parent
87f078da13
commit
be4956f360
|
@ -40,7 +40,7 @@ export class Game
|
||||||
constructor(id)
|
constructor(id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.#state = new State();
|
this.#state = new State(Game.#width, Game.#height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ export class Game
|
||||||
*/
|
*/
|
||||||
reset()
|
reset()
|
||||||
{
|
{
|
||||||
this.#state = new State();
|
this.#state = new State(Game.#width, Game.#height);
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,20 @@ export class State
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new instance of the {@link State `State`} class.
|
* 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} */ (
|
this.#board = /** @type {Board} */ (
|
||||||
Array(6).fill("").map(
|
Array(height).fill("").map(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
return Array(7).fill(
|
return Array(width).fill(
|
||||||
/** @type {CellOwner} */ (""));
|
/** @type {CellOwner} */ (""));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue