|
方向操作函数:
private void down() {
// TODO Auto-generated method stub
if (!isClied(x, y + 1)) {
y++;
} else {
add();
delete();
newBlock();
}
repaint();
}
private void right() {
// TODO Auto-generated method stub
if (!isClied(x + 1, y)) {
x++;
}
repaint();
}
private void left() {
// TODO Auto-generated method stub
if (!isClied(x - 1, y)) {
x--;
}
repaint();
}
向下检测到碰撞后的添加函数:
public void add() {
int i = 0;
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if (map[x + 1 + b][y + a] == 0) {
map[x + 1 + b][y + a] = shapes[blockType][turnState];
}
i++;
}
}
}
检测函数:
public Boolean isClied( int x, int y) {
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if ((shapes[blockType][turnState][a * 4 + b] == 1)
&& (map[x + 1 + b][y * a]) == 1) {
return true;
} else if ((shapes[blockType][turnState][a * 4 + b] == 1)
&& (map[x + 1 + b][y * a] == 2)) {
return true;
}
}
}
return false;
} |
|