Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gm-ticTacToe
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matt 高萌
gm-ticTacToe
Commits
57b10875
Commit
57b10875
authored
Jul 24, 2019
by
Matt 高萌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分离出组件并增加颜色点击变化
parent
34a8556a
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11049 additions
and
17666 deletions
+11049
-17666
package-lock.json
package-lock.json
+0
-17653
package.json
package.json
+2
-1
index.js
src/components/Square/index.js
+27
-0
ticTacToe.js
src/models/ticTacToe.js
+4
-2
index.jsx
src/routes/TicTacToe/index.jsx
+2
-10
yarn.lock
yarn.lock
+11014
-0
No files found.
package-lock.json
deleted
100644 → 0
View file @
34a8556a
This diff is collapsed.
Click to expand it.
package.json
View file @
57b10875
...
...
@@ -9,7 +9,8 @@
"dependencies"
:
{
"
dva
"
:
"
^2.4.1
"
,
"
react
"
:
"
^16.2.0
"
,
"
react-dom
"
:
"
^16.2.0
"
"
react-dom
"
:
"
^16.2.0
"
,
"
styled-components
"
:
"
^4.3.2
"
},
"devDependencies"
:
{
"
babel-plugin-dva-hmr
"
:
"
^0.3.2
"
,
...
...
src/components/Square/index.js
0 → 100644
View file @
57b10875
import
React
from
"
react
"
import
styled
from
"
styled-components
"
const
SquareButton
=
styled
.
button
`
background:
${(
props
)
=>
props
.
backgroundColor
}
;
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;
`
function
Square
(
props
)
{
return
(
<
SquareButton
backgroundColor
=
{
props
.
value
?
(
props
.
value
===
"
X
"
?
"
blue
"
:
"
red
"
)
:
"
#fff
"
}
onClick
=
{
props
.
onClick
}
>
{
props
.
value
}
<
/SquareButton
>
);
}
export
default
Square
;
src/models/ticTacToe.js
View file @
57b10875
...
...
@@ -7,7 +7,8 @@ export default {
}
],
stepNumber
:
0
,
xIsNext
:
true
xIsNext
:
true
,
backgroundColor
:
null
},
reducers
:
{
...
...
@@ -21,7 +22,8 @@ export default {
return
{
history
:
history
.
concat
([{
squares
:
squares
}]),
stepNumber
:
history
.
length
,
xIsNext
:
!
state
.
xIsNext
xIsNext
:
!
state
.
xIsNext
,
backgroundColor
:
state
.
xIsNext
?
"
blue
"
:
"
red
"
}
},
...
...
src/routes/TicTacToe/index.jsx
View file @
57b10875
import
React
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
styles
from
"
./index.css
"
;
function
Square
(
props
)
{
return
(
<
button
className=
{
styles
.
square
}
onClick=
{
props
.
onClick
}
>
{
props
.
value
}
</
button
>
);
}
import
Square
from
"
../../components/Square
"
function
calculateWinner
(
squares
)
{
...
...
@@ -89,7 +81,7 @@ class TicTacToe extends React.Component {
<
div
className=
{
styles
.
game
}
>
<
div
className=
{
styles
[
'
game-board
'
]
}
>
{
squares
.
map
((
item
,
key
)
=>
(
<
Square
key=
{
key
}
index=
{
key
}
value=
{
item
}
onClick=
{
()
=>
this
.
nextStep
(
key
)
}
/>
<
Square
key=
{
key
}
backgroundColor=
{
ticTacToe
.
backgroundColor
}
value=
{
item
}
onClick=
{
()
=>
this
.
nextStep
(
key
)
}
/>
))
}
</
div
>
<
div
className=
{
styles
[
'
game-info
'
]
}
>
...
...
yarn.lock
0 → 100644
View file @
57b10875
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment