コード例 #1
0
  private void keyPressesForPlayer3(KeyEvent ke, Snake snake) {
    if (ke.getKeyCode() == KeyEvent.VK_I) {
      if (snake.getDirection() != 2) {
        snake.setDirection(0);
      }
    }

    if (ke.getKeyCode() == KeyEvent.VK_J) {
      if (snake.getDirection() != 1) {
        snake.setDirection(3);
      }
    }

    if (ke.getKeyCode() == KeyEvent.VK_K) {
      if (snake.getDirection() != 0) {
        snake.setDirection(2);
      }
    }
    if (ke.getKeyCode() == KeyEvent.VK_L) {
      if (snake.getDirection() != 3) {
        snake.setDirection(1);
      }
    }
  }
コード例 #2
0
  private void keyPressesForPlayer1(KeyEvent ke, Snake snake) {
    if (ke.getKeyCode() == KeyEvent.VK_UP) {
      if (snake.getDirection() != 2) {
        snake.setDirection(0);
      }
    }

    if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
      if (snake.getDirection() != 1) {
        snake.setDirection(3);
      }
    }

    if (ke.getKeyCode() == KeyEvent.VK_DOWN) {
      if (snake.getDirection() != 0) {
        snake.setDirection(2);
      }
    }
    if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
      if (snake.getDirection() != 3) {
        snake.setDirection(1);
      }
    }
  }