www.pudn.com > only.rar > onlyDlg.cpp


// onlyDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "only.h" 
#include "onlyDlg.h" 
#include "SETUP.h" 
#include "BEST.h" 
#include "tongyong.h" 
 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// 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() 
 
///////////////////////////////////////////////////////////////////////////// 
// COnlyDlg dialog 
 
COnlyDlg::COnlyDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(COnlyDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(COnlyDlg) 
		// 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_pmenu=new CMenu(); 
} 
 
 
void COnlyDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(COnlyDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(COnlyDlg, CDialog) 
	//{{AFX_MSG_MAP(COnlyDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_COMMAND(IDM_GAME, OnGame) 
	ON_COMMAND(IDM_BEST, OnBest) 
	ON_COMMAND(IDM_EXIT, OnExit) 
	ON_COMMAND(IDM_GRADE1, OnGrade1) 
	ON_COMMAND(IDM_GRADE2, OnGrade2) 
	ON_COMMAND(IDM_GRADE3, OnGrade3) 
	ON_WM_LBUTTONDOWN() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// COnlyDlg message handlers 
 
BOOL COnlyDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
m_bycolor=true; 
 
	// 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); 
		} 
	}*/ 
	m_pmenu->DestroyMenu(); 
	m_pmenu->LoadMenu(IDR_MENU1); 
	SetMenu(m_pmenu); 
 
 
	// 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 
	 
	// TODO: Add extra initialization here 
	CPaintDC dc(this); 
	for(int i=0;i<15;i++) 
			for(int j=0;j<15;j++) 
				map[i][j]=0; 
 
if (g_RunMode==1&& !g_UserFirst) 
	{ 
	/*	CPoint pt;            			// Computer first 
		m_bycolor = !m_bycolor;			// 1-Black  0-White 
		map[7][7]=m_bycolor+1; 
InvalidateRect( FALSE); 
		pt.x = 7*23+ 4; 
		pt.y = 7*23 + 4;*/ 
		jsjdown(7,7,1); 
	//	UpdateWindow(); 
		//ClientToScreen(&pt); 
		//SetCursorPos(pt.x, pt.y); 
		//PlaySound(IDSOUND_PUTSTONE); 
		//Judge(7, 7, m_Board[7][7]); 
		//Ring(); 
	}    
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void COnlyDlg::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 COnlyDlg::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 
	{ 
		 
CPaintDC dc(this); 
		CDialog::OnPaint(); 
		Drawqp(dc); 
  for(int i=0;i<15;i++) 
			for(int j=0;j<15;j++) 
				if(map[i][j]) 
		    Drawqz(i,j,map[i][j],dc); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR COnlyDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void COnlyDlg::OnGame()  
{ 
	// TODO: Add your command handler code here 
    Invalidate();    
	UpdateWindow();          
 
	SETUP setup; 
	if(setup.DoModal()==IDCANCEL) 
	{ 
		CDialog::EndDialog(0); 
		return; 
	} 
	 
} 
 
void COnlyDlg::OnBest()  
{ 
	// TODO: Add your command handler code here 
	BEST best; 
	best.DoModal(); 
} 
 
void COnlyDlg::OnExit()  
{ 
	// TODO: Add your command handler code here 
	CDialog::EndDialog(0); 
} 
 
 
 
void COnlyDlg::OnGrade1()  
{ 
	// TODO: Add your command handler code here 
	skill = 1; 
	m_pmenu->CheckMenuItem(IDM_GRADE1, MF_BYCOMMAND | MF_CHECKED);   
	m_pmenu->CheckMenuItem(IDM_GRADE2, MF_BYCOMMAND | MF_UNCHECKED); 
	m_pmenu->CheckMenuItem(IDM_GRADE3, MF_BYCOMMAND | MF_UNCHECKED); 
} 
 
void COnlyDlg::OnGrade2()  
{ 
	// TODO: Add your command handler code here 
	skill = 2; 
	m_pmenu->CheckMenuItem(IDM_GRADE2, MF_BYCOMMAND | MF_CHECKED);   
	m_pmenu->CheckMenuItem(IDM_GRADE1, MF_BYCOMMAND | MF_UNCHECKED); 
	m_pmenu->CheckMenuItem(IDM_GRADE3, MF_BYCOMMAND | MF_UNCHECKED); 
} 
 
void COnlyDlg::OnGrade3()  
{ 
	// TODO: Add your command handler code here 
	skill = 3; 
	m_pmenu->CheckMenuItem(IDM_GRADE3, MF_BYCOMMAND | MF_CHECKED);   
	m_pmenu->CheckMenuItem(IDM_GRADE1, MF_BYCOMMAND | MF_UNCHECKED); 
	m_pmenu->CheckMenuItem(IDM_GRADE2, MF_BYCOMMAND | MF_UNCHECKED); 
} 
 
 
void COnlyDlg::Drawqp(CPaintDC& dc) 
{ 
    CBitmap bitmap; 
	CBitmap* pOldBitmap; 
	CDC MemDC; 
	MemDC.CreateCompatibleDC(&dc);             ///建立与显示设备兼容的内存设备场境 
	bitmap.LoadBitmap(IDB_BITMAP1);            ///取出位图资源 
	pOldBitmap=MemDC.SelectObject(&bitmap);  ///将位图选入内存场境 
	BITMAP bm; 
    bitmap.GetObject(sizeof(BITMAP),&bm); 
	 dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCCOPY);///显示它 
	MemDC.SelectObject(pOldBitmap); 
 
} 
 
