一、游戏说明如下:

打中老鼠加一分,当得分值小于10分时,老鼠每0.8秒出现一次,当得分值大于等于10分并且小于50分时,老鼠每0.6秒出现一次。当得分值大于等于50分时,老鼠每0.4秒出现一次。这个游戏是参考别人的部分代码,并在其基础上改进了一些。具体代码如下:

1、

// dadishuDlg.h : header file
//#if !defined(AFX_DADISHUDLG_H__40135455_30B1_45C8_B123_A78832063FD4__INCLUDED_)
#define AFX_DADISHUDLG_H__40135455_30B1_45C8_B123_A78832063FD4__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000/
// CDadishuDlg dialogclass CDadishuDlg : public CDialog
{
// Construction
public:CTime t;CButton * pMouse[12];CString strTime;int nowMouse;int gameScore;int hour,minute,second;CDadishuDlg(CWnd* pParent = NULL);   // standard constructor// Dialog Data//{{AFX_DATA(CDadishuDlg)enum { IDD = IDD_DADISHU_DIALOG };// NOTE: the ClassWizard will add data members here//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CDadishuDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);   // DDX/DDV supportvirtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);//}}AFX_VIRTUAL// Implementation
protected:HICON m_hIcon;// Generated message map functions//{{AFX_MSG(CDadishuDlg)virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();afx_msg void OnContinue();afx_msg void OnPause();afx_msg void OnTimer(UINT nIDEvent);afx_msg void OnStart();afx_msg void OnCancel();//}}AFX_MSGDECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DADISHUDLG_H__40135455_30B1_45C8_B123_A78832063FD4__INCLUDED_)

2、

// dadishuDlg.cpp : implementation file
//#include "stdafx.h"
#include "dadishu.h"
#include "dadishuDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)enum { IDD = IDD_ABOUTBOX };//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementation
protected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_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()/
// CDadishuDlg dialogCDadishuDlg::CDadishuDlg(CWnd* pParent /*=NULL*/): CDialog(CDadishuDlg::IDD, pParent)
{//{{AFX_DATA_INIT(CDadishuDlg)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32hour=0;minute=0;second=0;m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CDadishuDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CDadishuDlg)// NOTE: the ClassWizard will add DDX and DDV calls here//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CDadishuDlg, CDialog)//{{AFX_MSG_MAP(CDadishuDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_CONTINUE, OnContinue)ON_BN_CLICKED(IDC_PAUSE, OnPause)ON_WM_TIMER()ON_BN_CLICKED(IDC_START, OnStart)ON_BN_CLICKED(IDC_CANCEL, OnCancel)//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// CDadishuDlg message handlersBOOL CDadishuDlg::OnInitDialog()
{CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.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 this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);            // Set big iconSetIcon(m_hIcon, FALSE);     // Set small icon// TODO: Add extra initialization heregameScore=0;//分数nowMouse=0;//当前老鼠GetDlgItem(IDC_PAUSE)->EnableWindow(FALSE);GetDlgItem(IDC_CONTINUE)->EnableWindow(FALSE);for (int i=0;i<12;i++){//获取12个按钮的指针pMouse[i]=(CButton *)GetDlgItem(IDC_BUTTON1+i);}return TRUE;  // return TRUE  unless you set the focus to a control
}void CDadishuDlg::OnSysCommand(UINT nID, LPARAM lParam)
{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 need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.void CDadishuDlg::OnPaint()
{if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangleint 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 icondc.DrawIcon(x, y, m_hIcon);}else{CDialog::OnPaint();}
}// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDadishuDlg::OnQueryDragIcon()
{return (HCURSOR) m_hIcon;
}void CDadishuDlg::OnContinue()
{// TODO: Add your control notification handler code hereGetDlgItem(IDC_PAUSE)->EnableWindow(TRUE);GetDlgItem(IDC_CONTINUE)->EnableWindow(FALSE);GetDlgItem(IDC_START)->EnableWindow(FALSE);SetTimer(1,800,NULL);SetTimer(2,1000,NULL);}void CDadishuDlg::OnPause()
{// TODO: Add your control notification handler code hereKillTimer(1);KillTimer(2);GetDlgItem(IDC_PAUSE)->EnableWindow(FALSE);GetDlgItem(IDC_START)->EnableWindow(FALSE);GetDlgItem(IDC_CONTINUE)->EnableWindow(TRUE);}void CDadishuDlg::OnTimer(UINT nIDEvent)
{// TODO: Add your message handler code here and/or call defaultswitch(nIDEvent){case 1:pMouse[nowMouse]->SetIcon(0);//清除当前按钮上的老鼠nowMouse=rand()%12;//随机产生下一个老鼠pMouse[nowMouse]->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON1));break;case 2:second++;if(second==60)//设置钟表的显示{minute++;second=0;}if(minute==60){hour++;minute=0;}strTime.Format("%02d:%02d:%02d",hour,minute,second);//显示时间进度CWnd *pWnd=GetDlgItem(IDC_STATIC_time);pWnd->SetWindowText(strTime); //在设置时间新值,表明定时器已经工作。break;}CDialog::OnTimer(nIDEvent);
}BOOL CDadishuDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{// TODO: Add your specialized code here and/or call the base classCString str;for (int i=0;i<12;i++){if (LOWORD(wParam)==pMouse[i]->GetDlgCtrlID())//当前id与次元id相同,则选中{break;}}//i是当前选中老鼠编号if (nowMouse==i){gameScore++;str.Format("%d",gameScore);CStatic *pStatic=(CStatic *)GetDlgItem(IDC_STATIC_score);pStatic->SetWindowText(str);if (gameScore>=10){SetTimer(1,600,NULL);if (gameScore>=50){SetTimer(1,400,NULL);}}}return CDialog::OnCommand(wParam, lParam);
}void CDadishuDlg::OnStart()
{// TODO: Add your control notification handler code hereGetDlgItem(IDC_PAUSE)->EnableWindow(TRUE);GetDlgItem(IDC_CONTINUE)->EnableWindow(FALSE);SetTimer(1,800,NULL);SetTimer(2,1000,NULL);}void CDadishuDlg::OnCancel()
{// TODO: Add your control notification handler code hereCDialog::OnCancel();}

3、运行效果如下:

MFC制作打地鼠小游戏相关推荐

  1. matlab制作打地鼠游戏,Python制作打地鼠小游戏

    原标题:Python制作打地鼠小游戏 导语 大家好,欢迎来到 Crossin的编程教室 ! 打地鼠游戏相信大家都知道,这里就不多介绍了,反正就是不停地拿锤子打洞里钻出来的地鼠呗~ 今天就给大家分享一个 ...

  2. 如何用python制作五子棋游戏_Python制作打地鼠小游戏

    原文链接 Python制作小游戏(二十一)​mp.weixin.qq.com 效果展示 打地鼠小游戏https://www.zhihu.com/video/1200492442610450432 简介 ...

  3. python小游戏制作软件_Python制作打地鼠小游戏

    原文链接Python制作小游戏(二十一)​mp.weixin.qq.com 效果展示打地鼠小游戏https://www.zhihu.com/video/1200492442610450432 简介 打 ...

  4. android打地鼠设计报告,android开发中利用handler制作一个打地鼠小游戏

    android开发中利用handler制作一个打地鼠小游戏 发布时间:2020-11-25 15:21:11 来源:亿速云 阅读:136 作者:Leah 这期内容当中小编将会给大家带来有关androi ...

  5. matlab制作打地鼠游戏,scratch编程制作打地鼠的游戏教程

    scratch编程制作打地鼠的游戏教程Sk1少儿编程网-https://www.pxcodes.com Sk1少儿编程网-https://www.pxcodes.com 首先,新建背景和角色,从背景库 ...

  6. linux打地鼠游戏代码,JavaScript实现打地鼠小游戏

    一.实验说明 1. 环境介绍 本实验环境采用Ubuntu Linux桌面环境,实验中会用到桌面上的程序: Xfce终端: Linux命令行终端,打开后会进入Bash环境,可以使用Linux命令 Fir ...

  7. java 打地鼠 源代码_Java实现的打地鼠小游戏完整示例【附源码下载】

    本文实例讲述了Java实现的打地鼠小游戏.分享给大家供大家参考,具体如下: 这里涉及到java线程和GUI的相关知识,一个简单的java小游戏打地鼠,有兴趣的朋友可以优化一下.先来看看运行效果: 具体 ...

  8. python编的俄罗斯方块游戏_手把手制作Python小游戏:俄罗斯方块(一)

    手把手制作Python小游戏:俄罗斯方块1 大家好,新手第一次写文章,请多多指教 A.准备工作: 这里我们运用的是Pygame库,因为Python没有内置,所以需要下载 如果没有pygame,可以到官 ...

  9. python图形小游戏代码_手把手制作Python小游戏:俄罗斯方块(一)

    手把手制作Python小游戏:俄罗斯方块1 大家好,新手第一次写文章,请多多指教 A.准备工作: 这里我们运用的是Pygame库,因为Python没有内置,所以需要下载 如果没有pygame,可以到官 ...

最新文章

  1. Deep Learning论文笔记之(七)深度网络高层特征可视化
  2. 1013 B. And
  3. java发送c语言结构体_C语言中结构体直接赋值?
  4. java设计模式4-装饰者模式
  5. 【优化算法】粒子群的混沌混合蝴蝶优化算法【含Matlab源码 047期】
  6. 网格搜索、随机搜索和贝叶斯调参总结与python代码实践
  7. 离线渲染与实时渲染杂谈 ——从发布会上的产品展示说起
  8. ROS学习笔记(三)—— 话题 topic详解
  9. 完成“LPS node 与Crazyflie在TWR协议下的成功双向测距”实现心路历程总结
  10. Spring boot 获取本机的IP地址mac地址以及电脑名称!
  11. Windows10 64位系统设置FRPC开机自动启动
  12. golang: 密码中允许出现数字、大写字母、小写字母、特殊字符,但至少包含其中2种且长度在8-16之间(四种符号任意满足三种即可)
  13. EVE-NG模拟器教程(三)——Lab平台初探
  14. Linux 远程复制命令scp命令的使用
  15. Ubuntu 20.04下搭建奥比中光-Astra(详细教程)
  16. 智能信息处理大学生科技实践与创新(3I)工作室
  17. 一键生成controller、service、mapper、model、po
  18. 品优购静态页面(html+css)——商品详情页
  19. Comet OJ - Contest #8 E神奇函数(莫比乌斯函数容斥)
  20. android源码宇宙-Glide

热门文章

  1. spark调用python_在MRS集群中使用Python3.7运行PySpark程序,调用RDD的take函数报错处理...
  2. 再介绍一篇Contrastive Self-supervised Learning综述论文
  3. 一站式机器学习平台建设实践
  4. 论文浅尝 | 基于表示学习的大规模知识库规则挖掘
  5. 腾讯2013实习生笔试题+答案1-5aadaa 6-10adbcc 11-15 acacc16-20 bbddc
  6. 如何实现一个循环显示超长图片的控件
  7. 美商务部再禁6项新兴技术,包括光刻软件和5nm生产技术
  8. PHP7 ini 配置大全
  9. R语言排序 -- sort() order() rank()
  10. Django 模板系统2