A clone of Minesweeper made in C with SDL2.
Before building, ensure you have the following libraries installed:
SDL2
SDL2_ttf
SDL2_image
To build Minesweeper for Linux from source, follow these steps:
-
Clone the Minesweeper repository from GitHub:
git clone https://github.com/uwiwiow/minesweeper cd minesweeper/
-
Create a build directory for MinGW:
mkdir build cd build
-
Run CMake to configure the build:
cmake ..
-
Build the project using make:
make
This will compile the source code and generate the executable.
Once the build process is complete, you can run the Minesweeper game directly from the source build directory:
./minesweeper
Before building, ensure you have the following libraries installed:
mingw-w64-toolchain
mingw-w64-sdl2
mingw-w64-sdl2_ttf
mingw-w64-sdl2_image
-
Clone the Minesweeper repository from GitHub:
git clone https://github.com/uwiwiow/minesweeper cd minesweeper/
-
Create a build directory for MinGW:
mkdir build-mingw cd build-mingw
-
Run CMake with the MinGW toolchain file:
x86_64-w64-mingw32-cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-mingw.cmake ..
To make a static build add
-DSTATIC_BUILD=ON
:x86_64-w64-mingw32-cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-mingw.cmake -DSTATIC_BUILD=ON ..
-
Once CMake configuration is done, build the project:
make
This will generate the minesweeper.exe executable.
Once the build process is complete, you can run the Minesweeper game directly from the directory:
.\minesweeper.exe
-
Download and extract the binary distribution archive:
tar -xzvf minesweeper_linux_x86_64.tar.gz cd minesweeper-*
-
Run the game:
./run.sh
-
Download and extract the binary distribution archive:
Expand-Archive .\minesweeper_windows_x86_64.zip cd .\minesweeper-*
-
Run the game:
.\minesweeper.exe
There are almost 99 mines (due to duplicated positions).
Every time you start a game, you will open a blank tile first. From there, you will be opening the adjacent tiles.
- WASD for movement
- O to restart the game
- P to uncover all the tiles
- K to open a tile
- L to flag or question mark a tile
- 1-5 to show debug information
Open all the tiles without hitting a mine.
The in-game debug keys and their explanations:
Displays the (x, y) coordinates of the cursor.
Displays (Type, Amount):
-
Type represents the type of tile:
- BLANK: A blank tile
- NUMBER: A tile with a number representing the number of mines around it
- MINE: A mine
- M-EXP: A mine that the player opened, only appears when it's game over
-
Amount represents the number of mines around the tile where the cursor is located.
Displays (Mark, Visible):
-
Mark represents the player's assessment of the tile:
- CLEAR: A regular tile
- FLAG: A flagged tile
- QSTN: A questioned tile
-
Visible is a boolean value indicating if the current tile is visible in normal mode. (Uncovering all the tiles with key P doesn't affect this value.)
Displays (State):
- State represents the current state of the game:
- START: The player hasn't opened any tile (uncovering all the tiles with key P doesn't affect this)
- PLAYING: The player has opened a tile (if the game is restarted and all the tiles were uncovered, this feature will be disabled automatically)
- WIN: The player has opened all the safe tiles, uncovering all the mines
- LOSE: The player has opened a tile with a mine, uncovering all the tiles and the tile with the mine opened is colored red
Toggles the debug information background between black and transparent.
Almost all the settings are set in the Status struct.
// default settings
Status status = {
.TILE = 40, // The size of each tile
.W_TILES = 32, // Number of tiles in width
.H_TILES = 16, // Number of tiles in height
.BOMBS = 99, // Number of bombs in the game (might not be accurate)
.STATE = START, // Default state when starting the game (typically set to START)
.VISIBLE_TILES = 0 // Number of starting visible tiles (used to calculate win condition; typically left as 0)
.FIRST_CELL = BLANK, // Default first tile to open (BLANK / NUMBER / MINE / ANY)
.MAX_ITERATIONS = 10000 // Maximum iterations for generating the board before automatic termination (-1 for unlimited)
};
The width and height of the window are calculated based on the values given in the status.