+const Team = {
+ X: 0,
+ O: 1,
+ properties: {
+ 0: {name: "X"},
+ 1: {name: "O"}
+ }
+};
+
function undisplay(element) {
element.style.display="none";
}
squares: Array(9).fill(null)
}
],
- stepNumber: 0,
- xIsNext: true
+ step_number: 0,
+ next_to_play: Team.X
};
}
squares: Array(9).fill(null)
}
],
- stepNumber: 0,
- xIsNext: true
+ step_number: 0,
+ next_to_play: Team.X
});
}
receiveMove(i) {
- const history = this.state.history.slice(0, this.state.stepNumber + 1);
+ const history = this.state.history.slice(0, this.state.step_number + 1);
const current = history[history.length - 1];
const squares = current.squares.slice();
if (calculateWinner(squares) || squares[i]) {
return;
}
- squares[i] = this.state.xIsNext ? "X" : "O";
+ squares[i] = Team.properties[this.state.next_to_play].name;
+ let next_to_play;
+ if (this.state.next_to_play === Team.X)
+ next_to_play = Team.O;
+ else
+ next_to_play = Team.X;
this.setState({
history: history.concat([
{
squares: squares
}
]),
- stepNumber: history.length,
- xIsNext: !this.state.xIsNext
+ step_number: history.length,
+ next_to_play: next_to_play
});
}
}
}
- jumpTo(step) {
- this.setState({
- stepNumber: step,
- xIsNext: (step % 2) === 0
- });
- }
-
render() {
const history = this.state.history;
- const current = history[this.state.stepNumber];
+ const current = history[this.state.step_number];
const winner = calculateWinner(current.squares);
let status;
if (winner) {
status = "Winner: " + winner;
} else {
- status = "Next player: " + (this.state.xIsNext ? "X" : "O");
+ status = "Next player: " + (Team.properties[this.state.next_to_play].name);
}
return (