Skip to content

A simple Pacman clone made with Java Swing for learning purposes. Move Pacman with arrow keys, avoid ghosts, and collect food pellets. Not a full-featured Pacman, just a basic demo using JPanel.

Notifications You must be signed in to change notification settings

nikunj-kohli/Pacman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Pacman (Java Swing Version)

This is a simple Pacman clone made as a learning project using Java and JPanel.
It is not a full-featured Pacman game, but a basic attempt to recreate some of the gameplay using Java Swing.

Features

  • Basic Pacman movement with arrow keys
  • Four ghosts with random movement
  • Food pellets to collect
  • Score and lives tracking
  • Game over and restart functionality

Technologies Used

  • Java (JDK 8+)
  • Java Swing (JPanel, JFrame, Timer)
  • Custom image assets for Pacman, ghosts, and walls

How to Play

  1. Requirements:

    • Java JDK installed (version 8 or higher)
  2. Compile the code:
    Open a terminal in the src directory and run:

    javac App.java Pacman.java
    
  3. Run the game:

    java App
    
  4. Controls:

    • Use the arrow keys to move Pacman.
    • Collect all the food pellets to win.
    • Avoid the ghosts. If you lose all lives, the game is over.
    • Press any arrow key after game over to restart.

Note

This project is a simple try and not as good as the real Pacman game you may have played.
It was made for learning purposes using only Java and basic Swing components.


Technical Details

  • The game board is defined by a string array (tileMap), where each character represents a wall, food, ghost, or Pacman.
  • The main game logic is handled in the Pacman class, which extends JPanel and uses a javax.swing.Timer for the game loop.
  • All game objects (Pacman, ghosts, walls, food) are represented as instances of an inner Block class.
  • Movement and collision detection are handled manually in the code.
  • Ghosts move randomly and change direction when hitting a wall.
  • The game is rendered by overriding paintComponent(Graphics g) and drawing all elements each frame.
  • Keyboard input is handled with the KeyListener interface to control Pacman and restart the game after game over.

Enjoy!

About

A simple Pacman clone made with Java Swing for learning purposes. Move Pacman with arrow keys, avoid ghosts, and collect food pellets. Not a full-featured Pacman, just a basic demo using JPanel.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages