老师上课教了一个简单连连看游戏的制作。感觉不错!恰巧今年学会了一个游戏——魔兽,最喜欢魔兽的画面,于是就花了五一一天时间做了这个“魔兽连连看游戏”。以下为画面截图。和部分源代码。
可以下载此资源http://download.csdn.net/source/1278212
// lianliankan.cpp : Defines the class behaviors for theapplication.
//
#include "stdafx.h"
#include "lianliankan.h"
#include "lianliankanDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLianliankanApp
BEGIN_MESSAGE_MAP(CLianliankanApp, CWinApp)
//{{AFX_MSG_MAP(CLianliankanApp)
// NOTE - the ClassWizard willadd and remove mapping macros here.
//DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLianliankanApp construction
CLianliankanApp::CLianliankanApp()
{
// TODO: add construction code here,
// Place all significant initialization inInitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CLianliankanApp object
CLianliankanApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CLianliankanApp initialization
BOOL CLianliankanApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wishto reduce the size
// of your final executable,you should remove from the following
// the specific initializationroutines you do not need.
#ifdef _AFXDLL
Enable3dControls();//Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();//Call this when linking to MFC statically
#endif
CLianliankanDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here tohandle when the dialog is
// dismissedwith OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here tohandle when the dialog is
// dismissedwith Cancel
}
// Since the dialog has been closed, returnFALSE so that we exit the
// application, rather thanstart the application's message pump.
return FALSE;
}
// lianliankan.h : main header file for the LIANLIANKANapplication
//
#if!defined(AFX_LIANLIANKAN_H__6A163226_9DA7_429D_9466_43D0B634D4C8__INCLUDED_)
#defineAFX_LIANLIANKAN_H__6A163226_9DA7_429D_9466_43D0B634D4C8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including thisfile for PCH
#endif
#include "resource.h"// mainsymbols
/////////////////////////////////////////////////////////////////////////////
// CLianliankanApp:
// See lianliankan.cpp for the implementation of this class
//
class CLianliankanApp : public CWinApp
{
public:
CLianliankanApp();
// Overrides
// ClassWizard generated virtual functionoverrides
//{{AFX_VIRTUAL(CLianliankanApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CLianliankanApp)
// NOTE - the ClassWizard willadd and remove member functions here.
//DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarationsimmediately before the previous line.
#endif //!defined(AFX_LIANLIANKAN_H__6A163226_9DA7_429D_9466_43D0B634D4C8__INCLUDED_)
// lianliankanDlg.cpp : implementation file
//
#include "StdAfx.h"
#include "lianliankan.h"
#include "lianliankanDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual functionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange*pDX); //DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLianliankanDlg dialog
CLianliankanDlg::CLianliankanDlg(CWnd* pParent )
: CDialog(CLianliankanDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLianliankanDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require asubsequent DestroyIcon in Win32
m_hIcon =AfxGetApp()->LoadIcon(IDR_MAINFRAME);
state = -1;
blank =AfxGetApp()->LoadIcon(IDI_ICON33);
count = 0;
UINTtemp[]={IDI_ICON1,IDI_ICON2,IDI_ICON3,IDI_ICON4,IDI_ICON5,IDI_ICON6,IDI_ICON7,IDI_ICON8,IDI_ICON9,IDI_ICON10,IDI_ICON11,IDI_ICON12,IDI_ICON13,IDI_ICON14,IDI_ICON15,IDI_ICON16,IDI_ICON17,IDI_ICON18,IDI_ICON19,IDI_ICON20,IDI_ICON21,IDI_ICON22,IDI_ICON23,IDI_ICON24,IDI_ICON25,IDI_ICON26,IDI_ICON27,IDI_ICON28,IDI_ICON29,IDI_ICON30,IDI_ICON31,IDI_ICON32,IDI_ICON1,IDI_ICON2,IDI_ICON3,IDI_ICON4,IDI_ICON5,IDI_ICON6,IDI_ICON7,IDI_ICON8,IDI_ICON9,IDI_ICON10,IDI_ICON11,IDI_ICON12,IDI_ICON13,IDI_ICON14,IDI_ICON15,IDI_ICON16,IDI_ICON17,IDI_ICON18,IDI_ICON19,IDI_ICON20,IDI_ICON21,IDI_ICON22,IDI_ICON23,IDI_ICON24,IDI_ICON25,IDI_ICON26,IDI_ICON27,IDI_ICON28,IDI_ICON29,IDI_ICON30,IDI_ICON31,IDI_ICON32};
for(int i=0;i<64;i++){
icon[i] = temp[i];
}
}
void CLianliankanDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLianliankanDlg)
DDX_Control(pDX, IDC_BUTTON9, m_btn9);
DDX_Control(pDX, IDC_BUTTON8, m_btn8);
DDX_Control(pDX, IDC_BUTTON7, m_btn7);
DDX_Control(pDX, IDC_BUTTON64, m_btn64);
DDX_Control(pDX, IDC_BUTTON63, m_btn63);
DDX_Control(pDX, IDC_BUTTON62, m_btn62);
DDX_Control(pDX, IDC_BUTTON61, m_btn61);
DDX_Control(pDX, IDC_BUTTON60, m_btn60);
DDX_Control(pDX, IDC_BUTTON6, m_btn6);
DDX_Control(pDX, IDC_BUTTON59, m_btn59);
DDX_Control(pDX, IDC_BUTTON58, m_btn58);
DDX_Control(pDX, IDC_BUTTON57, m_btn57);
DDX_Control(pDX, IDC_BUTTON56, m_btn56);
DDX_Control(pDX, IDC_BUTTON55, m_btn55);
DDX_Control(pDX, IDC_BUTTON54, m_btn54);
DDX_Control(pDX, IDC_BUTTON53, m_btn53);
DDX_Control(pDX, IDC_BUTTON52, m_btn52);
DDX_Control(pDX, IDC_BUTTON51, m_btn51);
DDX_Control(pDX, IDC_BUTTON50, m_btn50);
DDX_Control(pDX, IDC_BUTTON5, m_btn5);
DDX_Control(pDX, IDC_BUTTON49, m_btn49);
DDX_Control(pDX, IDC_BUTTON48, m_btn48);
DDX_Control(pDX, IDC_BUTTON47, m_btn47);
DDX_Control(pDX, IDC_BUTTON46, m_btn46);
DDX_Control(pDX, IDC_BUTTON45, m_btn45);
DDX_Control(pDX, IDC_BUTTON44, m_btn44);
DDX_Control(pDX, IDC_BUTTON43, m_btn43);
DDX_Control(pDX, IDC_BUTTON42, m_btn42);
DDX_Control(pDX, IDC_BUTTON41, m_btn41);
DDX_Control(pDX, IDC_BUTTON40, m_btn40);
DDX_Control(pDX, IDC_BUTTON4, m_btn4);
DDX_Control(pDX, IDC_BUTTON39, m_btn39);
DDX_Control(pDX, IDC_BUTTON38, m_btn38);
DDX_Control(pDX, IDC_BUTTON37, m_btn37);
DDX_Control(pDX, IDC_BUTTON36, m_btn36);
DDX_Control(pDX, IDC_BUTTON35, m_btn35);
DDX_Control(pDX, IDC_BUTTON34, m_btn34);
DDX_Control(pDX, IDC_BUTTON33, m_btn33);
DDX_Control(pDX, IDC_BUTTON32, m_btn32);
DDX_Control(pDX, IDC_BUTTON31, m_btn31);
DDX_Control(pDX, IDC_BUTTON30, m_btn30);
DDX_Control(pDX, IDC_BUTTON3, m_btn3);
DDX_Control(pDX, IDC_BUTTON29, m_btn29);
DDX_Control(pDX, IDC_BUTTON28, m_btn28);
DDX_Control(pDX, IDC_BUTTON27, m_btn27);
DDX_Control(pDX, IDC_BUTTON26, m_btn26);
DDX_Control(pDX, IDC_BUTTON25, m_btn25);
DDX_Control(pDX, IDC_BUTTON24, m_btn24);
DDX_Control(pDX, IDC_BUTTON23, m_btn23);
DDX_Control(pDX, IDC_BUTTON22, m_btn22);
DDX_Control(pDX, IDC_BUTTON21, m_btn21);
DDX_Control(pDX, IDC_BUTTON20, m_btn20);
DDX_Control(pDX, IDC_BUTTON2, m_btn2);
DDX_Control(pDX, IDC_BUTTON19, m_btn19);
DDX_Control(pDX, IDC_BUTTON18, m_btn18);
DDX_Control(pDX, IDC_BUTTON17, m_btn17);
DDX_Control(pDX, IDC_BUTTON16, m_btn16);
DDX_Control(pDX, IDC_BUTTON15, m_btn15);
DDX_Control(pDX, IDC_BUTTON14, m_btn14);
DDX_Control(pDX, IDC_BUTTON13, m_btn13);
DDX_Control(pDX, IDC_BUTTON12, m_btn12);
DDX_Control(pDX, IDC_BUTTON11, m_btn11);
DDX_Control(pDX, IDC_BUTTON10, m_btn10);
DDX_Control(pDX, IDC_BUTTON1, m_btn1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLianliankanDlg, CDialog)
//{{AFX_MSG_MAP(CLianliankanDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON64,OnButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLianliankanDlg message handlers
BOOL CLianliankanDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to systemmenu.
// IDM_ABOUTBOX must be in the system commandrange.
ASSERT((IDM_ABOUTBOX & 0xFFF0) ==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for thisdialog. The framework does thisautomatically
// when the application's mainwindow is not a dialog
SetIcon(m_hIcon,TRUE);// Setbig icon
SetIcon(m_hIcon,FALSE);// Set small icon
srand((unsigned)time(NULL));
for(int i=0;i<100;i++){
int m = rand()%64;
int n = rand()%64;
UINT temp = icon[m];
icon[m] = icon[n];
icon[n] = temp;
}
HICONIcon1=AfxGetApp()->LoadIcon(icon[1]);
m_btn1.SetIcon(Icon1);
HICONIcon2=AfxGetApp()->LoadIcon(icon[2]);
m_btn2.SetIcon(Icon2);
HICONIcon3=AfxGetApp()->LoadIcon(icon[3]);
m_btn3.SetIcon(Icon3);
HICONIcon4=AfxGetApp()->LoadIcon(icon[4]);
m_btn4.SetIcon(Icon4);
HICONIcon5=AfxGetApp()->LoadIcon(icon[5]);
m_btn5.SetIcon(Icon5);
HICONIcon6=AfxGetApp()->LoadIcon(icon[6]);
m_btn6.SetIcon(Icon6);
HICONIcon7=AfxGetApp()->LoadIcon(icon[7]);
m_btn7.SetIcon(Icon7);
HICONIcon8=AfxGetApp()->LoadIcon(icon[8]);
m_btn8.SetIcon(Icon8);
HICONIcon9=AfxGetApp()->LoadIcon(icon[9]);
m_btn9.SetIcon(Icon9);
HICONIcon10=AfxGetApp()->LoadIcon(icon[10]);
m_btn10.SetIcon(Icon10);
HICONIcon11=AfxGetApp()->LoadIcon(icon[11]);
m_btn11.SetIcon(Icon11);
HICONIcon12=AfxGetApp()->LoadIcon(icon[12]);
m_btn12.SetIcon(Icon12);
HICONIcon13=AfxGetApp()->LoadIcon(icon[13]);
m_btn13.SetIcon(Icon13);
HICONIcon14=AfxGetApp()->LoadIcon(icon[14]);
m_btn14.SetIcon(Icon14);
HICONIcon15=AfxGetApp()->LoadIcon(icon[15]);
m_btn15.SetIcon(Icon15);
HICONIcon16=AfxGetApp()->LoadIcon(icon[16]);
m_btn16.SetIcon(Icon16);
HICONIcon17=AfxGetApp()->LoadIcon(icon[17]);
m_btn17.SetIcon(Icon17);
HICONIcon18=AfxGetApp()->LoadIcon(icon[18]);
m_btn18.SetIcon(Icon18);
HICONIcon19=AfxGetApp()->LoadIcon(icon[19]);
m_btn19.SetIcon(Icon19);
HICONIcon20=AfxGetApp()->LoadIcon(icon[20]);
m_btn20.SetIcon(Icon20);
HICONIcon21=AfxGetApp()->LoadIcon(icon[21]);
m_btn21.SetIcon(Icon21);
HICONIcon22=AfxGetApp()->LoadIcon(icon[22]);
m_btn22.SetIcon(Icon22);
HICONIcon23=AfxGetApp()->LoadIcon(icon[23]);
m_btn23.SetIcon(Icon23);
HICONIcon24=AfxGetApp()->LoadIcon(icon[24]);
m_btn24.SetIcon(Icon24);
HICONIcon25=AfxGetApp()->LoadIcon(icon[25]);
m_btn25.SetIcon(Icon25);
HICONIcon26=AfxGetApp()->LoadIcon(icon[26]);
m_btn26.SetIcon(Icon26);
HICONIcon27=AfxGetApp()->LoadIcon(icon[27]);
m_btn27.SetIcon(Icon27);
HICONIcon28=AfxGetApp()->LoadIcon(icon[28]);
m_btn28.SetIcon(Icon28);
HICONIcon29=AfxGetApp()->LoadIcon(icon[29]);
m_btn29.SetIcon(Icon29);
HICONIcon30=AfxGetApp()->LoadIcon(icon[30]);
m_btn30.SetIcon(Icon30);
HICONIcon31=AfxGetApp()->LoadIcon(icon[31]);
m_btn31.SetIcon(Icon31);
HICONIcon32=AfxGetApp()->LoadIcon(icon[32]);
m_btn32.SetIcon(Icon32);
HICONIcon33=AfxGetApp()->LoadIcon(icon[33]);
m_btn33.SetIcon(Icon33);
HICONIcon34=AfxGetApp()->LoadIcon(icon[34]);
m_btn34.SetIcon(Icon34);
HICONIcon35=AfxGetApp()->LoadIcon(icon[35]);
m_btn35.SetIcon(Icon35);
HICONIcon36=AfxGetApp()->LoadIcon(icon[36]);
m_btn36.SetIcon(Icon36);
HICONIcon37=AfxGetApp()->LoadIcon(icon[37]);
m_btn37.SetIcon(Icon37);
HICONIcon38=AfxGetApp()->LoadIcon(icon[38]);
m_btn38.SetIcon(Icon38);
HICONIcon39=AfxGetApp()->LoadIcon(icon[39]);
m_btn39.SetIcon(Icon39);
HICONIcon40=AfxGetApp()->LoadIcon(icon[40]);
m_btn40.SetIcon(Icon40);
HICONIcon41=AfxGetApp()->LoadIcon(icon[41]);
m_btn41.SetIcon(Icon41);
HICONIcon42=AfxGetApp()->LoadIcon(icon[42]);
m_btn42.SetIcon(Icon42);
HICONIcon43=AfxGetApp()->LoadIcon(icon[43]);
m_btn43.SetIcon(Icon43);
HICONIcon44=AfxGetApp()->LoadIcon(icon[44]);
m_btn44.SetIcon(Icon44);
HICONIcon45=AfxGetApp()->LoadIcon(icon[45]);
m_btn45.SetIcon(Icon45);
HICONIcon46=AfxGetApp()->LoadIcon(icon[46]);
m_btn46.SetIcon(Icon46);
HICONIcon47=AfxGetApp()->LoadIcon(icon[47]);
m_btn47.SetIcon(Icon47);
HICONIcon48=AfxGetApp()->LoadIcon(icon[48]);
m_btn48.SetIcon(Icon48);
HICONIcon49=AfxGetApp()->LoadIcon(icon[49]);
m_btn49.SetIcon(Icon49);
HICONIcon50=AfxGetApp()->LoadIcon(icon[50]);
m_btn50.SetIcon(Icon50);
HICONIcon51=AfxGetApp()->LoadIcon(icon[51]);
m_btn51.SetIcon(Icon51);
HICONIcon52=AfxGetApp()->LoadIcon(icon[52]);
m_btn52.SetIcon(Icon52);
HICONIcon53=AfxGetApp()->LoadIcon(icon[53]);
m_btn53.SetIcon(Icon53);
HICONIcon54=AfxGetApp()->LoadIcon(icon[54]);
m_btn54.SetIcon(Icon54);
HICONIcon55=AfxGetApp()->LoadIcon(icon[55]);
m_btn55.SetIcon(Icon55);
HICONIcon56=AfxGetApp()->LoadIcon(icon[56]);
m_btn56.SetIcon(Icon56);
HICONIcon57=AfxGetApp()->LoadIcon(icon[57]);
m_btn57.SetIcon(Icon57);
HICONIcon58=AfxGetApp()->LoadIcon(icon[58]);
m_btn58.SetIcon(Icon58);
HICONIcon59=AfxGetApp()->LoadIcon(icon[59]);
m_btn59.SetIcon(Icon59);
HICONIcon60=AfxGetApp()->LoadIcon(icon[60]);
m_btn60.SetIcon(Icon60);
HICONIcon61=AfxGetApp()->LoadIcon(icon[61]);
m_btn61.SetIcon(Icon61);
HICONIcon62=AfxGetApp()->LoadIcon(icon[62]);
m_btn62.SetIcon(Icon62);
HICONIcon63=AfxGetApp()->LoadIcon(icon[63]);
m_btn63.SetIcon(Icon63);
HICONIcon64=AfxGetApp()->LoadIcon(icon[0]);
m_btn64.SetIcon(Icon64);
beginTime = CTime::GetCurrentTime();
// TODO: Add extra initialization here
return TRUE; // returnTRUE unless you set the focus to a control
}
void CLianliankanDlg::OnSysCommand(UINT nID, LPARAMlParam)
{
if ((nID & 0xFFF0) ==IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID,lParam);
}
}
// If you add a minimize button to your dialog, you will needthe code below
// to draw the icon. For MFCapplications using the document/view model,
// this is automatically done for you by theframework.
void CLianliankanDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // devicecontext for painting
SendMessage(WM_ICONERASEBKGND,(WPARAM) dc.GetSafeHdc(), 0);
// Center icon in clientrectangle
int cxIcon =GetSystemMetrics(SM_CXICON);
int cyIcon =GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon+ 1) / 2;
int y = (rect.Height() - cyIcon+ 1) / 2;
// Draw the icon
dc.DrawIcon(x, y,m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display whilethe user drags
// the minimized window.
HCURSOR CLianliankanDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLianliankanDlg::OnButton(UINT nID){
state = -state;
CButton* cb = (CButton*)GetDlgItem(nID);
if(state>0){
cb1 = cb;
icon1 =cb->GetIcon();
}else if(state<0){
cb2 = cb;
icon2 =cb->GetIcon();
if(icon1==icon2&&cb1!=cb2&&cb1->GetIcon()!=blank){
cb1->SetIcon(blank);
cb2->SetIcon(blank);
count+=2;
if(count==64){
endTime= CTime::GetCurrentTime();
CTimeSpanduration = endTime - beginTime;
MessageBox("恭喜你,勇士!你的魔兽等级将增加一级!本次游戏用时:"+duration.Format("%M")+"分"+duration.Format("%S")+"秒","",MB_OK);
}
}else{
}
}
UpdateData(FALSE);
}