最近在学java,在网上下了个俄罗斯方块的代码看,看到这里不懂了,这段函数是判断是否和墙或和以下落的方块碰撞的代码,大家帮忙看看,其中map[][]值为2时是墙,值为1是已经有方块占据了。map[][]两个下标为什么是x+b+1,y+a(x,y是方块起始坐标),shapes的第三维坐标为什么是a*4+b? public boolean blow(int x, int y, int BlockType, int TurnType){
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++){
if (((shapes[BlockType][TurnType][a * 4 + b] == 1) && (map[y+a][x+ b + 1] == 1))
|| ((shapes[BlockType][TurnType][a * 4 + b] == 1) && (map[y+a][x+ b + 1] == 2))){
return true;
}
}
}
return false;
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++){
if (((shapes[BlockType][TurnType][a * 4 + b] == 1) && (map[y+a][x+ b + 1] == 1))
|| ((shapes[BlockType][TurnType][a * 4 + b] == 1) && (map[y+a][x+ b + 1] == 2))){
return true;
}
}
}
return false;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货