added history
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user