My questions is that I have this class for a checkers game but I dont know how to implement that on a new function to restart the board.
class Board{
private board:number[][];
constructor(){
this.board = [
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 2, 0, 2, 0, 2, 0, 2],
[2, 0, 2, 0, 2, 0, 2, 0],
[0, 2, 0, 2, 0, 2, 0, 2]
];
}
initializeBoard() {
for (let i = 0; i < this.board.length; i++) {
for (let j = 0; j < this.board[i].length; j++) {
const cellvalue = this.board[i][j];
if (cellvalue === 2) {
setTile(i, j, "red pawn");
} else if (cellvalue === 1) {
setTile(i, j, "blue pawn");
}
}
}
setTile(0, 0, "blue queen");
setTile(7, 7, "red queen");
}
}
And I have another file with the function to restart the board, how I import that initializeBoard() function on the class Board to the new one (function onRestart)??
Thank you very much!
I will want to see when I apply the function onRestart the Board start again with the same positions.