Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / C++
Article

XMineSweeper

Rate me:
Please Sign up or sign in to vote.
4.84/5 (17 votes)
25 Feb 2006CPOL2 min read 91K   1.9K   18   30
A simulation of the famous MineSweeper game by Microsoft.

Sample Image - XMineSweeper.jpg

Introduction

The XMineSweeper is a simulation for the famous 'MineSweeper' game by Microsoft which is shipped with its Windows operating system.

It is a light game that can help you spend some minutes with fun, far from coding problems.

Benefits

I know it sounds silly to make the MineSweeper which is already developed for best outputs by the software gurus at Microsoft, but it was first an assignment for joining a job in a firm (without mentioning its name, Sakhr).

But after development, it was really fun, and it made me learn some practical skills.

Features

Using the resources bitmap files from the original MineSweeper (%windir%\System32\winmine.exe) for drawing with GDI, I tried to make it look like the original by drawing 3D-like lines (by drawing white line on one side, and a gray one on the other side to make it feels like the effect of light and shadow).

The CMineSweeper Class

Here comes the main class for the game which manages the sequence of the game (this is how we learn the Game Engine from game developers). The class responds to user clicks, checks for mines, and draws the output for the 'Device Context' passed to it.

void CMineSweeper::Draw(CDC *pDC);

The draw function is essential for rendering the game to the CDC object passed to it. This design avoids the problem of flicker, by calling this function in the WM_PAINT message, and also call it when we need to update the view for the user.

Handle both right and left mouse button down

Handling the middle mouse button down is straight (ON_WM_MBUTTONUP()), but to handle both right-left mouse buttons down, you have to add a small check for the other button using the API function GetKeyState() which is used by game developers when they can't wait for the message to be sent, rather they go checking for it by themselves.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Egypt Egypt
C# C++
GDI
MFC
ASP.NET

Comments and Discussions

 
GeneralRe: good job Pin
Maged Abdelkhalek11-Mar-09 7:39
Maged Abdelkhalek11-Mar-09 7:39 
QuestionNice...? Pin
Lee Middle25-Feb-06 5:43
Lee Middle25-Feb-06 5:43 
AnswerRe: Nice...? Pin
Ahmad_Hashem25-Feb-06 9:18
Ahmad_Hashem25-Feb-06 9:18 
GeneralRe: Nice...? Pin
Lee Middle25-Feb-06 18:47
Lee Middle25-Feb-06 18:47 
GeneralRe: Nice...? Pin
Ahmad_Hashem26-Feb-06 7:19
Ahmad_Hashem26-Feb-06 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.