added history

This commit is contained in:
OezmenK
2022-07-19 13:40:44 +02:00
parent 0226cb9cfb
commit 6e97d11f43

View File

@@ -10,6 +10,7 @@ export class BoardComponent implements OnInit {
draw: boolean;
xIsNext: boolean;
fields: any[];
history: any[];
constructor() {}
@@ -22,6 +23,7 @@ export class BoardComponent implements OnInit {
this.draw = false;
this.xIsNext = true;
this.fields = Array(9).fill(null);
this.history = [];
}
get player() {
@@ -36,6 +38,8 @@ export class BoardComponent implements OnInit {
if (!this.fields[i]) {
this.fields.splice(i, 1, this.player);
this.history.push(this.fields.slice());
this.xIsNext = !this.xIsNext;
this.calculateWinner();
}