Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Pacman Game

A simple Pacman game built with Python and Tkinter. No external dependencies required!

📋 Features

  • Classic Pacman gameplay with maze navigation
  • Arrow key controls for smooth movement
  • Three ghosts with basic AI (random movement and chase behavior)
  • Pellet collection for scoring points
  • Collision detection with walls and ghosts
  • Win/Lose conditions with restart functionality
  • Score tracking displayed in real-time

🎯 How to Play

Controls

  • Arrow Keys (↑ ↓ ← →): Move Pacman
  • Spacebar: Restart game (after game over or win)

Objective

  • Collect all the yellow pellets (dots) in the maze
  • Avoid the colored ghosts (red, pink, cyan)
  • Score 10 points for each pellet collected

Game Rules

  • Win: Collect all pellets in the maze
  • Lose: Get caught by a ghost
  • Pacman cannot move through walls (blue blocks)

🚀 Running the Game

Prerequisites

  • Python 3.x (Tkinter is included with standard Python installation)

Steps to Run

  1. Navigate to the game directory:

    cd pacman_game
  2. Run the game:

    python pacman.py

    Or on some systems:

    python3 pacman.py
  3. Start playing! Use arrow keys to move Pacman around the maze.

🎨 Game Elements

  • Yellow Circle 🟡 - Pacman (you!)
  • Blue Blocks 🟦 - Walls (cannot pass through)
  • Yellow Dots ⚫ - Pellets (collect for points)
  • Red Circle 🔴 - Ghost #1
  • Pink Circle 🩷 - Ghost #2
  • Cyan Circle 🔵 - Ghost #3

🎓 Learning Points

This game demonstrates several programming concepts:

  • Object-Oriented Programming: Classes for Pacman, Ghost, and Game
  • Game Loop: Continuous update and render cycle
  • Collision Detection: Checking for wall and ghost collisions
  • Event Handling: Keyboard input processing
  • 2D Grid System: Maze representation using a matrix
  • Basic AI: Ghost movement algorithms

🔧 Customization

You can easily customize the game by modifying these constants in pacman.py:

CELL_SIZE = 30          # Size of each grid cell
GRID_WIDTH = 20         # Maze width
GRID_HEIGHT = 20        # Maze height
GAME_SPEED = 150        # Game speed in milliseconds (lower = faster)

You can also modify the MAZE layout to create your own custom levels!

📝 Code Structure

pacman.py
├── Constants (colors, sizes, maze layout)
├── Pacman class (player character)
├── Ghost class (enemy AI)
├── PacmanGame class (main game logic)
└── main() function (entry point)

🐛 Troubleshooting

Issue: "No module named 'tkinter'"

  • Solution: Tkinter should come with Python. If missing, install it:
    • Ubuntu/Debian: sudo apt-get install python3-tk
    • macOS: Tkinter is included with Python from python.org
    • Windows: Tkinter is included with standard Python installation

Issue: Game runs too fast or too slow

  • Solution: Adjust the GAME_SPEED constant in the code (higher = slower)

🎉 Enjoy!

Have fun playing Pacman! Try to beat your high score and see how long you can survive against the ghosts.


Created with Python + Tkinter | No external dependencies required

About

Creation of a Pacman game with IBM Bob

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages