Skip to content

Commit

Permalink
修复游戏自动落下触发的方块不落下的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryify committed Jun 13, 2017
1 parent 49147eb commit 5a565dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
15 changes: 7 additions & 8 deletions src/control/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ const states = {
store.commit('moveBlock', next)
states.fallInterval = setTimeout(fall, speeds[state.speedRun - 1])
} else {
let matrix = state.matrix
let matrix = fromJS(state.matrix)
const shape = cur && cur.shape
const xy = cur && cur.xy
const xy = fromJS(cur && cur.xy)
console.log({ matrix, shape, xy })
shape.forEach((m, k1) =>
m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) {
if (n && xy.get(0) + k1 >= 0) {
// 竖坐标可以为负
let line = matrix[xy[0] + k1]
line[xy[1] + k2] = 1
// line = line.set(xy[1] + k2, 1)
matrix[xy[0] + k1] = line
// matrix = matrix.set(xy[0] + k1, line)
let line = matrix.get(xy.get(0) + k1)
line = line.set(xy.get(1) + k2, 1)
matrix = matrix.set(xy.get(0) + k1, line)
}
})
)
Expand Down
16 changes: 8 additions & 8 deletions src/control/todo/down.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { want } from '../../unit/'
import event from '../../unit/event'
import states from '../states'
import { music } from '../../unit/music'
import { fromJS, List } from 'immutable'
const down = store => {
store.commit('key_down', true)
if (store.state.cur !== null) {
Expand Down Expand Up @@ -31,18 +32,17 @@ const down = store => {
// store.dispatch(actions.moveBlock(next));
states.auto()
} else {
let matrix = state.matrix
let matrix = fromJS(state.matrix)
const shape = cur.shape
const xy = cur.xy
const xy = fromJS(cur.xy)
console.log({ matrix, shape, xy })
shape.forEach((m, k1) =>
m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) {
if (n && xy.get(0) + k1 >= 0) {
// 竖坐标可以为负
let line = matrix[xy[0] + k1]
// line = line.set(xy[1] + k2, 1);
line[xy[1] + k2] = 1
matrix[xy[0] + k1] = line
// matrix = matrix.set(xy[0] + k1, line);
let line = matrix.get(xy.get(0) + k1)
line = line.set(xy.get(1) + k2, 1)
matrix = matrix.set(xy.get(0) + k1, line)
}
})
)
Expand Down
9 changes: 5 additions & 4 deletions src/control/todo/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { want } from '../../unit/'
import event from '../../unit/event'
import states from '../states'
import { music } from '../../unit/music'
import { fromJS, List } from 'immutable'
const down = store => {
store.commit('key_drop', true)
event.down({
Expand All @@ -28,7 +29,7 @@ const down = store => {
bottom = cur.fall(index)
index++
}
let matrix = state.matrix
let matrix = fromJS(state.matrix)
bottom = cur.fall(index - 2)
store.commit('moveBlock', bottom)
const shape = bottom.shape
Expand All @@ -37,9 +38,9 @@ const down = store => {
m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) {
// 竖坐标可以为负
let line = matrix[xy[0] + k1]
line[xy[1] + k2] = 1
matrix[xy[0] + k1] = line
let line = matrix.get(xy[0] + k1)
line = line.set(xy[1] + k2, 1)
matrix = matrix.set(xy[0] + k1, line)
}
})
)
Expand Down
6 changes: 5 additions & 1 deletion src/unit/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blockType, StorageKey } from './const'
import { fromJS } from 'immutable'
import { fromJS, List } from 'immutable'
const hiddenProperty = (() => {
// document[hiddenProperty] 可以判断页面是否失焦
let names = ['hidden', 'webkitHidden', 'mozHidden', 'msHidden']
Expand Down Expand Up @@ -61,6 +61,10 @@ const unit = {
},
isOver(matrix) {
// 游戏是否结束, 第一行落下方块为依据
// console.log(matrix)
if (List.isList(matrix)) {
matrix = matrix.toJS()
}
return matrix[0].some(n => !!n)
},
subscribeRecord(store) {
Expand Down

0 comments on commit 5a565dc

Please sign in to comment.