Commit 088d4945 authored by 佚名's avatar 佚名 🎅🏼

fix: bugs

parent f2e984ad
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -14,7 +14,7 @@ export const Button = styled.button`
font-weight: bold;
text-align: center;
&:focus {
outline: none
outline: none;
}
&.blue {
background: blue;
......
import { calculateWinner } from '../services/example';
export default {
namespace: 'game',
state: {
......@@ -15,26 +15,6 @@ export default {
reducers: {
handleClick(state, action){
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;
}
const history = state.history.slice(0, state.stepNumber + 1);
const current = history[history.length - 1];
const squares = current.squares.slice();
......@@ -56,7 +36,7 @@ export default {
return {
...state,
stepNumber: action.payload,
xIsNext: (action.move % 2) === 0
xIsNext: (action.payload % 2) === 0
}
}
},
......
import React from 'react';
import { connect } from 'dva';
import { calculateWinner } from '../services/example';
import Board from '../components/Board';
import style from './game.css';
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;
}
const Game = ({ history, stepNumber, xIsNext, dispatch }) => {
const current = history[stepNumber];
const winner = calculateWinner(current.squares);
......
......@@ -3,3 +3,23 @@ import request from '../utils/request';
export function query() {
return request('/api/users');
}
export 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;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment