Store the id of the board in the Game
class
This commit is contained in:
parent
f542319b43
commit
6faeae8b66
2 changed files with 18 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -12,8 +12,8 @@ let game;
|
|||
*/
|
||||
function initialize()
|
||||
{
|
||||
game = new Game();
|
||||
game.initialize("board");
|
||||
game = new Game("board");
|
||||
game.initialize();
|
||||
}
|
||||
|
||||
initialize();
|
||||
|
|
Loading…
Reference in a new issue