How zahidesad/yahtzeegame works
Project Type & Purpose
• This is a Java-based networked two-player Yahtzee game with a headless AWS-hosted server and a Swing desktop client.
• The server manages match-making, game sessions and enforces Yahtzee rules; each client presents an MVC-style GUI, communicates over TCP, and renders game state.
File Structure Analysis
• Top-level modules:
• /src/main/java/server → server entrypoint (YahtzeeServer), session manager (GameSession), per-player socket handler (PlayerHandler)
• /src/main/java/yahtzee → client application:
– controller/GameController.java: orchestrates UI ↔ model ↔ network
– model/: game logic (Dice, Player, ScoreCard, Categories, Game)
– network/: Message, MessageType, NetworkClient (JSON over TCP via Gson)
– view/: Swing panels (LobbyPanel, GamePanel, ScoreBoard, YahtzeeDice)
• Resources: images for GUI.
• Build/deploy: pom.xml (Maven), fat-jar packaging, Systemd unit on AWS.
Key Architecture Insights from README
• Both clients open persistent TCP sockets to the public AWS server.
• Server uses a fixed thread-pool: each pair of connections spawns a GameSession.
• MVC on the client side; message-based protocol for all state updates.
a. Main Components
• Client Application
• View Layer (Swing panels)
• Controller (GameController)
• Model (Game, Player, ScoreCard, Dice, Categories)
• NetworkClient (socket connection, JSON↔Message)
• Server Application
• YahtzeeServer (listener, thread-pool)
• PlayerHandler (one per socket)
• GameSession (pairs two PlayerHandlers, runs game loop)
• External Environment
• AWS EC2 (public IP)
• TCP/IP network
b. Relationships / Data Flows
• Clients establish two TCP connections to the server’s listen port (12345).
• NetworkClient sends/receives Message objects (JSON) to/from PlayerHandler.
• PlayerHandler hands messages into GameSession.
• GameSession manipulates server-side Game model and broadcasts state updates back through PlayerHandlers.
• On the client, GameController translates incoming messages into model updates and view rendering calls.
c. Architectural Patterns
• Client: MVC (Model–View–Controller separation)
• Server: thread-pooled, session-based concurrency
• Communication: message-based protocol over raw TCP, JSON serialization via Gson
d. Technologies & Frameworks
• Java 21, Maven
• Swing + FlatLaf (UI)
• AWS EC2 + Systemd (hosting)
• Gson (JSON)