diff --git a/src/.List.js.swp b/src/.List.js.swp deleted file mode 100644 index 3217881..0000000 Binary files a/src/.List.js.swp and /dev/null differ diff --git a/src/index.css b/src/index.css index a9945fc..7b78493 100644 --- a/src/index.css +++ b/src/index.css @@ -1,10 +1,58 @@ + +/** + * Web唐明明 + * 匆匆数载恍如梦,岁月迢迢华发增。 + * 碌碌无为枉半生,一朝惊醒万事空。 + */ + body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; + font: 14px "Century Gothic", Futura, sans-serif; + margin: 20px; } -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; +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; +} + diff --git a/src/index.js b/src/index.js index ef2edf8..5825f82 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,139 @@ +/** + * Web唐明明 + * 匆匆数载恍如梦,岁月迢迢华发增。 + * 碌碌无为枉半生,一朝惊醒万事空。 + * ComponentName: '官方demo - 组件之间的传参' + */ + import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; + +// 类组件 +// class Square extends React.Component { +// // 入口函数 +// render() { +// return ( +// +// ); +// } +// } + +// 函数组件 +const Square = (props) => { + return ( + + ) +} + +class Board extends React.Component { + // 类组件es6的constructor钩子函数 + constructor (props) { + super(props); + this.state = { + squares: Array(9).fill(null), + xInNext: true + } + } + // 定一个一个组件方法 + handleClick(i) { + // Array.slice()返回数组选定的元素,相当于克隆了原有数组 + const squares = this.state.squares.slice() + if(calculateWinner(squares) || squares[i]) { + return + } + squares[i] = this.state.xInNext ? 'X': 'O' + this.setState({ + squares, + xInNext: !this.state.xInNext + }) + } + // 小方格方法 + renderSquare(i) { + return this.handleClick(i)} + />; + } + render() { + const winner = calculateWinner(this.state.squares) + let status; + if (winner) { + status = '恭喜选手' + winner + '获胜~' + }else{ + status = '下一位选手: ' + (this.state.xInNext ? 'X': 'O'); + } + return ( +
+
{status}
+
+ {this.renderSquare(0)} + {this.renderSquare(1)} + {this.renderSquare(2)} +
+
+ {this.renderSquare(3)} + {this.renderSquare(4)} + {this.renderSquare(5)} +
+
+ {this.renderSquare(6)} + {this.renderSquare(7)} + {this.renderSquare(8)} +
+
+ ); + } +} + +class Game extends React.Component { + render() { + return ( +
+
+ +
+
+
{/* status */}
+
    {/* TODO */}
+
+
+ ); + } +} + +function calculateWinner(squares) { + const lines = [ + [0, 1, 2], + [3, 4, 5], + [6, 7, 8], + [0, 3, 6], + [1, 4, 7], + [2, 5, 8], + [0, 4, 8], + [2, 4, 6], + ]; + for (let i = 0; i < lines.length; i++) { + const [a, b, c] = lines[i]; + if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) { + return squares[a]; + } + } + return null; +} ReactDOM.render( - - - , + , document.getElementById('root') ); -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); diff --git a/src/App.css b/留一个备份的src/App.css similarity index 100% rename from src/App.css rename to 留一个备份的src/App.css diff --git a/src/App.js b/留一个备份的src/App.js similarity index 100% rename from src/App.js rename to 留一个备份的src/App.js diff --git a/src/App.test.js b/留一个备份的src/App.test.js similarity index 100% rename from src/App.test.js rename to 留一个备份的src/App.test.js diff --git a/src/List.js b/留一个备份的src/List.js similarity index 100% rename from src/List.js rename to 留一个备份的src/List.js diff --git a/留一个备份的src/index.css b/留一个备份的src/index.css new file mode 100644 index 0000000..a9945fc --- /dev/null +++ b/留一个备份的src/index.css @@ -0,0 +1,10 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; +} diff --git a/留一个备份的src/index.js b/留一个备份的src/index.js new file mode 100644 index 0000000..ef2edf8 --- /dev/null +++ b/留一个备份的src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/src/logo.svg b/留一个备份的src/logo.svg similarity index 100% rename from src/logo.svg rename to 留一个备份的src/logo.svg diff --git a/src/reportWebVitals.js b/留一个备份的src/reportWebVitals.js similarity index 100% rename from src/reportWebVitals.js rename to 留一个备份的src/reportWebVitals.js diff --git a/src/setupTests.js b/留一个备份的src/setupTests.js similarity index 100% rename from src/setupTests.js rename to 留一个备份的src/setupTests.js