老师判断游戏结束的方法有问题,假如你把方块全部放一边(左边角落或者右边角落),然后堆积到第二行时游戏就结束了,但讲道理只要方块还能落下来,游戏就没有结束,所以我完善了这个方法的逻辑判断,希望能帮到你
2018-04-08
// 检查游戏结束
var checkOver = function(){
var gameOver = false;
for (var j=0; j<next.data.length; j++) {
for(var i=0; i<next.data[j].length; i++){
if(next.data[j][i] >= 1){
if(gameData[1][next.origin.x + i] == 1){
gameOver = true;
}
}
}
}
return gameOver;
}
var checkOver = function(){
var gameOver = false;
for (var j=0; j<next.data.length; j++) {
for(var i=0; i<next.data[j].length; i++){
if(next.data[j][i] >= 1){
if(gameData[1][next.origin.x + i] == 1){
gameOver = true;
}
}
}
}
return gameOver;
}
2018-04-08
最赞回答 / 慕粉3918152
肯定是你复制错了- = 你复制上面gameData[cur.origin.x + i][cur.origin.y + j] == 2然后没修改好直接写了gameData[cur.origin.x + i][cur.origin.y + j] == 1;正确写法是gameData[cur.origin.x + i][cur.origin.y + j] = 1;多了一个等号
2018-04-08
// 下移
var down = function(){
var posx = cloneObject(cur);
posx.origin.x = posx.origin.x + 1;
if(check(posx,cur)){
clearData();
cur.origin.x = cur.origin.x + 1;
setData();
}
refreshDiv(gameData,gameDivs);
}
var down = function(){
var posx = cloneObject(cur);
posx.origin.x = posx.origin.x + 1;
if(check(posx,cur)){
clearData();
cur.origin.x = cur.origin.x + 1;
setData();
}
refreshDiv(gameData,gameDivs);
}
2018-04-07