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:
-
GameCellClass: Represents a single cell on the Minesweeper grid. Inherits from theBaseComponentclass and implements theIGameObjectinterface. TheGameCellclass uses theSetMediatormethod inherited fromBaseComponentto set its mediator, which is responsible for managing interactions between cells. -
GameCellsManagerClass: Acts as the mediator for theGameCellobjects. It implements theIMediatorinterface and inherits fromBaseComponent. TheGameCellsManagerhandles communication between the cells and theGameManager. -
GameManagerClass: Serves as the mediator for the entire game. It manages communication between theGameCellsManager, theGameCounterclasses (which track the timer and the number of flagged mines), and theGameBannerclass (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.
