VC面向对象的学习教程
源代码在线查看: tank.cpp
// Tank.cpp: implementation of the CTank class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "My.h"
#include "Tank.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// 高炮类成员函数
// 高炮类构造函数
CTank::CTank()
{
m_pointTank.x = 350;
m_pointTank.y = 450;
m_bmpTank.LoadBitmap(IDB_TANK);
BITMAP BM;
m_bmpTank.GetBitmap(&BM);
m_nWidth = BM.bmWidth;
m_nHeight = BM.bmHeight;
}
// 显示高炮
void CTank::ShowTank(CDC *pDC, CDC *pMemDC, CRect Client)
{
pMemDC->SelectObject(&m_bmpTank);
pDC->BitBlt(m_pointTank.x, m_pointTank.y,
m_nWidth, m_nHeight, pMemDC,0,0,SRCAND);
}
// 改变位置
void CTank::ChangePos(int tag)
{
if(tag == 0 && m_pointTank.x > 0)
m_pointTank.x -= 20;
else if(tag == 1 && m_pointTank.x+m_nWidth < 798)
m_pointTank.x += 20;
}