Blokus is a strategic board game where players take turns placing uniquely shaped tiles on a shared board. The goal is to place as many tiles as possible while adhering to placement rules. This project implements a multiplayer version of Blokus using Node.js, WebSockets, and MySQL.
- Node.js: For building the server and handling API requests.
- Express.js: To simplify routing and middleware.
- Socket.IO: For real-time communication between players.
- MySQL: To manage game state and player data.
- JSON Web Tokens (JWT): For secure authentication.
- HTML/CSS/JavaScript: For a dynamic and interactive UI.
- Socket.IO Client: To handle WebSocket communication.
- Player Management:
- Players log in as guests with unique usernames.
- JWT-based authentication.
- Game Lobby:
- Players can create and join game rooms.
- Real-time updates for lobby status using WebSockets.
- Tile Placement:
- All 21 Blokus tile shapes implemented.
- Placement rules enforced, including:
- Corner-touch requirement.
- No edge-touch rule for same-player tiles.
- Board boundaries.
- Game Synchronization:
- Real-time updates for moves using WebSockets.
- Persistent game state using MySQL.
- Players automatically join WebSocket rooms corresponding to their game.
- Broadcast events for:
- Player joins and leaves.
- Game moves.
- Game start and end.
- Node.js and npm: Download and Install
- MySQL
- Docker: Download and Install
- Docker Compose: Download and Install
-
Clone this repository:
git clone https://github.com/iee-ihu-gr-course1941/ADISE24_Blockage.git cd ADISE24_Blockage/backend
-
Install dependencies:
npm install
-
Set up the database:
-
Configure the backend:
- Copy
.env.example
to.env
:cp .env.example .env
- Update the
.env
file with your MySQL credentials and JWT secret.
- Copy
-
Start the backend:
npm start
- Run:
docker-compose up -d
-
Creating a Game:
- A player creates a game via an HTTP request.
- The player is added as the first participant and assigned a color.
-
Joining a Game:
- Players can join available games until the maximum number of players is reached.
- Each player is assigned a unique color dynamically.
-
Tile Placement:
- Players take turns placing tiles on the board.
- Placement rules are validated in real-time.
-
Game End:
- The game ends when all players have placed all possible tiles or when no moves remain.
- Scores are calculated based on unplaced tiles.
POST /auth/guest
: Login as a guest player.
GET /games
: Get all available games.GET /games/:gameId
: Get game details.GET /games/status
: Get games by status.GET /games/participants
: Get all the participants of games by status.GET /games/:gameId/participants
: Get all participants by gameId.POST /games/create
: Create a new game.POST /games/join
: Join an existing game.DELETE /games/leave
: Delete a game.
connection
: Connect to the server.player-left
: Notify player leaves from lobby.place-tile
: Place a tile on the board.game-ended
: Notify game end.disconnect
: Disconnect from the server.
connect
: Notify connection.error
: Notify an error.game-created
: Notify game created.player-joined
: Notify player joins the game.player-left
: Notify player leaves from lobby.game-started
: Notify game start.board-initialized
: Initialize the game board.game-update
: Update game state.game-deleted
: Notify game deleted.game-ended
: Notify game end.