About this project
A classic swap-and-match game with a twist: the board is also a puzzle.
Under the gem grid sits a layer of tiles. Every gem you clear damages the tile beneath it, and you only win once every tile in the center 6×6 area has been completely cleared. That turns a simple match game into a small strategy puzzle: where you clear matters as much as how much you clear.
Powerups
Special matches spawn Line, Color and Area bombs that you can fire on demand.
Fusions
Swap two powerups together for a stronger combined effect, up to wiping the whole board.
Scalable challenge
Pick 1–10 gem colors and 1–50 tile layers. Beat a level and jump straight to the next.
How to play
Mouse only. Press ESC any time to return to the menu.
- Select a gem. Click a gem and a yellow ring appears around it.
- Swap it. Click an adjacent gem to swap the two. If the swap makes no match, the gems slide back.
- Match 3 or more. Line up three or more gems of the same color in a row or column to clear them. Gems fall, new ones drop in, and chains score extra.
- Break the tiles. Each cleared gem removes one layer from the tile under it. Only the center 6×6 tiles have layers; the outer border starts already cleared.
- Win. Clear every layer in the center 6×6 area.
Tile colors
Tiles change color as they take damage, so you can see at a glance where work is left.
Top bar
- Score and the current
Lv./D.(level and difficulty). - Progress bar showing layer hits cleared out of the total needed.
- HINT highlights one valid swap in yellow.
- Shuffle (×3) reshuffles the board. You get three per game.
If no valid move is left, the game ends with NO MORE MOVES.
Powerups
Created automatically from special matches. The powerup appears on the gem you just swapped.
Line Bomb
Match exactly 4Gold ring with a cross. Clears a full row or a full column, whichever damages more tiles.
Color Bomb
Match 5 or morePink ring with a pentagon of dots. Clears every gem on the board that shares its color.
Area Bomb
Match in an L or T shapeTeal ring with a square. Clears the 3×3 area around itself.
Firing a powerup
- Double-click it to fire immediately.
- Swap it with a normal gem to fire it.
- Swap it with another powerup to fuse them (see below).
Powerup gems never count as part of a normal match; they break runs until you use them.
Fusions
Swap powerup A onto powerup B. The order doesn't matter.
| Combo | Result | Effect |
|---|---|---|
| Line + Line | Cross Bomb | Full row and full column of both powerups |
| Line + Area | Mega Area | 5×5 blast |
| Area + Area | Mega Area | 5×5 blast |
| Line + Color | Color Line | All gems of that color plus their entire rows and columns |
| Area + Color | Color Area | All gems of that color plus a 3×3 around each |
| Color + Color | Wipe Board | Clears the entire board |
Level & difficulty
Two dials on the start screen control how hard a game is.
Difficulty: 1–10
The number of gem colors in play. Fewer colors means easier matches and more chains. More colors means harder matching. The start screen previews the colors you've chosen.
Level: 1–50
The number of layers on every center tile. Level 1 needs one hit per tile; level 50 needs fifty. Win a level and the "Next Level" button takes you up by one.
Scoring
Bigger clears and longer chains pay off.
| Component | Points |
|---|---|
| Base | 10 per gem cleared |
| Size bonus | +10 for each gem beyond the minimum of 3 |
| Chain bonus | +30 per chain level above 1 (chain 2 = +30, chain 3 = +60, …) |
Your best score is saved to match3_highscore.json next to the script, and shown on the menu and end screens.
Run it
You need Python 3 and Pygame.
pip install pygame
python3 match3.py
The window is 512 × 592 pixels (an 8×8 grid of 64px cells plus an 80px top bar).
Controls
| Input | Action |
|---|---|
| Click gem, click neighbor | Swap |
| Double-click a powerup | Fire it |
ESC | Back to menu (works during animations too) |
R | Menu, from the win or game over screen |
Q | Quit, from the win or game over screen |
Under the hood
Everything lives in one well-commented file, match3.py.
Code layout
- Constants: grid size, cell size, animation timings, colors. Tweak the
*_MSvalues to change how the game feels. - Gem data: each cell is a small dict,
{"color": int, "power": str | None}, wrapped by helpers likemake_gem()andis_powerup(). - Grid logic:
make_grid()builds a board with no starting matches;find_matches()scans rows and columns;detect_powerup_type()decides which powerup a match earns;apply_gravity()andfill_empty()refill the board. - Powerups:
activate_powerup()handles a single bomb andfuse_powerups()handles combinations, keyed on an order-independentfrozenset. - Helpers:
has_any_move()for game over detection,find_hint(), anddo_shuffle(), which retries until the board has no matches but still has a move. - Drawing: tiles, gems, powerup rings and symbols, and a small
FloatTextclass for the drifting "+score" popups.
Game state machine
The main loop is driven by a simple state variable.
reverting: a swap with no result slides back.fallingre-checks the board, so chain reactions loop back intoflashing.wintriggers the moment the last tile layer clears, even mid-combo.gameovertriggers when no valid move remains after a combo ends.