react
This commit is contained in:
50
JavaScript/React/tic-tac-toe/src/index.css
Normal file
50
JavaScript/React/tic-tac-toe/src/index.css
Normal file
@@ -0,0 +1,50 @@
|
||||
body {
|
||||
font: 14px "Century Gothic", Futura, sans-serif;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
ol, ul {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
.board-row:after {
|
||||
clear: both;
|
||||
content: "";
|
||||
display: table;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.square {
|
||||
background: #fff;
|
||||
border: 1px solid #999;
|
||||
float: left;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
line-height: 34px;
|
||||
height: 34px;
|
||||
margin-right: -1px;
|
||||
margin-top: -1px;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
width: 34px;
|
||||
}
|
||||
|
||||
.square:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.kbd-navigation .square:focus {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
.game {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.game-info {
|
||||
margin-left: 20px;
|
||||
}
|
||||
72
JavaScript/React/tic-tac-toe/src/index.js
Normal file
72
JavaScript/React/tic-tac-toe/src/index.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
|
||||
class Square extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
value: null
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button className="square" onClick={() => this.setState({value: 'X'})}>
|
||||
{this.state.value}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Board extends React.Component {
|
||||
renderSquare(i) {
|
||||
return <Square value={i}/>;
|
||||
}
|
||||
|
||||
render() {
|
||||
const status = 'Next player: X';
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="status">{status}</div>
|
||||
<div className="board-row">
|
||||
{this.renderSquare(0)}
|
||||
{this.renderSquare(1)}
|
||||
{this.renderSquare(2)}
|
||||
</div>
|
||||
<div className="board-row">
|
||||
{this.renderSquare(3)}
|
||||
{this.renderSquare(4)}
|
||||
{this.renderSquare(5)}
|
||||
</div>
|
||||
<div className="board-row">
|
||||
{this.renderSquare(6)}
|
||||
{this.renderSquare(7)}
|
||||
{this.renderSquare(8)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Game extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className="game">
|
||||
<div className="game-board">
|
||||
<Board />
|
||||
</div>
|
||||
<div className="game-info">
|
||||
<div>{/* status */}</div>
|
||||
<ol>{/* TODO */}</ol>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<Game />,
|
||||
document.getElementById('root')
|
||||
);
|
||||
Reference in New Issue
Block a user