⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minedlg.cpp

📁 一个扫雷小游戏
💻 CPP
字号:
// mineDlg.cpp : implementation file

#include "stdafx.h"
#include "mine.h"
#include "mineDlg.h"
#include "GDIObjects.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CPen Pen1,Pen2,Pen3,Pen4,Pen5,Pen6,Pen7;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	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()

/////////////////////////////////////////////////////////////////////////////
// CMineDlg dialog

CMineDlg::CMineDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMineDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMineDlg)
		// 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);
}

void CMineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMineDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMineDlg, CDialog)
	//{{AFX_MSG_MAP(CMineDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(IDM_RESTRAT, OnRestrat)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON1, Onstart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMineDlg message handlers

BOOL CMineDlg::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

	CMenu MainMenu;
	if(!MainMenu.LoadMenu(IDR_MAINFRAME))
	{
		AfxMessageBox("Can't load main menu!",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}
	SetMenu(&MainMenu);
	m_hMainMenu=MainMenu.Detach();	

	// TODO: Add extra initialization here
	int nRow=10, nCol=10, nMineNum=10;
	bStart = FALSE;
	bFail = FALSE;
	bBothDown = FALSE;
	LandMine.Create(nRow,nCol,nMineNum,42,73,this);//set rect weizhi
	m_DlgReSize = TRUE;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMineDlg::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 CMineDlg::OnPaint() 
{
	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();
	}
	RECT ClientRect;
	GetClientRect(&ClientRect);
	CClientDC ClientDC(this);

	//drawing the whole area
	ClientDC.SelectObject(Pen2);
	ClientDC.MoveTo(ClientRect.right-3,1);
	ClientDC.LineTo(1,1);
	ClientDC.LineTo(1,ClientRect.bottom-1);
	
	ClientDC.SelectObject(Pen1);
	ClientDC.MoveTo(ClientRect.right-2,1);
	ClientDC.LineTo(ClientRect.right-2,ClientRect.bottom-1);
	ClientDC.LineTo(1,ClientRect.bottom-1);
	ClientDC.MoveTo(ClientRect.right-3,2);
	ClientDC.LineTo(ClientRect.right-3,ClientRect.bottom-2);
	ClientDC.LineTo(2,ClientRect.bottom-2);

	//drwaing status area
	ClientDC.MoveTo(ClientRect.right-10,9);
	ClientDC.LineTo(10,9);
	ClientDC.LineTo(10,44);
	ClientDC.MoveTo(ClientRect.right-11,10);
	ClientDC.LineTo(11,10);
	ClientDC.LineTo(11,43);
	
	ClientDC.SelectObject(Pen3);
	ClientDC.LineTo(ClientRect.right-11,43);
	ClientDC.LineTo(ClientRect.right-11,10);
	ClientDC.MoveTo(10,44);
	ClientDC.LineTo(ClientRect.right-10,44);
	ClientDC.LineTo(ClientRect.right-10,9);
	
	//drawing the mine area
	ClientDC.MoveTo(ClientRect.right-10,51);
	ClientDC.LineTo(ClientRect.right-10,ClientRect.bottom-9);
	ClientDC.LineTo(10,ClientRect.bottom-9);
	ClientDC.MoveTo(ClientRect.right-11,52);
	ClientDC.LineTo(ClientRect.right-11,ClientRect.bottom-10);
	ClientDC.LineTo(11,ClientRect.bottom-10);
	ClientDC.SelectObject(Pen1);
	ClientDC.MoveTo(ClientRect.right-10,51);
	ClientDC.LineTo(10,51);
	ClientDC.LineTo(10,ClientRect.bottom-9);
	ClientDC.MoveTo(ClientRect.right-11,52);
	ClientDC.LineTo(11,52);
	ClientDC.LineTo(11,ClientRect.bottom-10);


	LandMine.ReDraw(bFail);
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMineDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMineDlg::OnRestrat() 
{
	// TODO: Add your command handler code here
	bFail = FALSE;
//	if(bStart)
//		KillTimer(1);
	bStart = FALSE;
	LandMine.Reset(LandMine.GetRow(),LandMine.GetCol(),LandMine.GetMineNum());
//	TimeCount.SetNumber(0);
//	MineCount.SetNumber(LandMine.GetMineNum());
//	m_Face.SetBitmap(&m_FaceNormal);
	RedrawWindow();	
}

void CMineDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bFail==0)
	{

		if(nFlags&MK_RBUTTON)
		{	
			bBothDown = 2;
			LandMine.BothButtonDown(point);
		}
		else
		{
			bBothDown = FALSE;
			LandMine.LButtonDown(point);
		}
	}	
	CDialog::OnLButtonDown(nFlags, point);
}

void CMineDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bFail==0)
	{

		if(bBothDown)
		{
			bBothDown--;
			int nStatus = LandMine.BothButtonUp(point);
			if(nStatus==-1)
			{
				bFail = TRUE;
//				KillTimer(1);

			}
			else
				if(LandMine.IsSuccess())
				{	
//					KillTimer(1);

					AfxMessageBox("祝贺您!挖雷任务胜利完成!",MB_OK);
					bFail = -1;
				}
		}
		else
		{
			int nStatus = LandMine.LButtonUp(point);
			if(nStatus==-1)
			{
				bFail = TRUE;
//				KillTimer(1);

			}
			else
				if(LandMine.IsSuccess())
				{	
//					KillTimer(1);

					AfxMessageBox("祝贺您!挖雷任务胜利完成!",MB_OK);
					bFail = -1;
				}
		}
		if(!bStart)
		{
			bStart = TRUE;
//			SetTimer(1, 1000, NULL);
		}
	}	
	CDialog::OnLButtonUp(nFlags, point);
}

void CMineDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bFail==0)
	{
		if(nFlags&MK_LBUTTON)
		{	bBothDown = 2;
			LandMine.BothButtonDown(point);
		}
		else
		{
			bBothDown = FALSE;
			switch(LandMine.RButtonDown(point))
			{
			case 0:
				break;
			case 1:
//				MineCount.Increase();
				break;
			case -1:
//				MineCount.Decrease();
				break;
			};
		}
		if(LandMine.IsSuccess())
		{	
//			KillTimer(1);

			AfxMessageBox("祝贺您!挖雷任务胜利完成!",MB_OK);
			bFail = -1;
		}

	}
	CDialog::OnRButtonDown(nFlags, point);	

}

void CMineDlg::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bFail==0)
	{
		if(bBothDown)
		{
			bBothDown--;
			if(LandMine.BothButtonUp(point)==-1)
				bFail = TRUE;
			else
				if(LandMine.IsSuccess())
				{	
//					KillTimer(1);
					AfxMessageBox("祝贺您!挖雷任务胜利完成!",MB_OK);
					bFail = -1;
				}
		}
	}
		
	CDialog::OnRButtonUp(nFlags, point);
}

void CMineDlg::Onstart() 
{
	// TODO: Add your control notification handler code here
	OnRestrat();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -