Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dva-JingZi-Game
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
Point 郑海洋
dva-JingZi-Game
Commits
d3ed529c
Commit
d3ed529c
authored
Jul 18, 2019
by
Point 郑海洋
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加胜利颜色
parent
b1c732b2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
144 additions
and
75 deletions
+144
-75
box.js
src/component/box.js
+9
-4
winImg.css
src/component/winImg.css
+43
-0
winImg.js
src/component/winImg.js
+19
-0
global.css
src/global.css
+0
-1
g.js
src/models/g.js
+15
-14
index.js
src/pages/index.js
+58
-56
No files found.
src/component/box.js
View file @
d3ed529c
import
styled
from
'
styled-components
'
;
import
WinImg
from
'
./winImg
'
;
const
Box
=
styled
.
div
`
background: #fff;
border: 1px solid #999;
...
...
@@ -16,7 +16,7 @@ const Box = styled.div `
function
BoxMaster
(
props
)
{
const
handelClick
=
(
value
)
=>
{
// 判断游戏是否有胜利者
if
(
props
.
winer
)
return
if
(
props
.
win
n
er
)
return
// 判断是否重复点击
if
(
!
reClick
(
value
))
{
// 更新整体
...
...
@@ -48,8 +48,13 @@ function BoxMaster(props) {
return
(
<
Box
onClick
=
{
()
=>
handelClick
(
props
)}
style
=
{{
background
:
props
.
color
}}
>
{
props
.
flag
}
<
Box
onClick
=
{
()
=>
handelClick
(
props
)}
style
=
{{
background
:
props
.
winner
&&
props
.
value
===
props
.
winner
.
value
?
""
:
props
.
color
}}
>
{
props
.
winner
&&
props
.
value
===
props
.
winner
.
value
?
(
<
WinImg
flag
=
{
props
.
flag
}
/
>
)
:
(
<
span
>
{
props
.
flag
}
<
/span>
)
}
<
/Box
>
)
}
...
...
src/component/winImg.css
0 → 100644
View file @
d3ed529c
.winCss
{
font-size
:
14px
;
animation
:
winAnimation
2s
infinite
;
-moz-animation
:
winAnimation
2s
infinite
;
/* Firefox */
-webkit-animation
:
winAnimation
2s
infinite
;
/* Safari 和 Chrome */
-o-animation
:
winAnimation
2s
infinite
;
/* Opera */
}
@keyframes
winAnimation
{
0
%
{
background
:
red
;}
25
%
{
background
:
yellow
;}
50
%
{
background
:
blue
;}
75
%
{
background
:
green
;}
100
%
{
background
:
white
;}
}
@-moz-keyframes
winAnimation
/* Firefox */
{
0
%
{
background
:
red
;}
25
%
{
background
:
yellow
;}
50
%
{
background
:
blue
;}
75
%
{
background
:
green
;}
100
%
{
background
:
white
;}
}
@-webkit-keyframes
winAnimation
/* Safari 和 Chrome */
{
0
%
{
background
:
red
;}
25
%
{
background
:
yellow
;}
50
%
{
background
:
blue
;}
75
%
{
background
:
green
;}
100
%
{
background
:
white
;}
}
@-o-keyframes
winAnimation
/* Opera */
{
0
%
{
background
:
red
;}
25
%
{
background
:
yellow
;}
50
%
{
background
:
blue
;}
75
%
{
background
:
green
;}
100
%
{
background
:
white
;}
}
src/component/winImg.js
0 → 100644
View file @
d3ed529c
import
React
,{
Component
}
from
'
react
'
;
import
style
from
'
./winImg.css
'
;
export
default
class
WinImg
extends
Component
{
constructor
(
props
)
{
super
(
props
)
}
render
(){
const
{
flag
}
=
this
.
props
return
(
<
div
className
=
{
style
.
winCss
}
>
<
span
>
winner
is
{
flag
}
<
/span
>
<
/div
>
)
}
}
src/global.css
View file @
d3ed529c
...
...
@@ -6,4 +6,3 @@ html, body, #root {
body
{
margin
:
0
;
}
src/models/g.js
View file @
d3ed529c
export
default
{
namespace
:
'
main
'
,
state
:
{
now
f
lag
:
"
X
"
,
now
F
lag
:
"
X
"
,
list
:
[{
value
:
1
,
flag
:
null
,
...
...
@@ -31,7 +31,7 @@ export default {
flag
:
null
,
}],
actionData
:
[],
winer
:
null
,
win
n
er
:
null
,
goBackKey
:
null
},
reducers
:
{
...
...
@@ -39,7 +39,7 @@ export default {
const
{
tempFlag
}
=
action
.
payload
return
{
...
state
,
now
f
lag
:
tempFlag
,
now
F
lag
:
tempFlag
,
}
},
updateSelectOne
(
state
,
action
)
{
...
...
@@ -63,15 +63,15 @@ export default {
...
state
,
list
:
tempData
,
actionData
:
tempActionData
,
now
f
lag
:
tempNowFlag
,
now
F
lag
:
tempNowFlag
,
goBackKey
:
goBackKey
}
},
updateWiner
(
state
,
action
)
{
const
{
winer
}
=
action
.
payload
updateWin
n
er
(
state
,
action
)
{
const
{
win
n
er
}
=
action
.
payload
return
{
...
state
,
win
er
:
wi
ner
,
win
ner
:
win
ner
,
goBackKey
:
null
}
}
...
...
@@ -137,7 +137,7 @@ export default {
},
// 回退操作
*
updateRenderDataFn
({
f
lag
,
booleanF
lag
,
key
,
actionData
,
},
{
...
...
@@ -146,12 +146,13 @@ export default {
select
})
{
const
tempList
=
yield
select
(
state
=>
state
.
main
.
list
)
let
tempNowFlag
=
yield
select
(
state
=>
state
.
main
.
now
f
lag
)
let
tempNowFlag
=
yield
select
(
state
=>
state
.
main
.
now
F
lag
)
let
tempActionDataList
=
JSON
.
parse
(
JSON
.
stringify
(
actionData
))
let
tempData
=
[]
let
tempActionData
=
[]
let
goBackKey
=
null
if
(
!
flag
)
{
// 如果点击的不是重玩
if
(
!
booleanFlag
)
{
let
index
=
tempActionDataList
.
findIndex
((
item
,
index
)
=>
{
return
item
.
key
===
key
})
...
...
@@ -177,16 +178,16 @@ export default {
})
},
// 更新获胜者
*
updateWinerFn
({
winer
*
updateWin
n
erFn
({
win
n
er
},
{
call
,
put
,
select
})
{
yield
put
({
type
:
"
updateWiner
"
,
payload
:{
winer
}
type
:
"
updateWin
n
er
"
,
payload
:{
win
n
er
}
})
}
},
...
...
src/pages/index.js
View file @
d3ed529c
...
...
@@ -10,21 +10,22 @@ import {
function
Main
({
dispatch
,
list
,
now
f
lag
,
now
F
lag
,
actionData
,
winer
win
n
er
})
{
useEffect
(()
=>
{
if
(
winer
)
return
// 如果有胜利者就不执行判断胜负方法
if
(
win
n
er
)
return
// 如果有胜利者就不执行判断胜负方法
let
twoDArry
=
renderArry
(
list
)
if
(
!
twoDArry
)
return
let
reData
=
checkWin
(
twoDArry
)
console
.
log
(
"
reData
"
,
reData
)
if
(
reData
&&
reData
.
status
===
'
win
'
)
{
dispatch
({
type
:
"
main/updateWinerFn
"
,
win
er
:
reData
.
wi
ner
type
:
"
main/updateWin
n
erFn
"
,
win
ner
:
reData
.
win
ner
})
}
...
...
@@ -48,132 +49,133 @@ function Main({
if
(
twoDArry
[
0
][
0
].
flag
!=
null
&&
twoDArry
[
0
][
1
].
flag
!=
null
&&
twoDArry
[
0
][
2
].
flag
!=
null
&&
twoDArry
[
0
][
0
].
flag
===
twoDArry
[
0
][
1
].
flag
&&
twoDArry
[
0
][
1
].
flag
===
twoDArry
[
0
][
2
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
0
]
win
n
er
:
twoDArry
[
0
][
0
]
}
}
// 判断第二行
if
(
twoDArry
[
1
][
0
].
flag
!=
null
&&
twoDArry
[
1
][
1
].
flag
!=
null
&&
twoDArry
[
1
][
2
].
flag
!=
null
&&
twoDArry
[
1
][
0
].
flag
===
twoDArry
[
1
][
1
].
flag
&&
twoDArry
[
1
][
1
].
flag
===
twoDArry
[
1
][
2
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
1
][
0
]
win
n
er
:
twoDArry
[
1
][
0
]
}
}
// 判断第三行
if
(
twoDArry
[
2
][
0
].
flag
!=
null
&&
twoDArry
[
2
][
1
].
flag
!=
null
&&
twoDArry
[
2
][
2
].
flag
!=
null
&&
twoDArry
[
2
][
0
].
flag
===
twoDArry
[
2
][
1
].
flag
&&
twoDArry
[
2
][
1
].
flag
===
twoDArry
[
2
][
2
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
2
][
0
]
win
n
er
:
twoDArry
[
2
][
0
]
}
}
// 判断第一列
if
(
twoDArry
[
0
][
0
].
flag
!=
null
&&
twoDArry
[
1
][
0
].
flag
!=
null
&&
twoDArry
[
2
][
0
].
flag
!=
null
&&
twoDArry
[
0
][
0
].
flag
===
twoDArry
[
1
][
0
].
flag
&&
twoDArry
[
1
][
0
].
flag
===
twoDArry
[
2
][
0
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
0
]
win
n
er
:
twoDArry
[
0
][
0
]
}
}
// 判断第二列
if
(
twoDArry
[
0
][
1
].
flag
!=
null
&&
twoDArry
[
1
][
1
].
flag
!=
null
&&
twoDArry
[
2
][
1
].
flag
!=
null
&&
twoDArry
[
0
][
1
].
flag
===
twoDArry
[
1
][
1
].
flag
&&
twoDArry
[
1
][
1
].
flag
===
twoDArry
[
2
][
1
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
1
]
win
n
er
:
twoDArry
[
0
][
1
]
}
}
// 判断第三列
if
(
twoDArry
[
0
][
2
].
flag
!=
null
&&
twoDArry
[
1
][
2
].
flag
!=
null
&&
twoDArry
[
2
][
2
].
flag
!=
null
&&
twoDArry
[
0
][
2
].
flag
===
twoDArry
[
1
][
2
].
flag
&&
twoDArry
[
1
][
2
].
flag
===
twoDArry
[
2
][
2
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
2
]
win
n
er
:
twoDArry
[
0
][
2
]
}
}
// 判断交叉左上角到右下角
if
(
twoDArry
[
0
][
0
].
flag
!=
null
&&
twoDArry
[
1
][
1
].
flag
!=
null
&&
twoDArry
[
2
][
2
].
flag
!=
null
&&
twoDArry
[
0
][
0
].
flag
===
twoDArry
[
1
][
1
].
flag
&&
twoDArry
[
1
][
1
].
flag
===
twoDArry
[
2
][
2
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
0
]
win
n
er
:
twoDArry
[
0
][
0
]
}
}
// 判断交叉右上角到左下角
if
(
twoDArry
[
0
][
2
].
flag
!=
null
&&
twoDArry
[
1
][
1
].
flag
!=
null
&&
twoDArry
[
2
][
0
].
flag
!=
null
&&
twoDArry
[
0
][
2
].
flag
===
twoDArry
[
1
][
1
].
flag
&&
twoDArry
[
1
][
1
].
flag
===
twoDArry
[
2
][
0
].
flag
)
{
return
{
status
:
'
win
'
,
winer
:
twoDArry
[
0
][
2
]
win
n
er
:
twoDArry
[
0
][
2
]
}
}
}
function
handleChangeData
(
f
lag
,
key
,
actionData
)
{
function
handleChangeData
(
booleanF
lag
,
key
,
actionData
)
{
dispatch
({
type
:
'
main/updateWinerFn
'
,
winer
:
null
type
:
'
main/updateWin
n
erFn
'
,
win
n
er
:
null
})
dispatch
({
type
:
'
main/updateRenderDataFn
'
,
key
:
key
,
actionData
:
actionData
,
flag
:
f
lag
,
booleanFlag
:
booleanF
lag
,
})
}
return
(
<
div
>
<
div
className
=
{
styles
.
content
}
>
{
list
.
map
((
item
,
index
)
=>
{
let
colorStr
=
item
.
flag
===
'
X
'
?
'
blue
'
:
item
.
flag
===
'
O
'
?
'
red
'
:
''
return
(
<
Box
key
=
{
item
.
value
}
value
=
{
item
.
value
}
nowFliage
=
{
nowflag
}
dispatch
=
{
dispatch
}
datasource
=
{
list
}
flag
=
{
item
.
flag
}
actionData
=
{
actionData
}
winer
=
{
winer
}
color
=
{
colorStr
}
/
>
)
})
}
<
/div
>
<
div
className
=
{
styles
.
rightBox
}
>
{
winer
?
<
p
>
Winer
is
{
winer
.
flag
}
<
/p> : <p> Next player: {nowflag }</
p
>
}
<
ul
>
<
li
>
<
button
onClick
=
{()
=>
handleChangeData
(
true
,
false
,
false
)}
>
Go
to
Game
Start
<
/button
>
<
/li
>
<
div
>
<
div
className
=
{
styles
.
content
}
>
{
actionData
.
map
((
item
,
index
)
=>
{
list
.
map
((
item
,
index
)
=>
{
let
colorStr
=
item
.
flag
===
'
X
'
?
'
blue
'
:
item
.
flag
===
'
O
'
?
'
red
'
:
''
return
(
<
li
key
=
{
item
.
key
}
value
=
{
item
.
key
}
>
<
button
className
=
{
styles
.
numLi
}
onClick
=
{()
=>
handleChangeData
(
false
,
item
.
key
,
actionData
)}
>
Go
to
move
#
{
index
+
1
}
<
/button
>
<
/li
>
<
Box
key
=
{
item
.
value
}
value
=
{
item
.
value
}
nowFliage
=
{
nowFlag
}
dispatch
=
{
dispatch
}
datasource
=
{
list
}
flag
=
{
item
.
flag
}
actionData
=
{
actionData
}
winner
=
{
winner
}
color
=
{
colorStr
}
/
>
)
})
}
<
/div
>
<
div
className
=
{
styles
.
rightBox
}
>
{
winner
?
<
p
>
winner
is
{
winner
.
flag
}
<
/p> : <p> Next player: {nowFlag}</
p
>
}
<
ul
>
<
li
>
<
button
onClick
=
{()
=>
handleChangeData
(
true
,
false
,
false
)}
>
Go
to
Game
Start
<
/button
>
<
/li
>
{
actionData
.
map
((
item
,
index
)
=>
{
return
(
<
li
key
=
{
item
.
key
}
value
=
{
item
.
key
}
>
<
button
className
=
{
styles
.
numLi
}
onClick
=
{()
=>
handleChangeData
(
false
,
item
.
key
,
actionData
)}
>
Go
to
move
#
{
index
+
1
}
<
/button
>
<
/li
>
)
})
}
<
/ul
>
<
/div
>
<
/div
>
<
/div
>
);
}
function
mapStateToProps
(
state
)
{
const
{
now
f
lag
,
now
F
lag
,
list
,
actionData
,
winer
win
n
er
}
=
state
.
main
;
return
{
now
f
lag
,
now
F
lag
,
list
,
actionData
,
winer
win
n
er
};
}
...
...
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