修复游戏自动落下触发的方块不落下的 bug
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -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) {
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -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({
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -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']
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user