~cpp
// OmokView.cpp : implementation of the COmokView class
//
#include "stdafx.h"
#include "Omok.h"
#include "OmokDoc.h"
#include "OmokView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COmokView
IMPLEMENT_DYNCREATE(COmokView, CView)
BEGIN_MESSAGE_MAP(COmokView, CView)
//{{AFX_MSG_MAP(COmokView)
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()
/////////////////////////////////////////////////////////////////////////////
// COmokView construction/destruction
COmokView::COmokView()
{
// TODO: add construction code here
}
COmokView::~COmokView()
{
}
BOOL COmokView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COmokView drawing
void COmokView::OnDraw(CDC* pDC)
{
COmokDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC -> Rectangle (0,0,500,500);
for (int moveX = 50;moveX <= 500;moveX += 50)
{
pDC -> MoveTo(0,moveX);
pDC -> LineTo (500,moveX);
}
for (int moveY = 50;moveY <= 500;moveY += 50)
{
pDC -> MoveTo(moveY,0);
pDC -> LineTo(moveY,500);
}
for (int findX = 0;findX < 9;findX++)
{
for (int findY = 0;findY < 9;findY++)
{
if (board[findX][findY] == 1)
{
pDC->SelectObject(GetStockObject(WHITE_BRUSH));
pDC->Ellipse(findX*50+30,findY*50+30,findX*50+70,findY*50+70);
}
else if (board[findX][findY] == 2)
{
pDC->SelectObject(GetStockObject(BLACK_BRUSH));
pDC->Ellipse(findX*50+30,findY*50+30,findX*50+70,findY*50+70);
}
}
}
if (turn == 1)
{
pDC->SelectObject(GetStockObject(WHITE_BRUSH));
pDC->Ellipse(putX*50+30,putY*50+30,putX*50+70,putY*50+70);
}
else if (turn == 2)
{
pDC->SelectObject(GetStockObject(BLACK_BRUSH));
pDC->Ellipse(putX*50+30,putY*50+30,putX*50+70,putY*50+70);
}
}
/////////////////////////////////////////////////////////////////////////////
// COmokView printing
BOOL COmokView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COmokView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COmokView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COmokView diagnostics
#ifdef _DEBUG
void COmokView::AssertValid() const
{
CView::AssertValid();
}
void COmokView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COmokDoc* COmokView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COmokDoc)));
return (COmokDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COmokView message handlers
void COmokView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
putX = (point.x - 25) / 50;
putY = (point.y - 25) / 50;
if( putX >= 0 && putX <= 8 && putY >= 0 && putY <= 8)
{
if (board[putX][putY] == 0)
{
if (turn == 1)
turn = 2;
else
turn = 1;
board[putX][putY] = turn;
}
Count = 1;
if (turn == 1)
{
for (int winX = 0;winX<9;winX++)
{
for (int winY = 0;winY<9;winY++)
{
if (board[winX][winY] == 1)
{
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0 || winY+movecnt > 8)
break;
if (board[winX-movecnt][winY+movecnt] == 0 || board[winX-movecnt][winY+movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winY+movecnt > 8)
break;
if (board[winX][winY+movecnt] == 0 || board[winX][winY+movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8 || winY+movecnt > 8)
break;
if (board[winX+movecnt][winY+movecnt] == 0 || board[winX+movecnt][winY+movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0)
break;
if (board[winX-movecnt][winY] == 0 || board[winX-movecnt][winY] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8)
break;
if (board[winX+movecnt][winY] == 0 || board[winX+movecnt][winY] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0 || winY-movecnt < 0)
break;
if (board[winX-movecnt][winY-movecnt] == 0 || board[winX-movecnt][winY-movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winY-movecnt < 0)
break;
if (board[winX][winY-movecnt] == 0 || board[winX][winY-movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8 || winY-movecnt < 0)
break;
if (board[winX+movecnt][winY-movecnt] == 0 || board[winX+movecnt][winY-movecnt] == 2)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
}
}
if (Count == 5)
break;
}
if (Count == 5)
MessageBox("뷁윈!!");
}
else if (turn == 2)
{
for (int winX = 0;winX<9;winX++)
{
for (int winY = 0;winY<9;winY++)
{
if (board[winX][winY] == 2)
{
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0 || winY+movecnt > 8)
break;
if (board[winX-movecnt][winY+movecnt] == 0 || board[winX-movecnt][winY+movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winY+movecnt > 8)
break;
if (board[winX][winY+movecnt] == 0 || board[winX][winY+movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8 || winY+movecnt > 8)
break;
if (board[winX+movecnt][winY+movecnt] == 0 || board[winX+movecnt][winY+movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0)
break;
if (board[winX-movecnt][winY] == 0 || board[winX-movecnt][winY] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8)
break;
if (board[winX+movecnt][winY] == 0 || board[winX+movecnt][winY] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX-movecnt < 0 || winY-movecnt < 0)
break;
if (board[winX-movecnt][winY-movecnt] == 0 || board[winX-movecnt][winY-movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winY-movecnt < 0)
break;
if (board[winX][winY-movecnt] == 0 || board[winX][winY-movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
Count = 1;
movecnt = 1;
do{
if (winX+movecnt > 8 || winY-movecnt < 0)
break;
if (board[winX+movecnt][winY-movecnt] == 0 || board[winX+movecnt][winY-movecnt] == 1)
break;
else
Count++;
movecnt++;
}while(Count < 5);
if (Count == 5)
break;
}
}
if (Count == 5)
break;
}
if (Count == 5)
MessageBox("흙윈!!!!");
}
Invalidate();
}
CView::OnLButtonDown(nFlags, point);
}
void COmokView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
for(int boardX = 0 ; boardX < 9;boardX++)
for (int boardY = 0;boardY < 9;boardY++)
board[boardX][boardY] = 0;
turn = 1;
}