|
| 1 | +# Function Builder Backend |
| 2 | + |
| 3 | +This is the backend server for the Function Builder game, responsible for handling multiplayer game rooms, player interactions, and game logic in real-time using `Node.js` and `Socket.IO`. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before you begin, ensure you have the following installed on your machine: |
| 8 | + |
| 9 | +- **Node.js**: You can download it from [nodejs.org](https://nodejs.org/). |
| 10 | +- **npm** (Node Package Manager): This is included with Node.js. |
| 11 | + |
| 12 | +## Getting Started |
| 13 | + |
| 14 | +Follow these instructions to set up and run the backend server locally. |
| 15 | + |
| 16 | +### 1. Clone the Repository |
| 17 | + |
| 18 | +First, clone the repository to your local machine: |
| 19 | + |
| 20 | +git clone https://github.com/Gamify-IT/functionbuilder-backend.git |
| 21 | +cd functionbuilder-backend |
| 22 | + |
| 23 | +### 2. Install Dependencies |
| 24 | +Run the following command to install the required dependencies: |
| 25 | + |
| 26 | +npm install |
| 27 | + |
| 28 | +3. Run the Server |
| 29 | +To start the server, run the following command: |
| 30 | + |
| 31 | +node server.js |
| 32 | + |
| 33 | + |
| 34 | +You can test the backend using a tool like Postman or curl. The following endpoints are available: |
| 35 | + |
| 36 | +GET /roomState: Fetches the current state of all game rooms. |
| 37 | +POST /createRoom: Creates a new game room. You need to pass the roomName and mode in the request body. |
| 38 | +POST /joinRoom: Allows a player to join a specific room. You need to pass the roomId in the request body. |
| 39 | + |
| 40 | +The server uses Socket.IO for real-time communication between clients and the server. Once connected, clients can listen for events such as: |
| 41 | + |
| 42 | +playerJoined: Broadcasts when a new player joins the room. |
| 43 | +startGame: Broadcasts when the game is ready to start. |
| 44 | +playerLeft: Broadcasts when a player leaves the room. |
| 45 | + |
| 46 | +Project Structure |
| 47 | +server.js: Main entry point for the server. |
| 48 | +/node_modules: Contains all installed dependencies. |
| 49 | +package.json: Lists the project dependencies and scripts. |
0 commit comments