// 111Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "111.h"
#include "111Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy111Dlg dialog
CMy111Dlg::CMy111Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy111Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy111Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy111Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy111Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy111Dlg, CDialog)
//{{AFX_MSG_MAP(CMy111Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy111Dlg message handlers
BOOL CMy111Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
/////////////////////////////////////////////////////////////////////////////
//
GetClientRect(&rect);
rect.top += 10;
rect.left += 10;
rect.bottom -= 10;
rect.right -= 10;
for(int x = rect.left , i = 0 ; x < rect.right ; x += 30 , i ++)
{
for(int y = rect.top , j = 0 ; y < rect.bottom ; y += 30 , j ++)
{
rt[i][j].left = x;
rt[i][j].top = y;
rt[i][j].right = x + 30;
rt[i][j].bottom = y + 30;
fg[i][j][0] = 0;
fg[i][j][1] = allnull;
}
}
/////////////////////////////////////////////////////////////////////////////
//
bw = true;
fg[4][4][0] = fg[5][4][0] = fg[4][5][0] = fg[5][5][0] = 1;
fg[4][4][1] = fg[5][5][1] = black;
fg[4][5][1] = fg[5][4][1] = white;
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CMy111Dlg::OnPaint()
{
CPaintDC dc(this);
CBrush *lpbrush = CBrush::FromHandle((HBRUSH)::GetStockObject(NULL_BRUSH));
dc.SelectObject(lpbrush);
/////////////////////////////////////////////////////////////////////////////
//
dc.Rectangle(&rect);
/////////////////////////////////////////////////////////////////////////////
//
for(int x = rect.left ; x < rect.right ; x += 30)
{
dc.MoveTo(x,rect.top);
dc.LineTo(x,rect.bottom);
}
for(int y = rect.top ; y < rect.bottom ; y += 30)
{
dc.MoveTo(rect.left,y);
dc.LineTo(rect.right,y);
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
if(fg[i][j][1] == black) DrawBk(&rt[i][j]);
if(fg[i][j][1] == white) DrawWt(&rt[i][j]);
}
}
}
HCURSOR CMy111Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy111Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
for(int x = 0; x < 10; x ++)
{
for(int y = 0; y < 10; y ++)
{
if(point.x > rt[x][y].left && point.x < rt[x][y].right &&
point.y > rt[x][y].top && point.y < rt[x][y].bottom)
{
if(fg[x][y][0] == 1) return;//如果有子存在返回
if(!Ddc(x, y)) return; //如果非落子位置返回
fg[x][y][0] = 1;
if(bw)
{
fg[x][y][1] = black;
DrawBk(&rt[x][y]);
Decide(x, y);
}
else
{
fg[x][y][1] = white;
DrawWt(&rt[x][y]);
Decide(x, y);
}
bw = !bw;
}
}
}
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
void CMy111Dlg::DrawBk(CRect *myrt)
{
CClientDC dc(this);
CBrush brush(RGB(0, 0, 0));
dc.SelectObject(&brush);
dc.Ellipse(myrt->left+5, myrt->top+5, myrt->right-5, myrt->bottom-5);
}
void CMy111Dlg::DrawWt(CRect *myrt)
{
CClientDC dc(this);
CBrush brush(RGB(255, 255, 255));
dc.SelectObject(&brush);
dc.Ellipse(myrt->left+5, myrt->top+5, myrt->right-5, myrt->bottom-5);
}
void CMy111Dlg::Decide(int x, int y)
{
//////////////////////////////////////////// 判断黑棋
if(bw)
{
//////////////////////////////////////////// 水平方向判断
for(int li = (x - 1) ; li >= 0; li --)
{
if(fg[li][y][0] == 0) break;
if(fg[li][y][1] == black)
{
for(int j = li; j < x; j ++)
{
DrawBk(&rt[j][y]);
fg[j][y][1] = black;
}
break;
}
}
for(int ri = (x + 1) ; ri <= 10; ri ++)
{
if(fg[ri][y][0] == 0) break;
if(fg[ri][y][1] == black)
{
for(int j = ri; j > x; j --)
{
DrawBk(&rt[j][y]);
fg[j][y][1] = black;
}
break;
}
}
for(int ui = (y - 1) ; ui >= 0; ui --)
{
if(fg[x][ui][0] == 0) break;
if(fg[x][ui][1] == black)
{
for(int j = ui; j < y; j ++)
{
DrawBk(&rt[x][j]);
fg[x][j][1] = black;
}
break;
}
}
for(int di = (y + 1) ; di <= 10; di ++)
{
if(fg[x][di][0] == 0) break;
if(fg[x][di][1] == black)
{
for(int j = di; j > y; j --)
{
DrawBk(&rt[x][j]);
fg[x][j][1] = black;
}
break;
}
}
//////////////////////////////////////////////////// 斜方向判断
for(int lux = (x - 1), luy = (y - 1); lux >= 0; lux --, luy --)
{
if(fg[lux][luy][0] == 0) break;
if(fg[lux][luy][1] == black)
{
for(int i = lux, j = luy; i < x; i ++, j ++)
{
DrawBk(&rt[i][j]);
fg[i][j][1] = black;
}
break;
}
}
for(int rux = (x + 1), ruy = (y - 1); rux <= 10; rux ++, ruy --)
{
if(fg[rux][ruy][0] == 0) break;
if(fg[rux][ruy][1] == black)
{
for(int i = rux, j = ruy; i > x; i --, j ++)
{
DrawBk(&rt[i][j]);
fg[i][j][1] = black;
}
break;
}
}
for(int ldx = (x - 1), ldy = (y + 1); lux >= 0; ldx --, ldy ++)
{
if(fg[ldx][ldy][0] == 0) break;
if(fg[ldx][ldy][1] == black)
{
for(int i = ldx, j = ldy; i < x; i ++, j --)
{
DrawBk(&rt[i][j]);
fg[i][j][1] = black;
}
break;
}
}
for(int rdx = (x + 1), rdy = (y + 1); rdx <= 10; rdx ++, rdy ++)
{
if(fg[rdx][rdy][0] == 0) break;
if(fg[rdx][rdy][1] == black)
{
for(int i = rdx, j = rdy; i > x; i --, j --)
{
DrawBk(&rt[i][j]);
fg[i][j][1] = black;
}
break;
}
}
}
//////////////////////////////////////////// 判断白棋
if(!bw)
{
//////////////////////////////////////////// 水平竖直判断
for(int w_li = (x - 1) ; w_li >= 0; w_li --)
{
if(fg[w_li][y][0] == 0) break;
if(fg[w_li][y][1] == white)
{
for(int j = w_li; j < x; j ++)
{
DrawWt(&rt[j][y]);
fg[j][y][1] = white;
}
break;
}
}
for(int w_ri = (x + 1) ; w_ri <= 10; w_ri ++)
{
if(fg[w_ri][y][0] == 0) break;
if(fg[w_ri][y][1] == white)
{
for(int j = w_ri; j > x; j --)
{
DrawWt(&rt[j][y]);
fg[j][y][1] = white;
}
break;
}
}
for(int w_ui = (y - 1) ; w_ui >= 0; w_ui --)
{
if(fg[x][w_ui][0] == 0) break;
if(fg[x][w_ui][1] == white)
{
for(int j = w_ui; j < y; j ++)
{
DrawWt(&rt[x][j]);
fg[x][j][1] = white;
}
break;
}
}
for(int w_di = (y + 1) ; w_di <= 10; w_di ++)
{
if(fg[x][w_di][0] == 0) break;
if(fg[x][w_di][1] == white)
{
for(int j = w_di; j > y; j --)
{
DrawWt(&rt[x][j]);
fg[x][j][1] = white;
}
break;
}
}
//////////////////////////////////////////////////// 斜方向判断
for(int lux = (x - 1), luy = (y - 1); lux >= 0; lux --, luy --)
{
i