-1
@Override
public void keyPressed(KeyEvent e) {
int i = e.getKeyCode();
if (i == KeyEvent.VK_A && direction != RIGHT && direction != DOWN && direction != UP)
direction = LEFT;
if (i == KeyEvent.VK_D && direction != LEFT && direction != UP && direction != DOWN)
direction = RIGHT;
if (i == KeyEvent.VK_W && direction != DOWN && direction != LEFT && direction != RIGHT)
direction = UP;
if (i == KeyEvent.VK_S && direction != UP && direction != LEFT && direction != RIGHT)
direction = DOWN;
if(i == KeyEvent.VK_SPACE)
if(over)
startGame();
else
paused = !paused;
}
你的問題是? – Abdelhak
正如我所看到的,你只允許改變你已經使用的方向。您將方向設置爲左側,方向不正確時,向下並向上 - >所以它已經離開了? –
嘗試添加一些括號{}以使您的代碼更清晰 – Abdelhak