Skip to content
Anar Bastanov edited this page Mar 17, 2024 · 16 revisions

Minesweeper Clone

A clone of the game Minesweeper resembling Google's version written in C for Windows. This project was created for a university assignment.

Main Idea

Our task was to get something together in two weeks that looks like and works like Minesweeper, with the addition of "rewind bombs". We made a rather eccentric decision to stick to CLI-based programs, but also try to make it feel like it has a GUI as much as possible. This game was inspired by the classic Minesweeper game available on Google, hence the looks of the game are quite similar to Google's version. From our past experiences with console games, there has been a huge improvement in the overall development process, despite that the source code is still a monolithic file. We take user input more gracefully, render the game state more appealingly, and implement more complex features.

Launch

The game starts with a little window greeting the player. The text slowly fills in and later it asks for a key press. Pressing Enter takes the player to the main menu. A short animation is performed before the main menu is listed. A big flashing sign at the top of the screen displays the game title with a short animation using a "sliding window" effect and a loading bar below. Note that we make extensive use of box-drawing characters to draw grids and borders, ANSI escape codes to manipulate foreground colors, background colors, and text styles, and Unicode emojis to represent various objects.


Launch

Menus & Prompts & Input Validation

All menus generally list all the options and actions you can perform with their brief descriptions. One important nuance is that the player needs to enter options as plain texts, while some might expect it to listen for key presses. For consistency reasons, we have grouped texts into four categories in terms of their purpose:

  • # - Preceeds a comment or a block of info.
  • > - Preceeds a prompt and then user input.
  • ~ - Preceeds a warning message.
  • ! - Preceeds an error message.

Different texts will also be colored differently:

Type Color
Comments #82AAFF #82AAFF
Prompt & Input #89DDFF #89DDFF
Warning #4EC9B0 #4EC9B0
Error #FF6666 #FF6666
Number #EB7669 #EB7669
Option #FFCB6B #FFCB6B

The program will try to validate every possible user input and print an error message in case of a failure; users can re-enter their input after an error. Inputs are parsed case-insensitively, i.e. it does not matter whether a or A is entered. Prompts that require multiple arguments use white-space characters as delimiters (except for newline characters); additionally, all extra characters are trimmed and ignored. Below you can see a list of all options in the main menu (#), a prompt for the user (>), and a series of error messages for different reasons (!):


Menu

Grid Size

Players can customize the size of the grid depending on their proficiency via the option S. It will show the current size of the grid, how many of the cells in the grid are mines, and a few more options. In the mobile version of Google's Minesweeper, there are only 3 difficulty levels. A player can either choose one of the provided templates or set a custom grid size. The grid cannot be too small or too large. Entering no values applies no changes and takes the player back to the menu. The default difficulty is set to medium.


Grid Size

Mine Count

Since there are two types of mines, there are two options, M and R, to adjust them separately. It will show the current mine count, average mine density, and three difficulty modes. It is also possible to set a custom mine count, but the density cannot be too low or too high. The ratio of normal mines to rewind mines must be balanced as well.


Mine Count

Rewind Mine Count

Gameplay

After entering the option P, the game will immediately start and a bunch of things will appear on the screen:

  1. Flag Count: Initially set to the total mine count, denotes how many flags the player supposedly has at any moment, but can drop below zero if flags are misplaced.
  2. Timer: This starts ticking continuously right after the first cell is revealed and updates on the screen alongside the grid after any move is performed.
  3. The field: An n by m grid labeled from all four sides with zero-based and single-digit coordinates displaying the game state.
  4. List of auxiliary actions:
    • In cases of despair, the player can enter D to end the game and reveal all the mines on the grid.
    • The option R is to end the current game and start over with a different placement of mines.
    • For some reason, the player can instantly end the game, lose all their progression, and return to the main menu.
  5. Input line: Players can enter either the coordinates of a new move or one of the options for auxiliary actions.

Mines are generated after the first move, hence the first opened cell is always empty. Players can provide the third argument F after two coordinates to mark a cell as flagged instead of opening it. The first move cannot be a flag. There are four key features to consider:

  • Opening a cell that has zero mines around it triggers a cascade effect and automatically reveals neighboring cells.
  • Opening an already opened cell with a labeled number exactly equal to the number of flagged cells around it reveals its neighboring cells.
  • Flagging an already opened cell with a labeled number exactly equal to the number of revealed cells around it flags its neighboring cells.
  • Selecting a flagged cell unflags it.

Gameplay

Assume the player accidentally unrevealed a cell with a mine. From here, they can make a decision:

A) Enter Z to close the cell with a mine and continue playing as if nothing happened.

B) Enter blank to reveal all the mines and start over.


Blunder

Revealing mines look like this:


Reveal All Mines

The player wins the moment when they reveal all the cells that have no mines on them. Victory looks like this:


Reveal All Mines

Rewind mines are a special type of mine that closes all the neighboring cells in a 5x5 chunk and randomly shuffles all the normal mines in that area. Accidentally triggering them does not cause the player to lose, they only reset some of the player's progression. It can be harder to spot them because numbers on open cells only account for normal mines.


Rewind Mine

Quit

After having some fun and enjoying the game, the player can exit the game from the main menu with the option Q.


Quit

Clone this wiki locally