Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chess-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
佚名
chess-game
Commits
088d4945
Commit
088d4945
authored
Jul 18, 2019
by
佚名
🎅🏼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: bugs
parent
f2e984ad
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
17696 deletions
+24
-17696
package-lock.json
package-lock.json
+0
-17653
style.js
src/components/style.js
+1
-1
game.js
src/models/game.js
+2
-22
Game.js
src/routes/Game.js
+1
-20
example.js
src/services/example.js
+20
-0
No files found.
package-lock.json
deleted
100644 → 0
View file @
f2e984ad
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/components/style.js
View file @
088d4945
...
...
@@ -14,7 +14,7 @@ export const Button = styled.button`
font-weight: bold;
text-align: center;
&:focus {
outline: none
outline: none
;
}
&.blue {
background: blue;
...
...
src/models/game.js
View file @
088d4945
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
}
}
},
...
...
src/routes/Game.js
View file @
088d4945
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
);
...
...
src/services/example.js
View file @
088d4945
...
...
@@ -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
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