U E D R , A S I H C RSS

오목/진훈,원명



1. OmokView.h

~cpp 
// OmokView.h : interface of the COmokView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_OMOKVIEW_H__5E50035A_B51D_11D7_8B86_00105A0D3B05__INCLUDED_)
#define AFX_OMOKVIEW_H__5E50035A_B51D_11D7_8B86_00105A0D3B05__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000



class COmokView : public CView
{
protected: // create from serialization only
	COmokView();
	DECLARE_DYNCREATE(COmokView)

// Attributes
public:
	COmokDoc* GetDocument();


// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COmokView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void OnInitialUpdate();
	protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~COmokView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(COmokView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	int movecnt;
	int Count;
	int turn;
	int putX;
	int putY;
	int board[9][9];

};

#ifndef _DEBUG  // debug version in OmokView.cpp
inline COmokDoc* COmokView::GetDocument()
   { return (COmokDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_OMOKVIEW_H__5E50035A_B51D_11D7_8B86_00105A0D3B05__INCLUDED_)


2. OmokView.cpp

~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("&#48577;윈!!");
		}
		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;
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:26
Processing time 0.0280 sec