Skip to content

Commit 5a565dc

Browse files
author
binaryify
committed
修复游戏自动落下触发的方块不落下的 bug
1 parent 49147eb commit 5a565dc

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

src/control/states.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,17 @@ const states = {
8282
store.commit('moveBlock', next)
8383
states.fallInterval = setTimeout(fall, speeds[state.speedRun - 1])
8484
} else {
85-
let matrix = state.matrix
85+
let matrix = fromJS(state.matrix)
8686
const shape = cur && cur.shape
87-
const xy = cur && cur.xy
87+
const xy = fromJS(cur && cur.xy)
88+
console.log({ matrix, shape, xy })
8889
shape.forEach((m, k1) =>
8990
m.forEach((n, k2) => {
90-
if (n && xy[0] + k1 >= 0) {
91+
if (n && xy.get(0) + k1 >= 0) {
9192
// 竖坐标可以为负
92-
let line = matrix[xy[0] + k1]
93-
line[xy[1] + k2] = 1
94-
// line = line.set(xy[1] + k2, 1)
95-
matrix[xy[0] + k1] = line
96-
// matrix = matrix.set(xy[0] + k1, line)
93+
let line = matrix.get(xy.get(0) + k1)
94+
line = line.set(xy.get(1) + k2, 1)
95+
matrix = matrix.set(xy.get(0) + k1, line)
9796
}
9897
})
9998
)

src/control/todo/down.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { want } from '../../unit/'
22
import event from '../../unit/event'
33
import states from '../states'
44
import { music } from '../../unit/music'
5+
import { fromJS, List } from 'immutable'
56
const down = store => {
67
store.commit('key_down', true)
78
if (store.state.cur !== null) {
@@ -31,18 +32,17 @@ const down = store => {
3132
// store.dispatch(actions.moveBlock(next));
3233
states.auto()
3334
} else {
34-
let matrix = state.matrix
35+
let matrix = fromJS(state.matrix)
3536
const shape = cur.shape
36-
const xy = cur.xy
37+
const xy = fromJS(cur.xy)
38+
console.log({ matrix, shape, xy })
3739
shape.forEach((m, k1) =>
3840
m.forEach((n, k2) => {
39-
if (n && xy[0] + k1 >= 0) {
41+
if (n && xy.get(0) + k1 >= 0) {
4042
// 竖坐标可以为负
41-
let line = matrix[xy[0] + k1]
42-
// line = line.set(xy[1] + k2, 1);
43-
line[xy[1] + k2] = 1
44-
matrix[xy[0] + k1] = line
45-
// matrix = matrix.set(xy[0] + k1, line);
43+
let line = matrix.get(xy.get(0) + k1)
44+
line = line.set(xy.get(1) + k2, 1)
45+
matrix = matrix.set(xy.get(0) + k1, line)
4646
}
4747
})
4848
)

src/control/todo/space.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { want } from '../../unit/'
22
import event from '../../unit/event'
33
import states from '../states'
44
import { music } from '../../unit/music'
5+
import { fromJS, List } from 'immutable'
56
const down = store => {
67
store.commit('key_drop', true)
78
event.down({
@@ -28,7 +29,7 @@ const down = store => {
2829
bottom = cur.fall(index)
2930
index++
3031
}
31-
let matrix = state.matrix
32+
let matrix = fromJS(state.matrix)
3233
bottom = cur.fall(index - 2)
3334
store.commit('moveBlock', bottom)
3435
const shape = bottom.shape
@@ -37,9 +38,9 @@ const down = store => {
3738
m.forEach((n, k2) => {
3839
if (n && xy[0] + k1 >= 0) {
3940
// 竖坐标可以为负
40-
let line = matrix[xy[0] + k1]
41-
line[xy[1] + k2] = 1
42-
matrix[xy[0] + k1] = line
41+
let line = matrix.get(xy[0] + k1)
42+
line = line.set(xy[1] + k2, 1)
43+
matrix = matrix.set(xy[0] + k1, line)
4344
}
4445
})
4546
)

src/unit/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { blockType, StorageKey } from './const'
2-
import { fromJS } from 'immutable'
2+
import { fromJS, List } from 'immutable'
33
const hiddenProperty = (() => {
44
// document[hiddenProperty] 可以判断页面是否失焦
55
let names = ['hidden', 'webkitHidden', 'mozHidden', 'msHidden']
@@ -61,6 +61,10 @@ const unit = {
6161
},
6262
isOver(matrix) {
6363
// 游戏是否结束, 第一行落下方块为依据
64+
// console.log(matrix)
65+
if (List.isList(matrix)) {
66+
matrix = matrix.toJS()
67+
}
6468
return matrix[0].some(n => !!n)
6569
},
6670
subscribeRecord(store) {

0 commit comments

Comments
 (0)