Minesweeper Sharp is a Windows Forms application written in C#. It is a custom implementation of the classic Minesweeper game, developed to strengthen understanding of C# and advanced design patterns, specifically the Mediator and Composite patterns. This project offers an engaging way to explore these concepts while creating a functional and enjoyable game.
- Three Difficulty Levels: Play Minesweeper at Easy, Intermediate, or Expert levels.
- Advanced Design Patterns: Implements the Mediator and Composite design patterns, providing a real-world application of these powerful software design techniques.
- Intuitive Interface: A clean and responsive user interface built with Windows Forms.
The Mediator pattern is central to the architecture of Minesweeper Sharp. It is implemented using the IMediator
interface, which defines a Notify
method for passing notifications between components. Here's how it's structured:
-
GameCell
Class: Represents a single cell on the Minesweeper grid. Inherits from theBaseComponent
class and implements theIGameObject
interface. TheGameCell
class uses theSetMediator
method inherited fromBaseComponent
to set its mediator, which is responsible for managing interactions between cells. -
GameCellsManager
Class: Acts as the mediator for theGameCell
objects. It implements theIMediator
interface and inherits fromBaseComponent
. TheGameCellsManager
handles communication between the cells and theGameManager
. -
GameManager
Class: Serves as the mediator for the entire game. It manages communication between theGameCellsManager
, theGameCounter
classes (which track the timer and the number of flagged mines), and theGameBanner
class (which displays the win or lose banner).
The Composite pattern is used to manage the hierarchical structure of the game components. The IGameObject
interface is implemented by all major classes (GameCell
, GameCellsManager
, GameCounter
, GameBanner
, and GameManager
), ensuring that each component can be drawn and can handle mouse click events. This allows individual cells, as well as groups of cells and other game elements, to be treated uniformly.
- .NET 6: Ensure you have .NET 6 installed on your machine.
- Visual Studio 2022: It is recommended to use Visual Studio 2022 or later for compiling and running the project.
- Clone the repository:
git clone https://github.com/yourusername/Minesweeper-Sharp.git
- Open the solution file (
Minesweeper Sharp.sln
) in Visual Studio 2022. - Build the solution.
- Run the application.
- Choose a difficulty level: Beginner, Intermediate, or Expert.
- Click on the cells to reveal either a number, an empty space, or a mine.
- Use the numbers to deduce where the mines are located and flag them.
- Clear all non-mined cells to win the game!
This project uses the following icons from FlatIcon:
- Flag icon: Flag icons created by Smashicons - Flaticon
- Timer icon: Time icons created by Freepik - Flaticon
- Application icon: Bomb icons created by surang - Flaticon
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.