Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pac-Man Game

This is a Pac-Man game implementation. The project is an extension of the given scaffold code, adding new features and enhancements to the game.


Table of Contents


How to Run

  1. Prerequisites: Ensure that you have Java installed on your system.
  2. Build Tool: This project uses Gradle for build management. Ensure you have Gradle installed, or use the Gradle wrapper included (gradle clean build run for Linux/MacOS, gradlew.bat for Windows).
  3. Running the Project:
    • Clone the repository or download the files.
    • Navigate to the project root directory.
    • Use the following command to run the project:
      ./gradle clean build run
    • Alternatively, if using an IDE, import the project as a Gradle project and run App.java in the pacman.view package.

Design Patterns

Factory Pattern

  • Files: GhostFactory.java, PacmanFactory.java, WallFactory.java, PelletFactory.java, RenderableFactoryRegistryImpl.java
  • Purpose: The Factory Pattern is used to create instances of various game entities (Pac-Man, Ghosts, Walls, Pellets) dynamically without modifying the core code structure.

Strategy Pattern

  • Files: ChaseStrategy.java, ScatterStrategy.java, BlinkyChaseStrategy.java, PinkyChaseStrategy.java, etc.
  • Purpose: The Strategy Pattern allows for flexible behavior of ghosts by switching between different chase and scatter strategies.

State Pattern

  • Files: GhostState.java, ScatterState.java, ChaseState.java, FrightenedState.java
  • Purpose: Manages the behavior of ghosts depending on their current state (chase, scatter, frightened) to dynamically change behavior without altering the core logic.

Observer Pattern

  • Files: GameStateObserver.java, LevelStateObserver.java, GameEngineImpl.java, DisplayManager.java, LevelImpl.java
  • Purpose: Allows different parts of the game (like score display and game state) to stay in sync by observing changes in game state and level state.

Command Pattern

  • Files: MoveCommand.java, MoveUpCommand.java, MoveDownCommand.java, KeyboardInputHandler.java
  • Purpose: Decouples input handling from action execution by encapsulating movement commands, allowing for flexible input handling.

Decorator Pattern

  • Files: GhostDecorator.java, FrightenedGhostDecorator.java
  • Purpose: Adds new behavior to ghosts dynamically, like frightened behavior, without changing the underlying ghost structure.

File and Class Overview

  • App.java: The main entry point for running the game.
  • pacman.model: Contains core models and game logic, including the engine, entities, and level management.
    • engine: Manages game state and engine operations.
    • entity: Holds all entity-related classes, including Pac-Man, ghosts, and pellets.
    • factories: Contains factory classes for creating game entities.
    • level: Manages level-related logic and state.
    • observer: Implements observer interfaces for game and level states.
  • pacman.view: Contains view-related classes for rendering the game and handling user input.
    • KeyboardInputHandler.java: Manages player input via keyboard.
    • DisplayManager.java: Handles rendering of game elements on the screen.

Additional Notes

  • Quirks: If you encounter issues with file paths or resources not loading, make sure to run the project from the root directory where resources/maze is accessible.
  • Known Issues: The game currently assumes fixed screen dimensions, so resizing may affect display. Further extensions could involve adapting to dynamic screen sizes.
  • Future Improvements: Additional states for ghosts and enhancements in rendering are possible with minimal code changes, thanks to the use of design patterns.

About

Implementation of a Pac-Man game. Built with Java and Gradle, the project extends scaffold code with new features and robust design pattern usage. Key patterns include Factory, Strategy, State, Observer, Command, and Decorator, enabling modular game logic, flexible ghost behaviors, and dynamic gameplay improvements.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages