How xyt-dev/kingofsnake works
Main Components
• Frontend Clients:
• "acapp": A Vue.js client containing typical Vue components (e.g., App.vue, HelloWorld.vue) for a mobile or dedicated application experience.
• "web": Another Vue.js based web client that includes detailed game logic scripts (e.g., Snake.js, GameMap.js, Wall.js) along with multiple views (like ranking, record, user account, and PK-related views). This suggests refined, interactive interfaces for gameplay and user interaction.
• Backend Services (found under the "backendCloud" directory):
• "backend": Built in Java (using Spring Boot and Maven) with a structured arrangement of controllers, services, mappers, and configuration classes. It handles key features such as user management (register, login, account info), game session control (PK start and control, ranklist, record management), and configurations like JWT authentication and WebSocket setups.
• "botRunningSystem": A subsystem dedicated to managing the bot running logic. It includes configuration classes, controllers, and service implementations which likely serve to operate automated bots during gameplay.
• "matchingSystem": Another subsystem aimed at pairing users (or bots) together. It handles player matching logic and related configurations.
Relationships & Interactions
• The Frontend (acapp and web) interacts with the Backend (the “backend” module) through API calls. These interactions include user authentication (JWT tokens, login, registration) and game actions (starting games, recording game results).
• The backend communicates with auxiliary services like the botRunningSystem and matchingSystem. These subsystems likely work through REST API calls or messaging events, handling game-specific behaviors like bot moves or player matching in real time.
• WebSocket configurations in the Java backend (e.g., WebSocketConfig) indicate real-time data flows where the server pushes game updates to connected frontend clients.
Architectural Patterns & Design Principles
• Modular Design: Notice how the backendCloud directory is split into multiple modules (backend, matchingSystem, botRunningSystem), each with a focused responsibility. This modularity is a key element in the architecture.
• Clear Separation of Concerns: Frontend and backend are cleanly separated. The frontend focuses on UI, game rendering, and user interactions; the backend deals with business logic, security (JWT, CORS configurations), and service organization.
• MVC Structure in the Backend: The Java code structure (controllers, services, mappers, POJOs) is indicative of the typical Model-View-Controller separation.
• Real-Time Communication: Inclusion of WebSocket configurations hints at a real-time or near real-time data flow between client and server, important for interactive gaming.