Click here to Skip to main content
6,822,613 members and growing! (20,647 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Game Development » Games     Intermediate License: The Code Project Open License (CPOL)

Game Application "- Memory Plus +"

By Shanmuga Sundar.V

Simple memory game
C++, Windows, .NET (.NET3.0), MFC, Dev
Posted:17 Jul 2008
Views:11,276
Bookmarked:12 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 3.32 Rating: 3.08 out of 5
2 votes, 16.7%
1
3 votes, 25.0%
2
1 vote, 8.3%
3
1 vote, 8.3%
4
5 votes, 41.7%
5

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


Member
Module Lead working in leading MNC company, india - bangalore.
Occupation: Architect
Location: India India

Other popular Game Development articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
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    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 17 Jul 2008
Editor: Sean Ewington
Copyright 2008 by Shanmuga Sundar.V
Everything else Copyright © CodeProject, 1999-2010
Web19 | Advertise on the Code Project