1
0
mirror of synced 2025-12-19 21:48:02 +08:00

修复游戏自动落下触发的方块不落下的 bug

This commit is contained in:
binaryify
2017-06-13 14:04:21 +08:00
parent 49147eb4cf
commit 5a565dce2b
4 changed files with 25 additions and 21 deletions

View File

@@ -82,18 +82,17 @@ const states = {
store.commit('moveBlock', next) store.commit('moveBlock', next)
states.fallInterval = setTimeout(fall, speeds[state.speedRun - 1]) states.fallInterval = setTimeout(fall, speeds[state.speedRun - 1])
} else { } else {
let matrix = state.matrix let matrix = fromJS(state.matrix)
const shape = cur && cur.shape 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) => shape.forEach((m, k1) =>
m.forEach((n, k2) => { m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) { if (n && xy.get(0) + k1 >= 0) {
// 竖坐标可以为负 // 竖坐标可以为负
let line = matrix[xy[0] + k1] let line = matrix.get(xy.get(0) + k1)
line[xy[1] + k2] = 1 line = line.set(xy.get(1) + k2, 1)
// line = line.set(xy[1] + k2, 1) matrix = matrix.set(xy.get(0) + k1, line)
matrix[xy[0] + k1] = line
// matrix = matrix.set(xy[0] + k1, line)
} }
}) })
) )

View File

@@ -2,6 +2,7 @@ import { want } from '../../unit/'
import event from '../../unit/event' import event from '../../unit/event'
import states from '../states' import states from '../states'
import { music } from '../../unit/music' import { music } from '../../unit/music'
import { fromJS, List } from 'immutable'
const down = store => { const down = store => {
store.commit('key_down', true) store.commit('key_down', true)
if (store.state.cur !== null) { if (store.state.cur !== null) {
@@ -31,18 +32,17 @@ const down = store => {
// store.dispatch(actions.moveBlock(next)); // store.dispatch(actions.moveBlock(next));
states.auto() states.auto()
} else { } else {
let matrix = state.matrix let matrix = fromJS(state.matrix)
const shape = cur.shape const shape = cur.shape
const xy = cur.xy const xy = fromJS(cur.xy)
console.log({ matrix, shape, xy })
shape.forEach((m, k1) => shape.forEach((m, k1) =>
m.forEach((n, k2) => { m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) { if (n && xy.get(0) + k1 >= 0) {
// 竖坐标可以为负 // 竖坐标可以为负
let line = matrix[xy[0] + k1] let line = matrix.get(xy.get(0) + k1)
// line = line.set(xy[1] + k2, 1); line = line.set(xy.get(1) + k2, 1)
line[xy[1] + k2] = 1 matrix = matrix.set(xy.get(0) + k1, line)
matrix[xy[0] + k1] = line
// matrix = matrix.set(xy[0] + k1, line);
} }
}) })
) )

View File

@@ -2,6 +2,7 @@ import { want } from '../../unit/'
import event from '../../unit/event' import event from '../../unit/event'
import states from '../states' import states from '../states'
import { music } from '../../unit/music' import { music } from '../../unit/music'
import { fromJS, List } from 'immutable'
const down = store => { const down = store => {
store.commit('key_drop', true) store.commit('key_drop', true)
event.down({ event.down({
@@ -28,7 +29,7 @@ const down = store => {
bottom = cur.fall(index) bottom = cur.fall(index)
index++ index++
} }
let matrix = state.matrix let matrix = fromJS(state.matrix)
bottom = cur.fall(index - 2) bottom = cur.fall(index - 2)
store.commit('moveBlock', bottom) store.commit('moveBlock', bottom)
const shape = bottom.shape const shape = bottom.shape
@@ -37,9 +38,9 @@ const down = store => {
m.forEach((n, k2) => { m.forEach((n, k2) => {
if (n && xy[0] + k1 >= 0) { if (n && xy[0] + k1 >= 0) {
// 竖坐标可以为负 // 竖坐标可以为负
let line = matrix[xy[0] + k1] let line = matrix.get(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)
} }
}) })
) )

View File

@@ -1,5 +1,5 @@
import { blockType, StorageKey } from './const' import { blockType, StorageKey } from './const'
import { fromJS } from 'immutable' import { fromJS, List } from 'immutable'
const hiddenProperty = (() => { const hiddenProperty = (() => {
// document[hiddenProperty] 可以判断页面是否失焦 // document[hiddenProperty] 可以判断页面是否失焦
let names = ['hidden', 'webkitHidden', 'mozHidden', 'msHidden'] let names = ['hidden', 'webkitHidden', 'mozHidden', 'msHidden']
@@ -61,6 +61,10 @@ const unit = {
}, },
isOver(matrix) { isOver(matrix) {
// 游戏是否结束, 第一行落下方块为依据 // 游戏是否结束, 第一行落下方块为依据
// console.log(matrix)
if (List.isList(matrix)) {
matrix = matrix.toJS()
}
return matrix[0].some(n => !!n) return matrix[0].some(n => !!n)
}, },
subscribeRecord(store) { subscribeRecord(store) {