Click here to Skip to main content
15,878,953 members
Articles / Multimedia / GDI
Article

Desktop Puzzle Game

Rate me:
Please Sign up or sign in to vote.
4.44/5 (31 votes)
12 Sep 2006CPOL 69.2K   1.4K   38   13
A Desktop puzzle game.

Introduction

This is a known but a different puzzle game. The images of puzzles are not included; in fact, the images are captured from your desktop! First of all, you can select the game difficulty: easy, medium, hard, and by pressing the Start button, the game will begin after the number of seconds you have specified (default is 2 seconds).

Game instructions

  • to move a rectangle, select the first and then a second one by clicking on the rectangles.
  • to rotate a rectangle by 180 degrees, right click on the rectangle.
  • to reveal the borders of each slice, you can click the middle button of the mouse.

Sample Image - Desktop_Puzzle_Game.jpg

Here are the main methods:

C#
// - Saves the bitmap of display DC to a memory DC
void        CaptureDesktop();

// - Replaces two rects in memory device context
void        ReplaceRects(CRect rectSource, CRect rectDest);

// - Inverts selected rect
void        InvertRect(CRect rect);

// - Draws a frame around a rectangle
void        FrameRect(CRect rect, BOOL bClear=FALSE);

// - Draws a frame around all rectangles
void        DrawFrames();

// - Checks if user has been corrected all rectangles
int        CheckForWin();

// - Returns rect of selected square
CRect        GetSquareFromPoint(CPoint point);

// - Select a rectangle (source) or Replace first selected rectangle (source) 
//   with new selected rectangle (destination)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

// - Draw all frames for help or clear them all
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);

// - Invert selected rectangle
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);

// - Checks for number of wrong items
afx_msg void OnExit();

// - Draws wrong items
afx_msg void OnTimer(UINT nIDEvent);

This is not a new game, just an attempt to help others on how to write such programs and may be find some techniques from this. Any suggestions and refinements are welcome. Enjoy the game!

License

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


Written By
Software Developer (Senior) www.LogicSims.ir
Iran (Islamic Republic of) Iran (Islamic Republic of)
Hadi Dayvary graduated from Azad University in spring 2003 in Apply Mathematics.
Started Visual C++ in 1999.
He likes to program all the time.
He lives in Iran.
www.LogicSims.ir

Comments and Discussions

 
Generalnice one i like it Pin
zzx_12345624-Jun-09 23:13
zzx_12345624-Jun-09 23:13 
Generalsend project Pin
farzaneh13651-May-08 0:06
farzaneh13651-May-08 0:06 
GeneralRe: send project Pin
Hadi Dayvary2-May-08 18:50
professionalHadi Dayvary2-May-08 18:50 
Generalnice Pin
bhage15-Sep-06 19:22
bhage15-Sep-06 19:22 
GeneralRe: nice Pin
Hadi Dayvary25-Oct-23 1:44
professionalHadi Dayvary25-Oct-23 1:44 
GeneralNice Idea Pin
NormDroid12-Sep-06 4:54
professionalNormDroid12-Sep-06 4:54 
GeneralGood idea & some suggestion. Pin
jcem16-Jul-06 22:04
jcem16-Jul-06 22:04 
GeneralA great idea, and some challenges ahead... Pin
Jun Du31-May-06 3:14
Jun Du31-May-06 3:14 
GeneralRe: A great idea, and some challenges ahead... Pin
Hadi Dayvary31-May-06 21:10
professionalHadi Dayvary31-May-06 21:10 
GeneralRe: A great idea, and some challenges ahead... Pin
Jun Du1-Jun-06 13:20
Jun Du1-Jun-06 13:20 
GeneralGreat Article Pin
SBaghestani31-May-06 0:17
SBaghestani31-May-06 0:17 
GeneralRe: Rubbish Article but interesting project Pin
Michael P Butler15-Jul-06 23:07
Michael P Butler15-Jul-06 23:07 
GeneralI like it Pin
qiuqianren30-May-06 23:45
qiuqianren30-May-06 23:45 

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.