-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrap project and add game logic
- Loading branch information
1 parent
3c31808
commit c5094b0
Showing
19 changed files
with
225 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "react-app", | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import Square from './Square'; | ||
import { calculateWinner } from '../utils'; | ||
|
||
export default class Board extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
squares: Array(9).fill(null), | ||
xIsNext: true | ||
}; | ||
} | ||
|
||
handleClick(i) { | ||
const squares = this.state.squares.slice(); | ||
if (calculateWinner(squares) || squares[i]) { | ||
return; | ||
} | ||
squares[i] = this.state.xIsNext ? 'X' : 'O'; | ||
this.setState({ | ||
squares: squares, | ||
xIsNext: !this.state.xIsNext | ||
}); | ||
} | ||
|
||
renderSquare(i) { | ||
return ( | ||
<Square | ||
value={this.state.squares[i]} | ||
onClick={() => this.handleClick(i)} | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
const winner = calculateWinner(this.state.squares); | ||
let status; | ||
if (winner) { | ||
status = 'Winner: ' + winner; | ||
} else { | ||
status = 'Next player: ' + (this.state.xIsNext ? 'X' : 'O'); | ||
} | ||
|
||
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import Board from './Board'; | ||
|
||
export default 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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
export default function Square(props) { | ||
return ( | ||
<button className="square" onClick={props.onClick}> | ||
{props.value} | ||
</button> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
import * as serviceWorker from './serviceWorker'; | ||
import './assets/index.css'; | ||
import Game from './components/Game'; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
|
||
// If you want your app to work offline and load faster, you can change | ||
// unregister() to register() below. Note this comes with some pitfalls. | ||
// Learn more about service workers: http://bit.ly/CRA-PWA | ||
serviceWorker.unregister(); | ||
ReactDOM.render(<Game />, document.getElementById('root')); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.