我正在尝试构建一个小游戏,其中有一个大网格。(10x20) 个空间和一个小网格 (3x3)。我想将小网格映射到大网格。
我必须能够为要放置的网格指定 ay/row 位置和 ax/cell 位置。
我怎样才能做到这一点?
例子:
small grid:
|0|1|0|
|1|1|1|
|0|1|0|
large grid
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
result:
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|1|0|0|0|0|0
|0|0|0|1|1|1|0|0|0|0
|0|0|0|0|1|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0
更新 游戏是俄罗斯方块。我检查了一个小网格(砖)不能从大网格边界中出来。
A brick holds:
X: cell position on the large grid
Y: row position on the large grid
Width: the width of the small grid
Height: the height of the small grid
Fields: the small grid where some fields are 0 (unmarked), and some are 1 (marked)
我尝试过这样的事情:但无法让它工作
for (var row = brick.y; row < brick.y + brick.height; row++) {
for (var cell = brick.x; cell < brick.x + brick.width; cell++) {
for (var fieldRow = 0; fieldRow < brick.type.fields.length; fieldRow++) {
for (var fieldCell = 0; fieldCell < brick.type.fields[fieldRow].length; fieldCell++) {
console.log(brick.type.fields[fieldRow][fieldCell]);
if (brick.type.fields[fieldRow][fieldCell] == 1) {
this.grid[row][cell] = 1;
}
}
}
}
}