Bang! the board game C implementation, including game manager, computer player, backend websocket server, and frontend web client.
Docker image is avaliable on Docker Hub
We need to implement a 4-layer architecture.
The first layer is the utils layer.
We have implemented some generic utilities, such as connection waiting room.
The second layer is the game logic layer.
It contains all the game logic and expose a simplified API to the third layer (network layer).
The third layer is the network interface layer.
We use websocket portocol to transfer data over TCP.
All the data were using JSON to deliver from / to the client.
The forth layer is the user interface layer.
We designed a website as graphical interface (GUI).
The main thread will spawn a server thread, and in each round of game, the server thread will spawn a game manager thread, which will be ended when a game is done.
And the main thread will stop the server when a round of game finished if user type exit
in terminal during the cycle.
Install cmake (to build libwebsocket
) and valgrind (to debug).
sudo apt update && sudo apt install -y cmake valgrind
Then, you need two terminal window to run the game server and the client.
sudo make setup
make server
./server
# Install third party libraries
sudo make setup
# Build server
make server
# or "make server-debug" to enable debug mode
# Run server
./server
# or "make valgrind" to run with valgrind
Change directory to web
pnpm install
pnpm dev
# Install PNPM
curl -fsSL https://get.pnpm.io/install.sh | sh -
# Install Node LTS
pnpm env use --global lts
# Change directory to web
cd web
# Install dependencies
pnpm install
# Run dev server
pnpm dev
After you run the both server and client, you should be able to play the game on http://localhost:8080
.
We Love GitHub!