老师判断游戏结束的方法有问题,假如你把方块全部放一边(左边角落或者右边角落),然后堆积到第二行时游戏就结束了,但讲道理只要方块还能落下来,游戏就没有结束,所以我完善了这个方法的逻辑判断,希望能帮到你
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
// 下移
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