|
1 |
| - |
2 | 1 | <html>
|
3 | 2 |
|
4 |
| - <head> |
5 |
| - <script src="https://unpkg.com/react@15/dist/react.js"></script> |
6 |
| - <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script> |
7 |
| - <script src="https://unpkg.com/prop-types@15/prop-types.js"></script> |
8 |
| - |
9 |
| - <script src="go-lib.js"></script> |
10 |
| - </head> |
11 |
| - <body> |
12 |
| - <div id="board-wrapper" style="width: 500px; height: 500px;" onclick="handleOnClick()"></div> |
13 |
| - |
14 |
| - <script> |
15 |
| - let pos = 0 |
16 |
| - const moves = [ |
17 |
| - { pos: [16, 4], color: 'B' }, |
18 |
| - { pos: [4, 16], color: 'W' }, |
19 |
| - { pos: [16, 17], color: 'B' }, |
20 |
| - { pos: [4, 4], color: 'W' }, |
21 |
| - { pos: [17, 11], color: 'B' }, |
22 |
| - { pos: [13, 16], color: 'W' }, |
23 |
| - { pos: [16, 15], color: 'B' }, |
24 |
| - { pos: [10, 16], color: 'W' }, |
25 |
| - { pos: [3, 14], color: 'B' }, |
26 |
| - { pos: [3, 12], color: 'W' }, |
27 |
| - ] |
28 |
| - |
29 |
| - const render = () => { |
30 |
| - const board = React.createElement(GoLib.Board, { |
31 |
| - width: 500, |
32 |
| - height: 500, |
33 |
| - size: 19, |
34 |
| - moves: moves.slice(0, pos), |
35 |
| - }) |
36 |
| - ReactDOM.render(board, document.getElementById('board-wrapper')) |
37 |
| - } |
38 |
| - |
39 |
| - const handleOnClick = () => { |
40 |
| - pos = pos === moves.length - 1 ? pos : pos + 1 |
41 |
| - render() |
42 |
| - } |
43 |
| - |
44 |
| - render() |
45 |
| - </script> |
46 |
| - </body> |
| 3 | +<head> |
| 4 | + <script src="https://unpkg.com/react@15/dist/react.js"></script> |
| 5 | + <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script> |
| 6 | + <script src="https://unpkg.com/prop-types@15/prop-types.js"></script> |
| 7 | + |
| 8 | + <script src="go-lib.js"></script> |
| 9 | +</head> |
| 10 | + |
| 11 | +<body> |
| 12 | + <div id="board-wrapper" style="width: 500px; height: 500px;"></div> |
| 13 | + |
| 14 | + <script> |
| 15 | + let color = 'B' |
| 16 | + const stones = [] |
| 17 | + |
| 18 | + const render = () => { |
| 19 | + const board = React.createElement(GoLib.components.Board, { |
| 20 | + width: 500, |
| 21 | + height: 500, |
| 22 | + size: 19, |
| 23 | + positions: stones, |
| 24 | + onPositionClick: handleBoardPositionClick, |
| 25 | + }) |
| 26 | + |
| 27 | + ReactDOM.render(board, document.getElementById('board-wrapper')) |
| 28 | + } |
| 29 | + |
| 30 | + const handleBoardPositionClick = (coordinate) => { |
| 31 | + stones.push({ color, coordinate }) |
| 32 | + |
| 33 | + color = color === 'B' ? 'W' : 'B' |
| 34 | + |
| 35 | + render() |
| 36 | + } |
| 37 | + |
| 38 | + render() |
| 39 | + </script> |
| 40 | +</body> |
| 41 | + |
47 | 42 | </html>
|
0 commit comments