Class SnakeGame

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class SnakeGame extends JFrame
The SnakeGame class is the main entry point for the Snake game. It creates the game window, initializes the UI components, and handles game transitions between the home screen and the game panel.
Version:
1.0.0
Author:
Anurag Zete
See Also:
  • Field Details

    • width

      public static final int width
      The width of the game window.
      See Also:
    • height

      public static final int height
      The height of the game window.
      See Also:
    • homePanel

      public static HomePanel homePanel
      The home panel displaying the main menu.
    • gamePanel

      public static GamePanel gamePanel
      The game panel displaying the snake game.
    • scoreBoard

      public static JLabel scoreBoard
      The scoreboard label showing the player's score.
  • Constructor Details

    • SnakeGame

      public SnakeGame()
      Constructs the Snake game window, setting its properties and initializing the GUI components.
  • Method Details

    • createGUI

      private void createGUI()
      Creates and initializes the GUI components, including the scoreboard, home panel, and game panel.
    • main

      public static void main(String[] args)
      The main method that launches the Snake game using Swing's event-dispatch thread.
      Parameters:
      args - The command-line arguments (not used).
    • startGame

      public static void startGame()
      Starts the game by switching from the home panel to the game panel. It removes the home screen, adds the game screen, and starts the game loop.
    • exitGame

      public static void exitGame()
      Exits the game by terminating the application.