Overview
Mokepon is a full-stack web game built with vanilla JavaScript on the client side and Node.js/Express on the server side. The architecture follows a clear separation between client and server, with a RESTful API handling communication.Directory Structure
Architecture
Client-Server Separation
The game uses a clear separation between frontend and backend: Client Side (/public)
- Handles user interface and rendering
- Manages game state and animations
- Uses HTML Canvas for map rendering
- Communicates with server via REST API
index.js)
- Express.js server managing game sessions
- Handles player registration and tracking
- Manages CPU opponents
- Provides RESTful API endpoints
- Implements security middleware
localhost:3000) and production environments.
Key Files
Server: index.js
The main Express server file that handles all backend logic.
Core Classes
Player ClassPlayer positions are stored as percentages (0-100%) rather than absolute pixels. This ensures the game works correctly across different screen sizes.
Combat System
The game uses a rock-paper-scissors style combat system:Middleware Stack
Client: public/js/mokepon.js
The client-side game logic handling UI, Canvas rendering, and API communication.
Client-Side Mokepon Class
UI: public/index.html
The HTML structure defines three main game sections:
- Character Selection - Choose your Mokepon
- Map Navigation - Move around and find opponents
- Battle Screen - Turn-based combat interface
Styling: public/css/
reset.css: Normalizes browser default stylesstyles.css: Custom game styling with modern CSS features
Assets: public/assets/
images/: Mokepon character sprites, map backgroundsicons/: UI icons and decorative elementsscreenshots/: Game screenshots for documentation
API Endpoints
The server exposes the following RESTful API endpoints:| Method | Endpoint | Description |
|---|---|---|
GET | /join | Register a new player, returns player ID |
POST | /mokepon/:playerId | Assign a Mokepon to a player |
GET | /mokepon/:playerId/safePosition | Get a safe spawn position |
POST | /mokepon/:playerId/position | Update player position, get enemies |
POST | /mokepon/:playerId/attacks | Submit player attack sequence |
GET | /mokepon/:playerId/attacks | Get player/CPU attack list |
GET | /mokepon/:playerId/cpu-attack | Get CPU’s next attack |
POST | /mokepon/:playerId/reset-attacks | Reset CPU attacks for new round |
POST | /mokepon/:playerId/check-advantage | Check type advantage |
DELETE | /player/:playerId | Remove player from game |
GET | /player/:playerId | Remove player (Beacon API) |
The
GET /player/:playerId endpoint exists to support the Beacon API, which can only make GET requests when the page unloads.CPU Opponents
The server automatically generates 3 CPU opponents when the first player joins:Security Features
The server implements multiple security measures:- Helmet: Sets secure HTTP headers including CSP
- CORS: Restricts origins in production
- Compression: Reduces response size
- Input Validation: Validates all user inputs
- Error Handling: Centralized error middleware
Next Steps
- Learn how to deploy the game
- Review the setup guide for development environment
- Explore the source code to understand implementation details