void COnlyDlg::Drawqz(int nx,int ny,char hb,CPaintDC& dc) 
{ 
	CBitmap bitmap; 
	CBitmap* pOldBitmap; 
	CDC MemDC; 
	MemDC.CreateCompatibleDC(&dc);             ///建立与显示设备兼容的内存设备场境 
 	bitmap.LoadBitmap(IDB_BITMAP2);///取出位图资源 
	pOldBitmap=MemDC.SelectObject(&bitmap);  ///将位图选入内存场境 
	BITMAP bm; 
    bitmap.GetObject(sizeof(BITMAP),&bm); 
	if(hb==1) 
dc.BitBlt(3+nx*23,3+ny*23,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCAND);///显示它 
	else if(hb==2) 
dc.BitBlt(3+nx*23,3+ny*23,bm.bmWidth,bm.bmHeight,&MemDC,0,0,MERGEPAINT); 
	MemDC.SelectObject(pOldBitmap); 
 
} 
 
void COnlyDlg::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
		int x1,y1; 
		m_bycolor=!m_bycolor; 
x1=(int)(point.x-3)/23 ; 
y1=(int)(point.y-3)/23 ; 
if(map[x1][y1]==0) 
map[x1][y1]=m_bycolor+1; 
		InvalidateRect( FALSE); 
 
	CDialog::OnLButtonDown(nFlags, point); 
	judge(x1,y1,map[x1][y1]); 
} 
 
bool COnlyDlg::judge(int nx,int ny,char style) 
{ 
	int i,j; 
	char color; 
	i=nx; 
	j=ny; 
	color=style; 
if ( LeftRight(i,j,color) >= 5 || UpDown(i,j,color) >= 5  
		 ||LupToRdown(i,j,color) >= 5 || RupToLdown(i,j,color)>=5) 
{ 
		if ( color== 1 ) 
		{ 
			MessageBox("黑棋棋胜利,结束战斗!","提示",MB_OK); 
 
for(int m=0;m<15;m++) 
			for(int n=0;n<15;n++) 
				map[m][n]=0; 
InvalidateRect( FALSE); 
		} 
		else 
		{ 
			MessageBox("白棋胜利了,结束战斗!","提示",MB_OK); 
for(int m=0;m<15;m++) 
			for(int n=0;n<15;n++) 
				map[m][n]=0; 
InvalidateRect( FALSE); 
		} 
 
 
} 
 
return false; 
} 
 
int COnlyDlg::LeftRight(int i,int j,char style) 
{ 
	int x1,y1,x2,y2,count; 
	x1=x2=i; 
	y1=y2=j; 
	count=1; 
	while ( --x1 > 0 && map[x1][y1] == style) 
	{ 
		count ++; 
	} 
    while ( ++ x2 <15 && map[x2][y2] == style ) 
	{ 
		count ++; 
	} 
	return count; 
 
 
} 
 
int COnlyDlg::UpDown(int i,int j,char style) 
{ 
    int x1,y1,x2,y2,count; 
	x1=x2=i; 
	y1=y2=j; 
	count=1; 
	while ( --y1 > 0 && map[x1][y1] == style) 
	{ 
		count ++; 
	} 
    while ( ++ y2 <15 && map[x2][y2] == style ) 
	{ 
		count ++; 
	} 
	return count; 
 
} 
 
int COnlyDlg::LupToRdown(int i,int j,char style) 
{ 
    int x1,y1,x2,y2,count; 
	x1=x2=i; 
	y1=y2=j; 
	count=1; 
	while ( --x1 > 0 && -- y1 >0 && map[x1][y1] == style) 
	{ 
		count ++; 
	} 
 
	while ( ++ x2<20 && ++ y2 < 20 &&map[x2][y2] == style ) 
	{ 
		count ++; 
	} 
	return count; 
 
} 
 
int COnlyDlg::RupToLdown(int i,int j,char style) 
{ 
    int x1,y1,x2,y2,count; 
	x1=x2=i; 
	y1=y2=j; 
	count=1; 
	while ( --x1 > 0 && ++y1 >0 && map[x1][y1] == style) 
	{ 
		count ++; 
	} 
 
	while ( ++ x2<20 && --y2 < 20 &&map[x2][y2] == style ) 
	{ 
		count ++; 
	} 
	return count; 
} 
 
void COnlyDlg::jsjdown(int nx,int ny,char style) 
{ 
m_bycolor=!m_bycolor; 
if(map[nx][ny]==0) 
map[nx][ny]=m_bycolor+1; 
		InvalidateRect( FALSE); 
 
}