This document provides instructions for setting up the HTMLCity multiplayer city builder game.
Before you begin, ensure you have the following installed:
- Node.js (v14 or newer)
- MongoDB (for user accounts and game persistence)
- Git (optional, for version control)
-
Clone or download this repository
git clone https://github.com/your-username/htmlcity.git cd htmlcity -
Install dependencies
npm install -
Create environment variables
- Copy the
.env.examplefile to.env(or create it if it doesn't exist) - Update the variables as needed, particularly the JWT and session secrets
- Copy the
-
Make sure MongoDB is running
# On most systems: sudo service mongod start # Or sudo systemctl start mongod
To start the game in development mode with automatic reloading:
npm run dev
This will start the server on http://localhost:3000 (or the port you specified in the .env file).
For production deployment:
-
Build the project
npm run build -
Start the server
npm start
The game uses various graphical assets for buildings, terrain, and UI elements:
- Building images should be placed in
/assets/buildings/ - Terrain tiles should be placed in
/assets/tiles/ - UI elements should be placed in
/assets/ui/
If you want to add your own assets, you can place them in these directories and update the code to reference them.
To add new building types, modify the js/buildings.js file:
- Add a new building definition to the
BUILDINGSobject - Add the corresponding image to the
/assets/buildings/directory - Update the UI in
index.htmlto show the new building type
By default, the game uses a 20x20 grid. You can change this by:
- Updating the
.envfile'sDEFAULT_GRID_SIZEsetting - The city constructor in
js/city.jswill use this value
HTMLCity supports the following multiplayer features:
- User accounts with authentication
- Persistent cities stored in MongoDB
- Real-time multiplayer with other players
- Trading resources with other players
- Leaderboards and city rankings
- The server uses Express.js for the API endpoints
- Socket.IO powers the real-time multiplayer functionality
- MongoDB stores user accounts, cities, and trading data
- The frontend uses pure HTML5, CSS, and JavaScript with Canvas for rendering
- If you encounter a "MongoDB connection error," make sure MongoDB is running on your system
- If WebSocket connections fail, check if your firewall allows connections on the server port
- For any other issues, check the server logs for detailed error messages
This project is available under the MIT License. See the LICENSE file for details.