Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
transform: rotate(360deg);
}
}
.case{
width: 50px;
height: 50px;
}
3 changes: 3 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Board from "./Board";

class App extends Component {
render() {
Expand All @@ -19,7 +20,9 @@ class App extends Component {
>
Learn React
</a>
<Board/>
</header>

</div>
);
}
Expand Down
64 changes: 64 additions & 0 deletions src/Board.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, {Component} from 'react';
import Cases from './Cases.jsx';
export default class Board extends Component {


constructor(props){

super(props);
this.state= {
grid:Array(9).fill(null),
player:'X',
};
}

handleClick(index) {
const grid = [...this.state.grid];
//grid[index] = 'X';
grid[index] =this.state.player;
if(this.state.player === 'X'){
this.setState({player:'O'});
}
else{
this.setState({player:'X'});

}
this.setState({ grid });
}


renderCase(i){

return <Cases value={this.state.grid[i]}

onClick={() => this.handleClick(i)}

/>;
}
render() {
const tour = 'Next Player : '+ this.state.player;

return (
<div>
<div className="tour">{tour}</div>
<div className="board-row">
{this.renderCase(0)}
{this.renderCase(1)}
{this.renderCase(2)}
</div>
<div className="board-row">
{this.renderCase(3)}
{this.renderCase(4)}
{this.renderCase(5)}
</div>
<div className="board-row">
{this.renderCase(6)}
{this.renderCase(7)}
{this.renderCase(8)}
</div>
</div>
);
}


}
23 changes: 23 additions & 0 deletions src/Cases.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, {Component} from 'react';


export default class Cases extends Component{

getStyle() {
return {
cursor: this.props.value ? 'default' : 'pointer'
}
}

render() {
return (
<button
className="case"
style={this.getStyle()}
onClick={this.props.onClick}
>
{this.props.value}
</button>
);
}
}
22 changes: 22 additions & 0 deletions src/Game.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, {Component} from 'react';
import Board from './Board.jsx';


export default class Game extends Component{

render() {
return (
<div className="game">
<div className="game-board">
<Board/>
</div>
<div className="game-info">
<div>{/* status */}</div>
<ol>{/* TODO */}</ol>
</div>
</div>
);
}


}