diff --git a/src/control/states.js b/src/control/states.js index fda0ff5..2bf7a14 100644 --- a/src/control/states.js +++ b/src/control/states.js @@ -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) } }) ) diff --git a/src/control/todo/down.js b/src/control/todo/down.js index e69a2b6..1c19e42 100644 --- a/src/control/todo/down.js +++ b/src/control/todo/down.js @@ -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) } }) ) diff --git a/src/control/todo/space.js b/src/control/todo/space.js index d4f7efc..11a6913 100644 --- a/src/control/todo/space.js +++ b/src/control/todo/space.js @@ -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) } }) ) diff --git a/src/unit/index.js b/src/unit/index.js index 44e301d..e3970d3 100644 --- a/src/unit/index.js +++ b/src/unit/index.js @@ -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) {