游戏应用程序"-Memory Plus +"(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/game-application-memory-plus-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1876 个词 阅读量 0游戏应用程序"-Memory Plus +"(译文)
原文地址:https://www.codeproject.com/Articles/27886/Game-Application-Memory-Plus
原文作者:Shanmuga Sundar.V
译文由本站 robot-v1.0 翻译
前言
Simple memory game
简单的记忆游戏
介绍(Introduction)
我想回想起我在MFC中的知识,因此在中断两年后,我开始以游戏软件+ Memory Plus-的形式开发此应用程序.这是您可能遇到的一个简单的游戏应用程序.我一直对编码游戏软件感兴趣.最初,我有实现此记忆游戏的逻辑.后来,我引入了一个附加选项,使它正常运行.而且我想探索更多的VC ++和MFC库,因此我仅使用VC ++和MFC库进行所有开发.(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 the Game)
Memory plus是一款通用游戏,易于玩耍.界面显示了一组没有图像的积木或按钮.单击任何一个砖块后,将显示一个特定的图像,然后单击下一个立即单击将显示其图像.现在,如果两个图像都匹配,则将从视图中清除两个积木.否则,用户必须通过记住匹配来尝试匹配图像.经验法则是清除所有积木,以最少的点击次数和最短的时间完成游戏,然后记录您的名字以获得高分.(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:)
- 使用MFC编写小型游戏应用程序(Write a small game application using MFC)
- 在按钮上加载图像(Load image on buttons)
- 在文本控件上加载图像(Load image on text control)
- 在对话框背景上加载图像(Load image on dialog background)
- 更改静态和文本控件的背景颜色和文本颜色(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.)
历史(History)
- 17(17)日(th)2008年7月:初始版本(July, 2008: Initial version)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ Windows .NET .NET3.0 MFC Dev 新闻 翻译