📄 tankdlg.cpp
字号:
// tankDlg.cpp : implementation file
//
#include "stdafx.h"
#include "tank.h"
#include "tankDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern void TankMove(CTankDlg *pl);
extern void KeyProc(CTankDlg *pl);
extern void ClearMsgQueue();
extern CCriticalSection MapMutex;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//##ModelId=3EBA49A4009C
class CAboutDlg : public CDialog
{
public:
//##ModelId=3EBA49A400A0
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
//##ModelId=3EBA49A4009E
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTankDlg dialog
CTankDlg::CTankDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTankDlg::IDD, pParent),m_bPause(FALSE),m_bPaint(TRUE)
{
//{{AFX_DATA_INIT(CTankDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nLevel=0;
m_bEscPress=FALSE;
if(!m_pictureTop.Load("pic\\bmp\\MainDlg\\top_Dlg.JPG"))
AfxMessageBox("读取图源出错");
if(!m_pictureLeft.Load("pic\\bmp\\MainDlg\\left_Dlg.JPG"))
AfxMessageBox("读取图源出错");
if(!m_pictureRight.Load("pic\\bmp\\MainDlg\\right_Dlg.JPG"))
AfxMessageBox("读取图源出错");
if(!m_pictureBloodFull.Load("pic\\bmp\\MainDlg\\BloodFull.JPG"))
AfxMessageBox("读取图源出错");
if(!m_pictureBloodEmpty.Load("pic\\bmp\\MainDlg\\BloodEmpty.JPG"))
AfxMessageBox("读取图源出错");
}
void CTankDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTankDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTankDlg, CDialog)
//{{AFX_MSG_MAP(CTankDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_WINDOWPOSCHANGED()
ON_WM_MOVE()
ON_WM_LBUTTONDOWN()
ON_WM_CLOSE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USERQUIT,Exit)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTankDlg message handlers
BOOL CTankDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
SetWindowPos(&CWnd::wndTop ,0,0,757,678,SWP_DRAWFRAME);
CenterWindow();
if(game.Init(GetSafeHwnd())==FALSE)
{
AfxMessageBox("游戏初始化失败!");
return FALSE;
}
hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)KeyProc,this,0 ,&ID);
SetTimer(1,20,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTankDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTankDlg::OnPaint()
{
if(m_bPaint)
{
CClientDC dc(this);
m_pictureTop.Draw(&dc,CPoint(0,0));
m_pictureTop.Draw(&dc,CPoint(0,645));
m_pictureLeft.Draw(&dc,CPoint(0,0));
m_pictureLeft.Draw(&dc,CPoint(645,0));
m_pictureRight.Draw(&dc,CPoint(650,0));
m_pictureLeft.Draw(&dc,CPoint(742,0));
m_pictureBloodFull.Draw(GetDC(),CPoint(650,44));
m_pictureBloodFull.Draw(GetDC(),CPoint(650,370));
int i=game.m_nLeftPlayer%10;
int j=game.m_nRightPlayer%10;
m_pictureBMath.Load("pic\\Bmp\\MainDlg\\Math\\B0.JPG");
m_pictureBMath.Draw(&dc,CPoint(700,10));
m_pictureBMath.Draw(&dc,CPoint(700,335));
CString temp;
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",i);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(&dc,CPoint(720,10));
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",j);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(&dc,CPoint(720,335));
if(game.m_tankleft)
{
//重绘坦克生命值
int i=game.m_tankleft->GetTankLife();
m_pictureBloodEmpty.Draw(GetDC(),CPoint(650,44));
m_pictureBloodFull.Draw(GetDC(),CPoint(650,44),(double(i)/200.00));
//重绘坦克杀敌数
int m=game.m_nLeftKills;
CString temp;
int pos=m%10;
if(pos!=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(708,200));
}
pos=m/100;
if(pos!=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(666,200));
}
m-=pos*100;
pos=m/10;
if(pos!=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(687,200));
}
//绘制坦克得分
int k=game.m_nLeftScore;
pos=k%10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(727,285));
}
pos=k/1000;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(651,285));
}
k-=pos*1000;
pos=k/100;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(677,285));
}
k-=pos*100;
pos=k/10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(702,285));
}
}
if(!game.m_bSinglePlayer&&game.m_tankright)
{
int j=game.m_tankright->GetTankLife();
m_pictureBloodEmpty.Draw(GetDC(),CPoint(650,370));
m_pictureBloodFull.Draw(GetDC(),CPoint(650,370),(double(j)/200.00));
int n=game.m_nRightKills;
CString temp;
int pos=n%10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(706,528));
}
pos=n/100;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(664,528));
}
n-=pos*100;
pos=n/10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",pos);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(685,528));
}
int h=game.m_nRightScore;
pos=h%10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(727,613));
}
pos=h/1000;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(651,613));
}
h-=pos*1000;
pos=h/100;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(677,613));
}
h-=pos*100;
pos=h/10;
if(pos>=0)
{
temp.Format("pic\\Bmp\\MainDlg\\Math\\L%d.JPG",pos);
m_pictureLMath.Load(temp);
m_pictureLMath.Draw(GetDC(),CPoint(702,613));
}
}
//专门针对单人情况的刷新问题
if(game.m_bSinglePlayer)
{
CString temp;
temp.Format("pic\\Bmp\\MainDlg\\Math\\B%d.JPG",0);
m_pictureBMath.Load(temp);
m_pictureBMath.Draw(GetDC(),CPoint(720,335));
}
game.UpdateScreen();
m_bPaint=FALSE;
}
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTankDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTankDlg::OnTimer(UINT nIDEvent)
{
static int nNum=0;
if(m_bPause)
{
if(nIDEvent==1)return;
if(nIDEvent==2)return;
if(nIDEvent==3)return;
}
GameState gstate=game.GetGameState();
switch(nIDEvent)
{
case 1:
game.UpdateScreen();
game.Run();
//负责刷新dlg-right框架
if(gstate==GAMEACTIVE||gstate==GAMENEXT)
{
ShowPlayerInfo();
}
if(gstate==GAMENEXT)
{
if(++m_nLevel <= GAMETOTALLEVEL)
{
char szMapFile[80];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -