{"id":23810561,"url":"https://github.com/nipuna-lakruwan/pacman-java-game","last_synced_at":"2026-04-28T00:30:18.068Z","repository":{"id":264009405,"uuid":"892078075","full_name":"Nipuna-Lakruwan/PacMan-Java-Game","owner":"Nipuna-Lakruwan","description":"The repository `Nipuna-Lakruwan/PacMan-Java-Game` contains a Java implementation of the classic Pac-Man game. The code is entirely written in Java, offering features and gameplay mechanics similar to the original arcade version.","archived":false,"fork":false,"pushed_at":"2024-11-21T13:29:06.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-02T00:15:50.782Z","etag":null,"topics":["java","jframe","pacman-game"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nipuna-Lakruwan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-21T13:23:57.000Z","updated_at":"2024-11-21T13:29:09.000Z","dependencies_parsed_at":"2024-11-21T14:38:20.147Z","dependency_job_id":null,"html_url":"https://github.com/Nipuna-Lakruwan/PacMan-Java-Game","commit_stats":null,"previous_names":["nipuna-lakruwan/pacman-java-game"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nipuna-Lakruwan%2FPacMan-Java-Game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nipuna-Lakruwan%2FPacMan-Java-Game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nipuna-Lakruwan%2FPacMan-Java-Game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nipuna-Lakruwan%2FPacMan-Java-Game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nipuna-Lakruwan","download_url":"https://codeload.github.com/Nipuna-Lakruwan/PacMan-Java-Game/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240063928,"owners_count":19742227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jframe","pacman-game"],"created_at":"2025-01-02T00:15:41.606Z","updated_at":"2026-04-28T00:30:17.998Z","avatar_url":"https://github.com/Nipuna-Lakruwan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PacMan Java Game\r\n\r\nA classic PacMan game implemented in Java using `JFrame` for the graphical user interface. This game features the main character, PacMan, navigating through a maze, collecting food, avoiding ghosts, and aiming to achieve the highest score possible.\r\n\r\n## Features\r\n\r\n- **PacMan Movement:** Use arrow keys (Up, Down, Left, Right) to control PacMan.\r\n- **Ghosts:** Four types of ghosts with different behaviors.\r\n- **Map Layout:** A 21x19 grid with walls, food, and ghosts.\r\n- **Score System:** Collect food to earn points. Lives decrease if PacMan collides with a ghost.\r\n- **Game Over:** The game ends when PacMan loses all lives.\r\n\r\n## Getting Started\r\n\r\n### Prerequisites\r\n\r\nMake sure you have Java installed on your system. You can download the latest version of Java from [here](https://www.oracle.com/java/technologies/javase-downloads.html).\r\n\r\n### Running the Game\r\n\r\n1. Clone this repository:\r\n\r\n   ```bash\r\n   git clone https://github.com/Nipuna-Lakruwan/pacman-java.git\r\n   ```\r\n\r\n2. Navigate to the project directory:\r\n\r\n   ```bash\r\n   cd pacman-java\r\n   ```\r\n\r\n3. Compile and run the game:\r\n\r\n   ```bash\r\n   javac App.java\r\n   java App\r\n   ```\r\n\r\n## How It Works\r\n\r\n- **Game Window:** The game uses a `JFrame` to create the window and a custom `JPanel` ([`PacMan`](src/PacMan.java)) to render the game board.\r\n- **Game State:** The game state is stored in a 2D grid (`tileMap`), where different characters represent different elements:\r\n  - 'X' for walls\r\n  - ' ' for food\r\n  - 'P' for PacMan\r\n  - 'b', 'o', 'p', 'r' for different colored ghosts\r\n- **Game Loop:** The game loop is driven by a `Timer` that updates the positions of PacMan and the ghosts, checks for collisions, and redraws the screen at a fixed rate.\r\n\r\n## Code Breakdown\r\n\r\n### [App.java](src/App.java)\r\n\r\nThis is the entry point of the game. It creates a `JFrame`, sets its size based on the grid dimensions, and adds the PacMan panel to the frame.\r\n\r\n```java\r\npublic class App {\r\n    public static void main(String[] args) throws Exception {\r\n        // Set up game board dimensions and create a JFrame window.\r\n        int rowCount = 21;\r\n        int columnCount = 19;\r\n        int tileSize = 32;\r\n        int boardWidth = columnCount * tileSize;\r\n        int boardHeight = rowCount * tileSize;\r\n\r\n        JFrame frame = new JFrame(\"Pac Man\");\r\n        frame.setSize(boardWidth, boardHeight);\r\n        frame.setLocationRelativeTo(null);\r\n        frame.setResizable(false);\r\n        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r\n\r\n        // Create the PacMan game panel and add it to the frame.\r\n        PacMan pacmanGame = new PacMan();\r\n        frame.add(pacmanGame);\r\n        frame.pack();\r\n        pacmanGame.requestFocus();\r\n        frame.setVisible(true);\r\n    }\r\n}\r\n```\r\n\r\n### [PacMan.java](src/PacMan.java)\r\n\r\nThis class defines the game logic, including PacMan’s movement, collision detection, and ghost AI.\r\n\r\n- **Block Class:** Represents game objects like walls, ghosts, food, and PacMan itself. Each Block has properties like position (x, y), dimensions (width, height), and a direction (U, D, L, R).\r\n- **Movement and Collisions:** The `move()` method updates PacMan’s and the ghosts’ positions and checks for collisions with walls, ghosts, and food.\r\n- **Graphics Rendering:** The `paintComponent()` method is responsible for rendering the game board, drawing walls, food, and characters on the screen.\r\n\r\n```java\r\npublic class PacMan extends JPanel implements ActionListener, KeyListener {\r\n    class Block {\r\n        // Defines the properties of a game object (e.g., PacMan, ghosts, walls)\r\n    }\r\n\r\n    // Game board setup and initialization\r\n    private void loadMap() {\r\n        // Loads the map tiles (walls, food, PacMan, and ghosts) into the game.\r\n    }\r\n\r\n    // Game loop logic and collision detection\r\n    private void move() {\r\n        // Updates PacMan and ghosts' positions, handles collisions and scoring.\r\n    }\r\n\r\n    // Handles key events to control PacMan's movement.\r\n    @Override\r\n    public void keyReleased(KeyEvent e) {\r\n        // Detects key events and updates PacMan's direction accordingly.\r\n    }\r\n}\r\n```\r\n\r\n## Game Map (tileMap)\r\n\r\nThe `tileMap` defines the layout of the game world. Each string in the array represents a row of the map:\r\n- 'X': Wall block\r\n- ' ': Empty space, where PacMan can move\r\n- 'P': PacMan’s starting position\r\n- 'b', 'o', 'p', 'r': Different colored ghosts\r\n- ' ': Food for PacMan to collect\r\n\r\n## Contributing\r\n\r\nFeel free to fork this repository and make your contributions. If you’d like to suggest improvements or fix bugs, submit a pull request with a detailed description of the changes.\r\n\r\n## License\r\n\r\nThis project is open-source and available under the MIT License.\r\n\r\nHappy gaming!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnipuna-lakruwan%2Fpacman-java-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnipuna-lakruwan%2Fpacman-java-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnipuna-lakruwan%2Fpacman-java-game/lists"}