A small arcade-style Snake game made with C++17 and SFML 3. Eat food to grow, avoid crashing into walls or your own tail, and try to beat your best score.
| Action | Keys |
|---|---|
| Move | A / D or Left / Right Arrow |
| Move Up/Down | W / S or Up / Down Arrow |
| Restart after losing | Enter |
- CMake 3.16 or newer
- A C++17 compiler (Visual Studio 2022 on Windows is recommended)
- SFML 3, built for the same compiler architecture as the project (normally 64-bit)
-
Download the SFML 3 Windows package that matches your Visual Studio version and architecture from SFML's download page.
-
Extract it to a stable location, such as
C:/SFML-3.0.0. -
Its CMake configuration folder should look like this:
C:/SFML-3.0.0/lib/cmake/SFML
The project does not hard-code an SFML installation path. Pass
SFML_DIRwhile configuring if CMake cannot find your copy.
Run these commands from the project folder in PowerShell:
cmake -S . -B build -DSFML_DIR="C:/SFML-3.0.0/lib/cmake/SFML"
cmake --build build --config Debug
.\build\Debug\Snake.exeFor a Release build, replace Debug with Release in the last two commands.
The build automatically copies the SFML DLL files beside Snake.exe, so the game can start without manually copying the library files.
Check that SFML_DIR points to the folder containing SFMLConfig.cmake, then configure again:
cmake -S . -B build -DSFML_DIR="C:/your-sfml-folder/lib/cmake/SFML"If CMake saved an old path, remove only the generated build directory and rerun the configure command.
Build the project with CMake rather than running a manually copied executable. The POST_BUILD step in CMakeLists.txt copies the required SFML DLLs next to the game executable.
The game loads C:/Windows/Fonts/arial.ttf; this is available on standard Windows installations. If that file is missing, change the font path in Snake.cpp to a font installed on your computer.