A technical implementation of Trading Card Game (TCG) mechanics featuring a Finite State Machine (FSM) architecture, drag & drop logic, and DOTween animations.
Card management system is a robust implementation of core card game mechanics designed in Unity. The project simulates a complete gameplay loop, from deck shuffling and drawing cards to managing a player's hand and playing cards onto the table.
The system focuses on modularity and user experience, featuring smooth procedural animations for card interactions and a strict separation of game logic from visual presentation.
- Advanced hand management:
- Dynamic card slots with support for reordering (swapping positions).
- Automatic card drawing logic based on hand capacity limits.
- Visual feedback: Hover scaling and highlighting animations.
- Drag & drop system:
- Physics/UI-based
Draggablelogic allowing cards to be played on the table. - "Return to hand" safety mechanic if a card is dropped in an invalid area.
- Physics/UI-based
- Card lifecycle:
- Full cycle implementation: deck -> hand -> table -> discard pile.
- Automatic cleanup of played cards.
- Game flow:
- Turn-based system with distinct phases (start, draw, play, end).
The project is structured around clean code principles, utilizing Interfaces and Design Patterns to ensure scalability.
The Game Loop is not hardcoded into a single manager but is driven by a flexible State Pattern (implementing IGameState).
- GameStateStartGame: Initializes the deck and shuffles
CardCollection. - GameStateDrawPhase: Handles drawing logic, ensuring the hand is refilled to the target count (X) at the start of the turn.
- GameStatePlayerTurn: Unlocks input, allowing the player to drag cards, interact with the board, or end the turn manually.
- GameStateEndGame: Handles the win/loss condition (e.g., deck empty).
The code relies on interfaces to decouple systems, making the project easy to extend.
ICardAnimation: Abstracts visual behavior, allowing different card types to have unique animations without changing the coreCardAnimator.IGameState: Standardizes how theTestManagerswitches between game phases.IDisplayInfo: Ensures UI elements display data uniformly.
Card data is strictly separated from logic using ScriptableObjects (CardCollection). This allows designers to balance the game and add new cards via the inspector without touching the codebase.
Instead of static transitions, the project uses DOTween for fluid visuals:
- Hover effects: Cards scale up and float (
SelectCardAnimation.cs). - Movement: Smooth transitions when drawing cards or returning them to hand (
MoveCardAnimation.cs).
- Drag & drop: Move cards from hand to table to play them.
- Drag in hand: Reorder cards within your hand.
- End turn button: Manually finish the current turn.
- Unity 6 (6000.0.26f1)
- DOTween (HOTween v2)