~cpp
// singleView.cpp : implementation of the CSingleView class
//
#include "stdafx.h"
#include "single.h"
#include "singleDoc.h"
#include "singleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSingleView
IMPLEMENT_DYNCREATE(CSingleView, CView)
BEGIN_MESSAGE_MAP(CSingleView, CView)
//{{AFX_MSG_MAP(CSingleView)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSingleView construction/destruction
CSingleView::CSingleView()
{
// TODO: add construction code here
for(i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
arr[i][j] = 0;
}
}
count = 0;
count1 = 0;
count2 = 0;
}
CSingleView::~CSingleView()
{
}
BOOL CSingleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSingleView drawing
void CSingleView::OnDraw(CDC* pDC)
{
CSingleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC -> Rectangle(5, 5, 1005, 1005);
for (i=5; i<1006; i+=30)
{
pDC ->MoveTo(i,5);
pDC ->LineTo(i,1005);
pDC ->MoveTo(5,i);
pDC ->LineTo(1005,i);
}
for(i=0;i<100; i++)
{
for(j=0;j<100; j++)
{
if(arr[i][j] == 1)
{
CBrush black(RGB(225,225,225));
pDC->SelectObject(&black);
pDC->Ellipse(5+30*i,5+30*j,5+30*(i+1),5+30*(j+1));
}
if(arr[i][j] == 2)
{
CBrush white(RGB(0,0,0));
pDC->SelectObject(&white);
pDC->Ellipse(5+30*i,5+30*j,5+30*(i+1),5+30*(j+1));
}
// }
}
}
if (arr[a][b]==1)
{
for (k=0; k<5; k++)
{
if(arr[a][b-k] == 1)
{
count1++;
}
else
break;
}
for (k=0; k<5; k++)
{
if(arr[a][b+k] == 1)
{
count1++;
}
else
break;
}
}
for (i=0; i<100; i++)
{
for (j=0; j<100; j++)
{
if(arr[i][j] == 1)
{
count1++;
if(count1 ==5)
MessageBox("승리 했습니다.", "승리");
}
else if(arr[i][j] == 2)
{
count2++;
if(count2==5)
MessageBox("승리 했습니다.", "승리");
}
else
{
count1 = 0;
count2 = 0;
}
}
}
// pDC -> Ellipse( , , , )
}
/////////////////////////////////////////////////////////////////////////////
// CSingleView printing
BOOL CSingleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSingleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSingleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSingleView diagnostics
#ifdef _DEBUG
void CSingleView::AssertValid() const
{
CView::AssertValid();
}
void CSingleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSingleDoc* CSingleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSingleDoc)));
return (CSingleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSingleView message handlers
void CSingleView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
x= point.x;
y= point.y;
/*
for (i=0; i<100; i++)
{
for (j=0; j<100; j++)
{
if(arr[i][j] == 1)
{
count1++;
if(count1 ==5)
MessageBox("승리 했습니다.", "승리");
}
else if(arr[i][j] == 2)
{
count2++;
if(count2==5)
MessageBox("승리 했습니다.", "승리");
}
else
{
count1 = 0;
count2 = 0;
}
}
}
*/
// 클릭한 배열에 숫자 1을 대입한다.
for(i=0; i< 100; i++)
{
if (x>5+30*i && x < 35+30*i)
{
for(j=0; j< 100; j++)
{
if (y>5+30*j && y< 35+30*j)
{
if (arr[i][j] == 0)
{
if (count % 2 ==0 )
{
arr[i][j] = 1;
a=i;
b=j;
}
else
{
arr[i][j] = 2;
a=i;
b=j;
}
count++;
}
}
}
}
}
Invalidate();
CView::OnLButtonDown(nFlags, point);
}