๐ Matching Cards Game
A Java Swing-based Memory Matching Game where players flip cards to find matching pairs before time runs out.
๐ Overview
Matching Cards Game is a desktop GUI application built using Java Swing.
Game Rules:
- โณ You get 5 seconds to memorize the cards at the start.
- โฐ You have 60 seconds total to match all pairs.
- ๐ฏ Each correct match increases your score.
- โ If time runs out, the game ends.
๐ฎ Gameplay Flow
- All cards are shown face-up for 5 seconds.
- Cards automatically flip face-down.
- Player clicks two cards:
- โ
If they match โ They stay revealed & score increases.
- โ If they donโt match โ They flip back.
- Game ends when:
- Time reaches zero, or
- All pairs are matched.
๐ Technologies Used
- Java
- Java Swing
- AWT Event Handling
javax.swing.Timer
- GridLayout
๐ Project Structure
MatchingCardsGame/
โ
โโโ src/
โ โโโ MatchingCardsGame.java
โ โโโ game.java
โ โโโ card.java
โ โโโ CardClickListener.java
โ โโโ pane.java
โ
โโโ Images/
โ โโโ (24 card images)
โ โโโ unknown.png
โ
โโโ matched.png
โโโ unmatched.png
โโโ LICENSE
โโโ .gitignore
โโโ README.md
๐ผ Images Directory
The Images/ folder contains:
- 24 card images
- The developer selects 12 unique images to create matching pairs (total 24 cards).
unknown.png is used as the back of the card.
โ ๏ธ Image file names must match the names used inside the code.
๐ง Core Components
๐น MatchingCardsGame
- Main application window (
JFrame)
- Combines:
- Score & timer panel (top)
- Game board grid (center)
๐น game
- Extends
JPanel
- Creates and shuffles 24 cards
- Handles:
- Card grid layout (4x6)
- Score tracking
- First & second card selection
๐น card
- Extends
JButton
- Manages:
- Card flipping
- Match checking
- Image updates
๐น CardClickListener
Controls card click behavior:
- Stores first click
- Compares with second click
- Resets selection
๐น pane
Displays:
- ๐ฏ Current score
- โณ Countdown timer (60 seconds)
Ends the game when time reaches zero.
โถ๏ธ How to Run the Project
1๏ธโฃ Requirements
2๏ธโฃ Compile
From the project root:
3๏ธโฃ Run
๐ธ Screenshots
โ
Match Example

โ Unmatched Example

๐ฏ Features
- 4x6 grid layout
- Randomized card positions
- Score tracking
- Countdown time
- Match / No Match dialog messages
- Game Over popup
- Simple and clean UI
๐ Possible Improvements
- Add restart button
- Add difficulty levels (Easy / Medium / Hard)
- Improve UI design
- Add sound effects
- Refactor card creation using loops
- Remove static fields for better architecture
- Add win condition screen
๐จโ๐ป Author
Developed by Ayman Soliman
GitHub: 
๐ License
This project is licensed under the terms described in the LICENSE file.