Jack Morton

Minesweeper

April 2022

In my first semester of University, I developed a minesweeper program for my MATLAB & C course. It is console-based and prints instructions for the user to follow. It contains an intuitive design with lots of input validation to ensure the game runs smoothly.

Screenshot of the console, asking the user to start a new game, and generating a fresh board.

The program generates a random minesweeper grid based off customisable input parameters. It can also load a save file. Each move, you have the option to reveal, flag, or unflag a tile, or to save and exit the game. The goal is to reveal all tiles which aren’t mines. When you reveal a tile, it displays the number of adjacent mines.

Screenshot of the console, after revealing a mind. A message was displayed, 'You lose!', and a prompt appears to play again.

If there are no adjacent mines, a recursive depth-first search function will automatically reveal all adjacent zeros, and their surrounding tiles.

Screenshot of the console, showing a user select row 5 column 1 to reveal, which had no adjacent mines, and revealed all adjacent tiles as wel.

At the end of the game, an image is automatically generated displaying the board so you can share the game you just played.

Pixel art of the full board, with all cells revealed. One mine is highlighted in red.

Check it out on GitHub.


Go back to posts