C# Minesweeper Game

By Fons Sonnemans, 29-jun-2003

Download Minesweeper.zip


I have always wondered how hard it would be to write a game in C#. I picked Minesweeper for my first try. Made an OO design and then went programming.

See the result in the downloadable zip file. The whole program is less then 400 lines of code!


I have reduced the complexity a bit by eliminating the flag-icon and all menu options.


The application is build using 3 objects: a Form, a Game which holds an array of Square objects.

UML Class Diagram (Visio)

MinewsweeperForm class
This class creates a Game object when the Start button is clicked. It also updates the Timer and Mines display. It contains a Panel control in which the Game object generates the Squares.

Game class
This class contains a multidimensional array of Square objects which is initialized in the constructor. The mines are randomly placed in the squares. It has a Timer which is used to calculate the elapsed gametime. The events DismantledMinesChanged and Tick are used to notify the MinesweeperForm that is has to update the GUI.

Square class
This class contains a normal WinForm Button object which Click and MouseDown events are captured. These events trigger the real game logic. The number of surrounding mines is calculated (cascading). Mines are dismantled (marked) or explode which is reported to the Game object using events.


Writing the Minesweeper game was a lot of fun. It demonstrates how object orientation really makes it easy. Examine it by stepping trough the code using the VS.NET debugger. I hope you enjoyed this article and sample.

Any suggestions and feedback for improving this article is most welcome. Send your suggestions and feedback to Fons.Sonnemans@reflectionit.nl

Tags: CSharp, Apps

Leave a Comment

Leave a Comment
3 + 1 =


  • Gay
    5 okt 2020 02:18
    Its shit
  • Nan Monash
    4 jun 2018 12:50
    How to get a flood of traffic to your websites in any niche ? Traffic Flood teaches how to get traffic in any niche using FB lead ads and a competition method that makes your traffic go viral !! ++ PLUS You'll Also Get EXCLUSIVE BONUSES for Fast Action-Takers ++ 1.Learn how to set up unlimited passive traffic machines that help you turn visitors and leads into SALES! 2.Learn how to do this in ANY niche 3.Finally get the traffic & profits to make this year your most profitable! 4.Stop burning a hole in your wallet - Start with ONLY $5! Zero risk... 5.Save time by following our exact step-by-step PDF & case study videos 6.Little maintenance after initial setup 7.Works with ANY kind of monetization strategy 8.No longer be a prisoner to slow, unreliable SEO traffic or outdated expensive paid traffic methods! Get Acces Now ==> http://bit.ly/TrafficFloodOk PLUS You'll Also Get EXCLUSIVE BONUSES for Fast Action-Takers
  • Morris Payne
    3 jun 2018 03:04
    Dear Sir (Are you an online marketer, do you own a business or businesses?) I was just looking at your website need to want Real Visitor Or You Website reflectionit.nl Get Seo From Social Marketing. https://www.reflectionit.nl -Visitor Come For Facebook Just Put You Website URL- -You Can Change Website URL 24 Hour- -Real Traffic Will Come From USA and W.Europe- -The Traffic Will Run 24/7-365 System!- -This Is Lifetime Traffic Visitor Facebook- ==Just for reference you can see our work here== [ http://createsplashpages.com/splash.php?id=750 ]
  • Dave King
    24 mei 2018 09:27
    Hi, My name is Dave and I was just looking at your website reflectionit.nl and thought perhaps I would message you on your contact form to see if you need help. I really liked your website but noticed you weren't getting a lot of traffic to your site and your Alexa ranking wasn't as strong as it could be. http://highscoreseo.com I can get 1,000’s of visitors looking at reflectionit.nl, ready to buy your product, service or signup for your offer. Our advertising network of over 9000 websites provides a low cost and effective online marketing solution that actually works. We can help your business get more online quality traffic by advertising your business on websites that are targeted to your market. The internet is a vast entity and kick starting your online business doesn’t have to take a ridiculous amount of cash. We’ll send real people to see your web site starting almost immediately! In fact, I can get 10,000 highly targeted visitors to your website for as little as $29 just so you can test out our service. Right now to make things really exciting you can get 200,000 Targeted visitors to you site in 30 days for only $199. If you'd like to talk personally please give me or Jim a call at 480-331-6775 9 to 5 MST USA. I have a short video here that explains how everything works http://highscoreseo.com Best Regards, Dave HighScoreSEO.com http://highscoreseo.com
  • gowthami
    23 dec 2014 06:22
    how to write code in a application
  • ashok
    20 dec 2014 11:23
    teach me how to write coding pls...
  • hasan
    20 mei 2014 12:05
    I am new
  • hasan
    20 mei 2014 12:04
    I am new programer .how can I programing with c#.
  • Carsen
    13 mei 2014 06:57
    Thank you for this. I'm learning c# and this is well made and organized and really helps.

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.