# elifnazlib/card-matching-game architecture

> Architecture diagram of the GitHub repository elifnazlib/card-matching-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elifnazlib/card-matching-game
- Repository: https://github.com/elifnazlib/card-matching-game

## Overview

##### Main Components
- Game Scenes – List each .unity scene (MainMenu, ChillMode, EasyMode, HardMode, MediumMode, Multiplayer). These represent the various states or screens of the game.
- Game Logic and Controllers – Include script components such as GameControl (overseeing game flow), ButtonController (handling UI interactions), Timer (managing time-based events), Score, and MultiplayerScore scripts to capture different game mechanics.
- Audio Management – Identify components managing background music and sound effects (BGMusic.cs and SoundEffects.cs). Note the various audio files for different game contexts (modes, win/lose events).
- UI and Visual Components – Although not code, separate elements like Sprites and TextMesh Pro assets (for fonts, materials, etc.) are used to render visuals and text consistently.
- Auxiliary Components – Mark any other scripts like ChangePlayer, ExitGame, GameOver, and MainToken which contribute to gameplay logic, state changes, or player management.

##### Out Relationships and Interactions
- Directional connections from the MainMenu scene leading to other game modes (scenes) via UI interactions, as handled by the ButtonController script.
- How audio components (BGMusic and SoundEffects) are triggered both during scene loading and specific game events (e.g., win, lose, button clicks) to enhance user experience.
- Integration with Unity’s event system and likely reliance on component-based design, showing that each scene usually contains multiple game objects that have attached scripts for specific functionalities.

##### Important Architectural Patterns
- The project leverages Unity’s component-based architecture: each GameObject in a scene has attached behavior scripts that work together during runtime.
- There is a clear separation between presentation (Scenes, Sprites, UI elements via TextMesh Pro) and game logic (scripts under Assets/Scripts).
- Event-driven interactions are likely central to the design, mapping user input (via buttons) to game state changes and transitions among scenes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Scenes Section
    subgraph "Scenes"
        MainMenu["MainMenu.unity"]:::scene
        ChillMode["ChillMode.unity"]:::scene
        EasyMode["EasyMode.unity"]:::scene
        HardMode["HardMode.unity"]:::scene
        MediumMode["MediumMode.unity"]:::scene
        Multiplayer["Multiplayer.unity"]:::scene
    end

    %% Game Logic Section
    subgraph "Game Logic"
        GameControl["GameControl\n(Manages game state and transitions)"]:::logic
        ButtonController["ButtonController\n(Handles UI interactions)"]:::logic
        Timer["Timer\n(Manages time events)"]:::logic
        Score["Score\n(Handles scoring)"]:::logic
        MultiplayerScore["MultiplayerScore\n(Manages multiplayer scores)"]:::logic
        ChangePlayer["ChangePlayer\n(Manages player switching)"]:::logic
        ExitGame["ExitGame\n(Handles game exit)"]:::logic
        GameOver["GameOver\n(Manages game over state)"]:::logic
        MainToken["MainToken\n(Handles token logic)"]:::logic
    end

    %% Audio Management Section
    subgraph "Audio Management"
        BGMusic["BGMusic\n(Plays background music)"]:::audio
        SoundEffects["SoundEffects\n(Triggers sound effects)"]:::audio
    end

    %% UI and Visual Resources Section
    subgraph "UI/Visual Resources"
        Sprites["Sprites Assets"]:::ui
        TextMesh["TextMesh Pro Assets"]:::ui
    end

    %% Relationships and Data Flow

    %% From MainMenu initiating UI action via ButtonController
    MainMenu -->|"UIButtonClick"| ButtonController
    ButtonController -->|"InitiatesGame"| GameControl

    %% GameControl orchestrates events and logic
    GameControl -->|"UpdatesTime"| Timer
    GameControl -->|"UpdatesScore"| Score
    GameControl -->|"MultiplayerEvent"| MultiplayerScore
    GameControl -->|"SwitchPlayer"| ChangePlayer
    GameControl -->|"ExitGame"| ExitGame
    GameControl -->|"CheckGameOver"| GameOver
    GameControl -->|"TokenUpdate"| MainToken

    %% Audio triggers from GameControl to Audio components and via scenes
    GameControl -->|"PlayBGM"| BGMusic
    GameControl -->|"PlaySFX"| SoundEffects

    %% Scene transitions triggered from UI interactions in ButtonController
    ButtonController -->|"LoadChillMode"| ChillMode
    ButtonController -->|"LoadEasyMode"| EasyMode
    ButtonController -->|"LoadHardMode"| HardMode
    ButtonController -->|"LoadMediumMode"| MediumMode
    ButtonController -->|"LoadMultiplayer"| Multiplayer

    %% Linking UI/Visual Resources with UI components (ButtonController)
    Sprites -->|"ProvidesUIElements"| ButtonController
    TextMesh -->|"ProvidesTextRendering"| ButtonController

    %% Background audio applied on scene load (from Scenes to BGMusic)
    MainMenu -->|"BackgroundAudio"| BGMusic
    ChillMode -->|"BackgroundAudio"| BGMusic
    EasyMode -->|"BackgroundAudio"| BGMusic
    HardMode -->|"BackgroundAudio"| BGMusic
    MediumMode -->|"BackgroundAudio"| BGMusic
    Multiplayer -->|"BackgroundAudio"| BGMusic

    %% Click Events from Component Mapping
    click MainMenu "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click ChillMode "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click EasyMode "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click HardMode "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click MediumMode "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click Multiplayer "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Scenes"
    click GameControl "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/GameControl.cs"
    click ButtonController "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/ButtonController.cs"
    click Timer "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/Timer.cs"
    click Score "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/Score.cs"
    click MultiplayerScore "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/MultiplayerScore.cs"
    click BGMusic "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/BGMusic.cs"
    click SoundEffects "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/SoundEffects.cs"
    click ChangePlayer "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/ChangePlayer.cs"
    click ExitGame "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/ExitGame.cs"
    click GameOver "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/GameOver.cs"
    click MainToken "https://github.com/elifnazlib/card-matching-game/blob/main/Assets/Scripts/MainToken.cs"
    click Sprites "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/Sprites"
    click TextMesh "https://github.com/elifnazlib/card-matching-game/tree/main/Assets/TextMesh Pro"

    %% Style Definitions
    classDef scene fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef logic fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef audio fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef ui fill:#FFCCCC,stroke:#333,stroke-width:2px;
```
