How rouhjp/rouh-mahjong-net works
The rouh-mahjong-net project is a Java-based desktop mahjong game that supports both local test play and networked multiplayer matches. The project uses Gradle for building and organizes its code into distinct packages corresponding to specific aspects of the application such as the user interface (UI), core game logic, network communications, scoring, and bot behavior.
Main Components
• User Interface (UI) Layer:
• Located primarily in the “app” and “app/view” packages.
• Contains windows, panels (such as AutoResizablePanel, MenuScene, RoomScene, GameResultViewPanel, etc.), and other visual elements for displaying game state and receiving user input.
• Game Engine / Core Game Logic:
• Found in the “game” and “game/event” packages.
• Manages game flow, player actions, rounds, wall generation, and overall game state.
• Implements design patterns such as Observer (e.g., TableObserver, TableObserverAdapter) and possibly MVC to separate the game model from the view.
• Bot / AI Module:
• Present in the “bot” package.
• Facilitates automated players with classes like DiscardingBot, StandardDiscardingBot, and additional AI strategies.
• Network Module:
• Located in the “net” package and supported by utilities in “util/net” and “util/net/msg”.
• Handles networking aspects including room creation, room membership, message conversion, and communication through RoomServer, RoomObserver, etc.
• This module enables multiplayer functionality, including room management and message passing between clients.
• Scoring and Rules Module:
• Found in the “score” package.
• Responsible for calculating hand scores, evaluating winning options, and representing scoring-related metrics.
• Tile and Resource Management:
• “tile” package contains classes for tiles, dice, and related game pieces.
• “src/main/resources/img” holds image assets for dice and tiles, indicative of the resource dependencies for the UI.
• Utility Classes:
• Located in “util” which provides common functionalities (e.g., Lists, Maps) and supportive network messaging utilities.
Relationships and Interactions
• UI Layer interacts with the Game Engine by sending and receiving game state changes. For example, a Scene in the “app” package will transition based on game events managed in the “game” packages.
• The Game Engine dispatches events (via classes in “game/event”) that are observed by both the UI (for rendering updates) and the Network Module (for multiplayer synchronization).
• The Bot Module plugs into the Game Engine allowing automated players to register and act within the game loop.
• The Network Module serves as an intermediary for remote players. Components here (such as Room, RoomServer, and RoomObserver) handle connection, message serialization (via util/net/msg) and communication to ensure synchronized gameplay.
• The Scoring Module works closely with the game logic to evaluate game outcomes, compute points, and display them in the UI.
• Utility packages support various common functions (e.g., list and map management) and provide network I/O management.
Architectural Patterns and Frameworks
• Separation of Concerns/MVC: The UI and game logic are clearly separated. Game state and business logic are managed separately from the user interface.
• Observer Pattern: Evident in the “game/event” package with components like TableObserver that facilitate event-driven updates.
• Modularization: The project is divided into logical modules: UI, game logic, networking, AI, and scoring.
• Gradle Build System: Shown in the build.gradle and settings.gradle files, which manage dependencies and project configuration.
Relevant Technologies
• Java as the programming language.
• Gradle for project build and dependency management.
• Logback (as seen in src/main/resources/logback.xml) is used for logging.
• Native image resources and drawing utilities for the UI.
• Custom network communication protocols and converters for facilitating multiplayer gameplay.
Elements
• Data stores or resource nodes for images and configuration files (resources for images, logback config).