1、 面面向向对对象象程程序序设设计计 课课程程设设计计 题 目: 吃豆子游戏程序 院 系: 数学与计算科学学院 专 业: 信息与计算科学 指导老师: 日 期: 2014 年 12 月 30 日 心得体会: 通过这次课程设计,我从对 MFC 的陌生到能熟练运 用基本的函数,了解其编程的具体实现方法,我对于面象 对向编程有了更深刻的认识,通过四个人的团队合作,我 从主持谐调各方面工作,如听取各方面意见,看成员整理 好的资料,到担任代码编写,学会了团队合作的重要性, 团队合作在写大的程序时比单个人完成有很大的优点。我 会继续在面向对象编程上下功夫,因为学无止境。 摘 要 MFC 是 Windows 编
2、程的面向对象化,是对 Windows 函数的简单封装, 使用 MFC 编程可以在短时间内编写一个 Windows 程序,而不必写大量 Windows代码,所以我使用 MFC 编写了一个吃豆子程序,该程序实现了一个能 过使用方向键控制消除屏幕上存在的豆子的功能,当用户按键盘向上、下、 左、 右键或每格一秒钟,嘴的状态发生改变,或是从一个方向张开向另一个方向, 或是由张开变成闭合状态,从而实现嘴一张一合前进,当嘴所经过位置有豆子, 豆子被消除而不再出现,所有豆子被“吃”完时,程序弹出对话框“You win ,Exit?” ,用户点确定后可退出程序。 实现方法:嘴的张开与闭合分别用 MFC 的 Pi
3、e 和 Ellipse 函数实现,豆子被存储在一个标记数组中, 豆子被吃时数组相 应元素标记为零。在 OnDraw()函数中画出每个豆子和嘴的原始位置,在响应 键盘上下左右方向虚拟键 VK_UP、VK_DOWN、VK_LEFT、VK_RIGTH 的 函数中控制豆子移动和嘴的方向,程序开始时在响应 WM_CREATE 消息的 函数中设置一个 TIMER,方向键消息和 TIMER 消息统一由一个判断函数处 理从而实现自动前进时的沿当前方向前进。 关键字:关键字:程序设计 豆子 MFC Abstract MFC is a Windows-based object-oriented programmi
4、ng, it is a simple package of Windows function , using the MFC programming can make us write a Windows program in a short time, without having to write a lot of Windows code, so I use MFC written a eat-beans program ,in this program we can use the arrow keys to control the mouth to move to eliminati
5、ng the beans on the screen, when the user presses the keyboard up, down, left, right, or each time one second goes by, the state of the mouth changed, it change from one direction to another direction, or from an opening state to a closed state. So we can obtain a mouth moving forward with its lips
6、keeping closing and opening, if a bean is in the way of the mouth, it will be eliminated by setting its element in the mark array as zero. when all beans have bean eaten, a dialog box prompts: “You win, Exit?“, after the user clicks OK , the game terminates. Implementation method: We can use the MFCs Pie function to draw a open mouth, while the Ellipse function to draw the closed mouth, all beans would be