How kaic-eder/mahjong-match3 works
Purpose and Runtime
This is a Unity 2D tile/board game project. Gameplay centers on generating a board of tile instances, identifying selectable matches, moving selected tiles into a tray/slot area, and progressing game state. The playable scene entry points are Assets/Scenes/SampleScene.unity and Assets/Scenes/testes de board.unity.
It runs in the Unity engine with Universal Render Pipeline 2D configuration under Assets/Settings/Renderer2D.asset and Assets/Settings/UniversalRP.asset.
Application Flow and State
Assets/Scripts/GameFlowController.cs is the likely top-level game orchestration boundary; Assets/Scripts/GameState.cs represents gameplay state. They coordinate board setup, player actions, and success/failure transitions rather than embedding that policy in individual tiles.
The runtime flow is broadly: load scene → initialize game/board → generate and spawn tiles → accept input → resolve matching/tray effects → update game state.
Board Construction Pipeline
The board subsystem is intentionally decomposed into model, generation, and view stages:
• Assets/Scripts/Board/BoardLayout.cs defines the board arrangement representation.
• Assets/Scripts/Board/BoardLayoutGenerator.cs produces layouts.
• Assets/Scripts/Board/BoardContentGenerator.cs assigns tile content while likely respecting matchability.
• Assets/Scripts/Board/BoardSpawner.cs instantiates the resulting content into Unity scene objects.
• Assets/Scripts/Board/BoardController.cs owns runtime board coordination.
Assets/Scripts/Board/BoardCell.cs is the cell-level unit connecting layout/content decisions to board occupancy and accessibility.
Solvability and Match Planning
Board generation appears coupled to planned solvability rather than purely random placement. Assets/Scripts/Board/BoardSolver.cs and Assets/Scripts/Board/PlannedMatch.cs provide a planning/validation layer, while Assets/Scripts/MatchFinder.cs identifies matching tiles during live gameplay.
This creates a key boundary: generator/solver logic determines legal content and intended match sequences before spawning; interaction logic consumes the live board state after spawning.
Tile Interaction and Presentation
Assets/Scripts/TileInteractionHandler.cs receives player tile-selection input and delegates behavior to Assets/Scripts/TileController.cs. Tile controllers should remain the Unity-object-facing layer: visual state, selection, availability, and transfer/removal behavior.
The tile asset is represented by Assets/Prefabs/Tile-marreco.prefab, with sprite resources rooted at Assets/Images/Sprite/Tiles.png.
Tray / Slot Resolution
Assets/Scripts/SlotManager.cs manages the destination collection for selected tiles and its capacity/order semantics. Assets/Scripts/TrayAnimator.cs supplies the visual movement/transition boundary for tray operations.
A typical action path is: interaction handler selects a tile → tile controller validates/removes or marks it → slot manager inserts it → match finder detects a completed set → game flow updates progression. Animation should not own game rules.
Input, Dependencies, and External Boundaries
Input uses Unity’s Input System action assets: Assets/PlayerControls.inputactions and generated wrapper Assets/PlayerControls.cs. The project includes DOTween as a bundled plugin at Assets/Plugins/Demigiant/DOTween; it is the principal third-party animation runtime, with settings in Assets/Resources/DOTweenSettings.asset.
No backend, persistence service, network API, or external SaaS integration is evident from the repository tree.
Main entry points: BoardController.cs Board Controller · GameFlowController.cs Game Flow Controller · TileController.cs Tile Controller · BoardLayoutGenerator.cs Layout Generator
Components 20
Unity Runtime
- Playable Scenes · SampleScene and board test scene are entry points.
Assets/Scenes/SampleScene.unity - URP 2D
Assets/Settings/UniversalRP.asset - Tile Prefab
Assets/Prefabs/Tile-marreco.prefab - DOTween
Assets/Plugins/Demigiant/DOTween
Board Pipeline
- Layout Generator
Assets/Scripts/Board/BoardLayoutGenerator.cs - Board Layout
Assets/Scripts/Board/BoardLayout.cs - Board Solver
Assets/Scripts/Board/BoardSolver.cs - Planned Match
Assets/Scripts/Board/PlannedMatch.cs - Content Generator
Assets/Scripts/Board/BoardContentGenerator.cs - Board Spawner
Assets/Scripts/Board/BoardSpawner.cs - Board Controller
Assets/Scripts/Board/BoardController.cs - Board Cell · Connects layout, content, and tile accessibility.
Assets/Scripts/Board/BoardCell.cs
Gameplay Interaction
- Game Flow Controller
Assets/Scripts/GameFlowController.cs - Game State
Assets/Scripts/GameState.cs - Player Controls
Assets/PlayerControls.cs - Tile Interaction Handler
Assets/Scripts/TileInteractionHandler.cs - Tile Controller · Owns Unity-facing selection, availability, and removal behavior.
Assets/Scripts/TileController.cs - Slot Manager · Owns tray capacity and ordering semantics.
Assets/Scripts/SlotManager.cs - Match Finder
Assets/Scripts/MatchFinder.cs - Tray Animator · Visualizes tray transitions without owning rules.
Assets/Scripts/TrayAnimator.cs
Connections 22
- Playable Scenes → Game Flow Controller: starts
- Playable Scenes → URP 2D: renders with
- Game Flow Controller → Game State: updates
- Game Flow Controller → Board Controller: initializes
- Board Controller → Layout Generator: requests
- Layout Generator → Board Layout: produces
- Layout Generator → Board Solver: plans with
- Board Solver → Planned Match: creates
- Board Solver → Content Generator: constrains
- Board Layout → Board Cell: defines cells
- Content Generator → Board Cell: assigns content
- Board Controller → Board Spawner: spawns through
- Board Spawner → Tile Prefab: instantiates
- Board Spawner → Tile Controller: creates
- Player Controls → Tile Interaction Handler: provides input
- Tile Interaction Handler → Tile Controller: selects
- Tile Controller → Slot Manager: moves selected tile
- Slot Manager → Match Finder: checks completed sets
- Match Finder → Game Flow Controller: reports resolution
- Slot Manager → Tray Animator: triggers transition
- Tray Animator → DOTween: animates with
- Board Controller → Tile Controller: tracks live board