附录4:防空战游戏程序 370 InvalidateRect(m Tank. GetTankO) Tank. ChangePos(O) InvalidateRect(m Tank. Get(, FALSE) else if( nChar==WK_RIGH)//使用〉键右移高炮 InvalidateRect(m Tank. Get Tank O) m Tank. ChangePos(1) InvalidateRect(m Tank. Get Tank O) else if( n Char=32& m stone. HaveStone o)//使用空格键发炮 m Stone Shot(m Tank. Get TankO. left /画战场 void CMyWnd:: DrawFields(CDC *pDC, CRect Client CBrush *kpOldBrush, brushSky, brushGrass, brushMoutain CRect rect(Client) brushsky. CreatesolidBrush(RGB(127,200,255);//画天空 pOldBrush pDC->SelectOb ject(&brushSky) pDC->Rectangle (rect pDC->SelectObject(poldBrush) brushgrass. CreateSolidBrush(RGB(0,255,0);//画草地 old Brush pDC->SelectObject(&brushGrass) DC->Rectangle(rect) pDC->SelectObject(poldBrush) brushmoutain. CreatesolidBrush(RGB(125,50,0);∥/画大山 oldBrush pDC->SelectObject( &brushMoutain pDC->Polygon(m pointMoutain, 5) DC->SelectObject(pOldBrush) //判断射击效果 BOOL CMyWnd: ShotOn( CRect &body 1, CRect &body 2) return body l PtInRect(body2. TopLefto)附录 4:防空战游戏程序 - 370 - { InvalidateRect(m_Tank.GetTank()); m_Tank.ChangePos(0); InvalidateRect(m_Tank.GetTank(), FALSE); } else if(nChar == VK_RIGHT) // 使用 > 键右移高炮 { InvalidateRect(m_Tank.GetTank()); m_Tank.ChangePos(1); InvalidateRect(m_Tank.GetTank()); } else if(nChar == 32 && m_Stone.HaveStone()) // 使用空格键发炮 m_Stone.Shot(m_Tank.GetTank().left); } // 画战场 void CMyWnd::DrawFields(CDC *pDC, CRect Client) { CBrush *pOldBrush, brushSky, brushGrass, brushMoutain; CRect rect(Client); brushSky.CreateSolidBrush(RGB(127, 200, 255)); // 画天空 pOldBrush = pDC->SelectObject(&brushSky); pDC->Rectangle(rect); pDC->SelectObject(pOldBrush); brushGrass.CreateSolidBrush(RGB(0, 255, 0)); // 画草地 pOldBrush = pDC->SelectObject(&brushGrass); rect.top = 400; pDC->Rectangle(rect); pDC->SelectObject(pOldBrush); brushMoutain.CreateSolidBrush(RGB(125, 50, 0)); // 画大山 pOldBrush = pDC->SelectObject(&brushMoutain); pDC->Polygon(m_pointMoutain, 5); pDC->SelectObject(pOldBrush); } // 判断射击效果 BOOL CMyWnd::ShotOn(CRect &body1, CRect &body2) { return body1.PtInRect(body2.TopLeft()); }