Skip to content
Permalink
Browse files

Save and show coordinates

  • Loading branch information...
Sercan Leylek
Sercan Leylek committed Feb 20, 2019
1 parent 2b4f596 commit 052f7da634fc4936408398b5efbbfc92405b1779
Showing with 13 additions and 3 deletions.
  1. +13 −3 tic-tac-toe/src/components/Game/Game.js
@@ -8,7 +8,9 @@ class Game extends React.Component {
this.state = {
history: [
{
squares: Array(9).fill(null)
squares: Array(9).fill(null),
col: -1,
row: -1
}
],
stepNumber: 0,
@@ -21,6 +23,8 @@ class Game extends React.Component {
const history = this.state.history.slice(0, this.state.stepNumber + 1);
const current = history[history.length - 1];
const squares = current.squares.slice();
const col = (i % 3) + 1;
const row = Math.floor(i/3) + 1;

if (calculateWinner(squares) || squares[i]) {
return;
@@ -29,7 +33,13 @@ class Game extends React.Component {
squares[i] = this.state.xIsNext ? 'X' : 'O';
this.setState({
history: history.concat(
[{squares: squares}]
[
{
squares: squares,
col: col,
row: row
}
]
),
stepNumber: history.length,
xIsNext: !this.state.xIsNext
@@ -51,7 +61,7 @@ class Game extends React.Component {

const moves = history.map((step, move) => {
const desc = move ?
'Go to move #' + move :
'Go to move #' + move + " at " + step.row + "," + step.col:
'Go to game start';
return (
<li key={move}>

0 comments on commit 052f7da

Please sign in to comment.
You can’t perform that action at this time.