Click here to Skip to main content
Licence CPOL
First Posted 17 Jul 2008
Views 18,616
Downloads 754
Bookmarked 17 times

Game Application "- Memory Plus +"

By Shanmuga Sundar.V | 17 Jul 2008
Simple memory game
2 votes, 15.4%
1
3 votes, 23.1%
2
1 vote, 7.7%
3
2 votes, 15.4%
4
5 votes, 38.5%
5
3.12/5 - 13 votes
μ 3.12, σa 2.82 [?]

Introduction

I wanted to recall my knowledge in MFC, so after a two year break, I started with developing this application as Game software + Memory Plus - . It is a simple game application which you have probably come across. I have always been interested in coding game software. I initially got logic for implementing this memory game. Later I brought in an additional option and made it work gracefully. And I wanted to explore more of VC++ and MFC libraries so I did all development using only VC++ & MFC libraries.

About Game

Memory plus is a generic game and simple to play. The interface shows a set of bricks or buttons with no images. Upon clicking any one brick a particular image will be shown then followed with the next immediate click its image will be shown. Now if both the images match, then both the bricks will get cleared from the view. Else, the user has to try matching the images by remembering the matches. The rule of thumb is to clear all the bricks to finish the game with a minimal number of clicks and in a minimum time then log your name for a highscore.

The time will start once the game has been initiated — either by clicking on the "Start" menu or clicking any bricks. The game can be paused at any time, in which case time slice will also be stopped. The game can also be restarted by clicking on the "New" menu. Upon clicking the "Highscore" menu, highscore information will be available.

Game Option

The game provides the following options

  • Images: the images option provides user flexibility for changing the images used on the bricks at anytime even while playing the game or before starting the game.
  • Size: the size option has been provided to modify the even matrix either to reduce or increase the bricks area.

    Note: If the size is modified, the game will restart as new game.

  • "Game help" will provide a brief instruction for the user regarding the game rules and options.

Using the Code

Understanding the code will be easy for the user. This code will guide you on how to:

  1. Write a small game application using MFC.
  2. Load image on buttons.
  3. Load image on text control.
  4. Load image on dialog background.
  5. Changes background color and text color of the static and text control.

Core code of the game:

void CSundar_GameDlg::LoadIcons(int NoBtns)
{
    int hIndex, index1;
    int ran;

    index1 = hIndex = 0;
    ran = 0;

    srand( (unsigned)time( NULL ) );
    for(int index = 0; index < (NoBtns) ; index++)
    {
        do
        {
            ran = rand();
            ran %= (NoBtns);
            index1 = 0;
            for(index1 = 0; index1 < index ; index1++)
            {
                if(ran == Array[index1])
                {
                    index1 = -1;
                    ran = rand();
                    ran %= (NoBtns);
                    continue;
                }
            }
        }while ( ran < 0 || ran >= NoBtns);

        Array[hIndex] = ran;

        hIndex++;
    }

    for(index = 0; index < NoBtns ; index++)
    {
        if(Array[index] >= (NoBtns/2))
        {
            Array[index] -= (NoBtns/2);
        }
    }
}

void CSundar_GameDlg::CheckMatchIcon(int BtnIndex)
{
    NumClick++;

    if(Init == FALSE)
    {
        Init = TRUE;
        OnGamePause();
    }

    if(ClickNo > 2)
    {
        DisplayIcon(CurBtnIndex, NULL);
        DisplayIcon(SelBtnIndex, NULL);
        SelBtnIndex = BtnIndex;
        CurBtnIndex = BtnIndex;
        DisplayIcon(CurBtnIndex, hIcon[Array[BtnIndex]]);
        ClickNo = 2;
    }
    else
        if(ClickNo == 2)
        {
            CurBtnIndex = BtnIndex;
            DisplayIcon(CurBtnIndex, hIcon[Array[BtnIndex]]);
            ClickNo++;

            if(CurBtnIndex != SelBtnIndex)
            {
                unsigned int diff = Array[CurBtnIndex] - Array[SelBtnIndex];
                if( diff == 0)
                {
                    DisplayIcon(CurBtnIndex, NULL, TRUE);
                    DisplayIcon(SelBtnIndex, NULL, TRUE);
                    if(CheckNoOfButton <= 0)
                    {
                        DlgState = 1;
                        Init = FALSE;
                        KillTimer(2);

                        TimeScore = Min;
                        NoOfClick = NumClick;
                        CScoreDlg Dlg;
                        Dlg.DoModal();

                        DlgState = 2;
                        Dlg.DoModal();

                    }
                }
                else
                {
                    SetTimer(1, 1500, NULL);
                }
            }
        }
        else if(ClickNo == 1)
        {
            SelBtnIndex = BtnIndex;
            CurBtnIndex = BtnIndex;
            ClickNo++;

            DisplayIcon(CurBtnIndex, hIcon[Array[BtnIndex]]);
        }
}

Conclusion

I would like to thank all my friends and colleagues who gave better ideas and suggestions in making this game better and more user friendly. Hope you enjoy this game.

License

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

About the Author

Shanmuga Sundar.V

Architect

India India

Member
Module Lead working in leading MNC company, india - bangalore.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUI needs more professionalism. PinmemberSreekanth Muralidharan23:55 5 Oct '08  
GeneralRe: UI needs more professionalism. PinmemberShanmuga Sundar.V21:55 14 Oct '08  
GeneralDone a good job... Pinmemberjalaldrg5:06 22 Jul '08  
GeneralHI PAN SHOD PinmemberMrGoodly16:58 18 Jul '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120209.1 | Last Updated 17 Jul 2008
Article Copyright 2008 by Shanmuga Sundar.V
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid