This commit is contained in:
Maciej Caderek
2022-02-19 04:53:42 +01:00
parent db7ba81b99
commit 0d3d7f6143
44 changed files with 228 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ class Player {
private interval = 1000;
private game: Game = new Game();
private ply: number = 0;
private callback: (playing: boolean, ply: number) => void = () => {};
public playing: boolean = false;
private firstRender: Promise<void>;
@@ -19,6 +20,10 @@ class Player {
.then((_) => this.board.render());
}
watch(fn: (playing: boolean, ply: number) => void) {
this.callback = fn;
}
updateConfig(config: Partial<GameConfig>) {
this.config = { ...this.config, ...config };
}
@@ -44,6 +49,11 @@ class Player {
async play() {
this.playing = true;
this.callback(this.playing, this.ply);
if (this.ply === this.game.getMoves().length) {
this.first();
}
while (true) {
await delay(this.interval);
@@ -57,6 +67,7 @@ class Player {
pause() {
this.playing = false;
this.callback(this.playing, this.ply);
}
async prev() {
@@ -82,6 +93,7 @@ class Player {
const ply = this.ply + 1;
if (ply >= this.game.length) {
this.pause();
return;
}