我正在寫一個方法來處理俄羅斯方塊的方向,並且對編寫硬降落的邏輯感到困惑。只要按下某個鍵就會調用移動方法。俄羅斯方塊 - 修復硬降碰撞
public void move(Direction direction) {
if (canMove(direction)) {
switch (direction) {
case DOWN:
row = row + 1;
break;
case LEFT:
col = col - 1;
break;
case RIGHT:
col = col + 1;
break;
case DROP:
for(int i = row; i < Grid.HEIGHT; i ++){
if(!grid.isSet(i,col)){
row = row + 1;
}
}
break;
}
}
}
我的想法是找到最遠的開放空間,該塊可以硬降,它會重複下去行,直到它擊中的是空間很難下降。
編輯:這是我的canMove方法,我已經改變了我的情況下降,即時下降確實奏效,但是,使用下拉鍵時似乎存在碰撞問題。我不明白爲什麼
public boolean canMove(Direction direction) {
if (!ableToMove)
return false;
boolean move = true;
// if the given direction is blocked, we can't move
// remember to check the edges of the grid
switch (direction) {
case DOWN:
if (row == (Grid.HEIGHT - 1) || grid.isSet(row + 1, col))
move = false;
break;
case DROP:
if (row == (Grid.HEIGHT - 1) || grid.isSet(row + 1, col))
move = false;
break;
// currently doesn't support checking LEFT or RIGHT
// MODIFY so that it correctly returns if it can move left or right
case LEFT:
if (col == (0) || grid.isSet(row, col-1))
move = false;
break;
case RIGHT:
if (row == (Grid.WIDTH - 1) || grid.isSet(row, col+1))
move = false;
break;
}
return move;
}
正如有人所說,_(我沒聽他的名字,他刪除了他的崗位太快)_有你看這裏http://stackoverflow.com/questions/16592898/tetris-hard-drop-logic? – frederick99
是的,我有和不知道如何做到這一點在我的代碼 – tofokevin