This project implements the classic 2048 game with a React frontend and a C++ backend.
backend/: C++ backend codegame_logic.hpp: Game logic implementationserver.cpp: Crow web server with API endpointsCMakeLists.txt: Build configurationDockerfile: Docker configuration for the backend
app/: React frontend codepage.tsx: Main game component
-
Build the Docker image: ```bash cd backend docker build -t game2048-backend . ```
-
Run the container: ```bash docker run -p 3001:3001 game2048-backend ```
-
Install dependencies: ```bash
sudo apt-get install build-essential cmake libboost-all-dev
brew install cmake boost
vcpkg install boost ```
-
Clone Crow: ```bash git clone https://github.com/CrowCpp/Crow.git backend/crow ```
-
Build the project: ```bash cd backend mkdir build && cd build cmake .. make ```
-
Run the server: ```bash ./game_server ```
-
Install dependencies: ```bash npm install ```
-
Run the development server: ```bash npm run dev ```
-
Open http://localhost:3000 in your browser.
- The C++ backend implements the game logic and exposes it via a REST API.
- The React frontend communicates with the backend to initialize the game, make moves, and reset the game.
- If the backend is unavailable, the frontend falls back to client-side logic.
POST /api/game/new: Create a new game sessionPOST /api/game/move: Make a move (requires sessionId and direction)POST /api/game/reset: Reset the game (requires sessionId)