added history
This commit is contained in:
@@ -10,6 +10,7 @@ export class BoardComponent implements OnInit {
|
|||||||
draw: boolean;
|
draw: boolean;
|
||||||
xIsNext: boolean;
|
xIsNext: boolean;
|
||||||
fields: any[];
|
fields: any[];
|
||||||
|
history: any[];
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ export class BoardComponent implements OnInit {
|
|||||||
this.draw = false;
|
this.draw = false;
|
||||||
this.xIsNext = true;
|
this.xIsNext = true;
|
||||||
this.fields = Array(9).fill(null);
|
this.fields = Array(9).fill(null);
|
||||||
|
this.history = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get player() {
|
get player() {
|
||||||
@@ -36,6 +38,8 @@ export class BoardComponent implements OnInit {
|
|||||||
if (!this.fields[i]) {
|
if (!this.fields[i]) {
|
||||||
this.fields.splice(i, 1, this.player);
|
this.fields.splice(i, 1, this.player);
|
||||||
|
|
||||||
|
this.history.push(this.fields.slice());
|
||||||
|
|
||||||
this.xIsNext = !this.xIsNext;
|
this.xIsNext = !this.xIsNext;
|
||||||
this.calculateWinner();
|
this.calculateWinner();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user