Class GamePanel.MyKeyAdapter

java.lang.Object
java.awt.event.KeyAdapter
com.project.snakeGame.GamePanel.MyKeyAdapter
All Implemented Interfaces:
KeyListener, EventListener
Enclosing class:
GamePanel

public class GamePanel.MyKeyAdapter extends KeyAdapter
The MyKeyAdapter class handles keyboard inputs to control the snake's direction. It listens for arrow key presses and updates the snake's direction accordingly.
  • Constructor Details

    • MyKeyAdapter

      public MyKeyAdapter()
  • Method Details

    • keyPressed

      public void keyPressed(KeyEvent e)
      Listens for key presses and changes the snake's direction based on the arrow keys. Prevents the snake from moving in the opposite direction.
      Specified by:
      keyPressed in interface KeyListener
      Overrides:
      keyPressed in class KeyAdapter
      Parameters:
      e - The KeyEvent triggered by the key press.