MFC的破泡器(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/bubble-breaker-by-mfc-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1270 个词 阅读量 0MFC的破泡器(译文)
原文地址:https://www.codeproject.com/Articles/43222/Bubble-Breaker-by-MFC
原文作者:cdh928
译文由本站 robot-v1.0 翻译
前言
*Plant bubble breaker’s game from WinCE to Windows XP by MFC *
从WinCE到Windows XP,通过MFC植入破坏泡沫的游戏
介绍(Introduction)
这是一个"泡沫破坏者"游戏.它与一般(This is a “bubble breaker” game. It comes along with general) CWnd
:(:)
CBubbleBreakerPanel
CBubbleMovingTool
CBubble2DArray
CBubbleImageList
CScene
CUndoManager
CBubbleSelector
背景(Background)
我喜欢oopdreams软件公司为WindowCE开发的Bubble Breaker游戏,所以我想通过MFC将其植入Windows XP.(I liked Bubble Breaker game for WindowCE developed by oopdreams software Inc., so I wanted to plant it to Windows XP by MFC.)
使用代码(Using the Code)
CBubbleBreakerPanel
来自(is derived from) CWnd
,这是主要框架.它处理鼠标和键盘事件,并处理GDI绘图等.(,and it is the main framework. It handles mouse and Keyboard events, and handles GDI drawing and so on.)
OnLButtonDown
就像这样:(is like this:)
void CBubbleBreakerPanel::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd::OnLButtonDown(nFlags, point);
if (m_rcNewGameZone.PtInRect(point)){
NewScene(TRUE);
Invalidate(FALSE);
return;
}
else if (m_rcMenuZone.PtInRect(point)){
if (m_Menu.GetSafeHmenu()){
CMenu*pSubMenu = m_Menu.GetSubMenu(0);
if (pSubMenu){
ClientToScreen(&point);
}
}
return;
}
void CBubbleBreakerPanel::DrawBubbleSelector(CDC*pDC)
{
if (m_pBubbleSelector && (m_pBubbleSelector->GetCount() >= 2 ))
{
for(int iIndex = 0;iIndex<m_pBubbleSelector->GetCount();iIndex++){
CBubble*pBubble = m_pBubbleSelector->GetAt(iIndex);
if (pBubble->iState == BubbleSelected){
CPen penBlack(PS_SOLID,1,COLOR_BLACK);
(CPen*)pDC->SelectObject(&penBlack);
CBubble*pLeftBubble = (pBubble->X - 1 >= 0) ?
&m_pBubbles[pBubble->Y*m_iXBubbleNums+
pBubble->X-1] : NULL;
CBubble*pRightBubble = (pBubble->X + 1 <
m_iXBubbleNums) ? &m_pBubbles
[pBubble->Y*m_iXBubbleNums+pBubble->X+1]
: NULL;
CBubble*pTopBubble = (pBubble->Y - 1 >= 0) ?
&m_pBubbles[(pBubble->Y-1)*
m_iXBubbleNums+pBubble->X] : NULL;
CBubble*pBottomBubble = (pBubble->Y + 1 <
m_iYBubbleNums) ? &m_pBubbles
[(pBubble->Y+1)*m_iXBubbleNums+pBubble->X]
: NULL;
int iPosX = pBubble->PosX + pBubble->OffsetX;
int iPosY = pBubble->PosY + pBubble->OffsetY;
if ((pLeftBubble == NULL) ||
(pLeftBubble->iState != BubbleSelected)) {
pDC->MoveTo(iPosX - pBubble->
iRadius - 1,iPosY - pBubble->iRadius - 1);
pDC->LineTo(iPosX - pBubble->
iRadius - 1,iPosY + pBubble->iRadius + 1);
}
if ((pRightBubble == NULL) ||
(pRightBubble->iState != BubbleSelected)){
pDC->MoveTo(iPosX + pBubble->iRadius + 1,
iPosY - pBubble->iRadius - 1);
pDC->LineTo(iPosX + pBubble->iRadius + 1,
iPosY + pBubble->iRadius + 1);
}
if ((pTopBubble == NULL) || (pTopBubble->iState
!= BubbleSelected)){
pDC->MoveTo(iPosX - pBubble->
iRadius - 1,iPosY - pBubble->iRadius - 1);
pDC->LineTo(iPosX + pBubble->
iRadius + 1,iPosY - pBubble->iRadius - 1);
}
if ((pBottomBubble == NULL) || (pBottomBubble->
iState != BubbleSelected)){
pDC->MoveTo(iPosX - pBubble->iRadius - 1,
iPosY + pBubble->iRadius + 1);
pDC->LineTo(iPosX + pBubble->iRadius + 1,
iPosY + pBubble->iRadius + 1);
}
}
}
}
}
CBubbleMovingTool
用于处理气泡运动,并且(is designed to handle bubbles movement, and) CBubbleMovingToolH
来自(is derived from) CBubbleMovingTool
处理地平线运动,以及(to handle horizon movement, and) CBubbleMovingToolV
处理垂直运动,以及(to handle vertical movement, and) HCBubbleMovingToolVH
首先处理水平运动并处理垂直运动.(to handle horizon movement first and handle vertical movement.)
CBubbleMovingToolH::ReArrangeRow
就像这样:(is like this:)
void CBubbleMovingToolH::ReArrangeRow(int iyIndex)
{
if (m_pBubbles)
{
CBubble2DArray bubble2dArray(m_pBubbles,m_iXBubbleNums,m_iYBubbleNums);
CBubble *pTempBubbles = new CBubble[m_iXBubbleNums];
int ixValidCount = 0;
if (pTempBubbles){
for (int ixIndex = m_iXBubbleNums - 1;ixIndex >= 0;ixIndex--)
{
CBubble *pBubble = bubble2dArray.GetBubble
(ixIndex,iyIndex);
if (pBubble && (pBubble->iState == BubbleActive) )
{
pTempBubbles[ixValidCount].iColorIndex =
pBubble->iColorIndex;
pTempBubbles[ixValidCount].iState =
pBubble->iState;
ixValidCount++;
}
}
for (int ixIndex = 0;ixIndex<m_iXBubbleNums;ixIndex++){
CBubble *pBubble = bubble2dArray.GetBubble
(ixIndex,iyIndex);
pBubble->iState = BubbleNone;
}
}
if (pTempBubbles)
{
for (int ixIndex = m_iXBubbleNums - 1 ,ixValidIndex = 0;
ixValidIndex<ixValidCount;ixIndex--)
{
CBubble *pBubble = bubble2dArray.GetBubble
(ixIndex,iyIndex);
if (pBubble)
{
pBubble->iColorIndex =
pTempBubbles[ixValidIndex].iColorIndex;
pBubble->iState = pTempBubbles
[ixValidIndex].iState;
ixValidIndex++;
}
}
delete []pTempBubbles;
pTempBubbles = NULL;
}
}
}
CBubbleSelectoris
用于处理气泡的选择.(is designed to handle bubbles' selection.)
CBubbleSelector PtInSelector
就像这样:(is like this:)
BOOL CBubbleSelector::PtInSelector(CPoint point)
{
BOOL bFounded = FALSE;
if (GetCount() >= 2)
{
for(int iIndex = 0;iIndex<GetCount();iIndex++)
{
CBubble*pBubble = GetAt(iIndex);
if (pBubble)
{
CRect rcBubbble = pBubble->GetRect();
rcBubbble.InflateRect(1,1,1,1);
if (rcBubbble.PtInRect(point)){
bFounded = TRUE;// Action
}
}
}
}
return bFounded;
}
兴趣点(Points of Interest)
我打算为其提供完整的GDI +绘图支持.(I am planning to give it full GDI+ support for drawing.) 我还计划确保它在Windows平台上完美运行.(I’m also planning to make sure it runs perfectly well on Windows platforms.)
历史(History)
- 2009年10月22日(Oct 22 2009):第一版(: First release)
关于作者(About the Author)
自1997年以来,我一直在为Windows编程.(I’ve been programming Windows since 1997.) 我对Windows内核编程,图像处理,网络技术,UI框架以及C/C ++/C#/MFC等感兴趣.(I am interested in Windows kernal programming, image processing, network tech, UI framework, and C/C++/C#/MFC and so on.) 自2000年以来,我一直在为政府工作.(I have been working for the Government since 2000.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ Windows Win2K MFC 新闻 翻译