U E D R , A S I H C RSS

오목/민수민

view.h

~cpp 
// sampleView.h : interface of the CSampleView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SAMPLEVIEW_H__7D3F7617_AE70_11D7_A975_00010298970D__INCLUDED_)
#define AFX_SAMPLEVIEW_H__7D3F7617_AE70_11D7_A975_00010298970D__INCLUDED_

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


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

// Attributes
public:
	CSampleDoc* GetDocument();

// Operations
public:

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

// Implementation
public:
	int count;
	int board[20][20];
	virtual ~CSampleView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CSampleView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	int win;
	int cnt;
	int y;
	int x;
};

#ifndef _DEBUG  // debug version in sampleView.cpp
inline CSampleDoc* CSampleView::GetDocument()
   { return (CSampleDoc*)m_pDocument; }
#endif

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

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

#endif // !defined(AFX_SAMPLEVIEW_H__7D3F7617_AE70_11D7_A975_00010298970D__INCLUDED_)

view.cpp

~cpp 
// sampleView.cpp : implementation of the CSampleView class
//

#include "stdafx.h"
#include "sample.h"

#include "sampleDoc.h"
#include "sampleView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSampleView

IMPLEMENT_DYNCREATE(CSampleView, CView)

BEGIN_MESSAGE_MAP(CSampleView, CView)
	//{{AFX_MSG_MAP(CSampleView)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSampleView construction/destruction

CSampleView::CSampleView()
{
	// TODO: add construction code here
	cnt=0,win=0;
	for(int i=0; i<20; i++)
	{
		for(int j=0 ; j<20; j++)
		{
			board[i][j]=0;
		}
	}
}

CSampleView::~CSampleView()
{
}

BOOL CSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSampleView drawing

void CSampleView::OnDraw(CDC* pDC)
{
	CSampleDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	for(int i=0; i<20; i++)
	{
		for (int j=0; j<20; j++)
		{
			pDC -> Rectangle(100+20*i,100+20*j,500,500);
		}
	}
	for(i=0; i<20 ;i++)
	{
		for(int j=0; j<20 ; j++)
		{
			if(board[i][j]==1)
			{
				CBrush brush( RGB(255,255,255) );
				pDC->SelectObject(&brush);
				pDC ->Ellipse(90+i*20,90+j*20,110+i*20,110+j*20);
			}
			else if(board[i][j]==2)
			{
				CBrush brush( RGB(0,0,0) );
				pDC->SelectObject(&brush);
				pDC->Ellipse(90+i*20,90+j*20,110+i*20,110+j*20);
			}
				
		}
	}


		

}

/////////////////////////////////////////////////////////////////////////////
// CSampleView printing

BOOL CSampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSampleView diagnostics

#ifdef _DEBUG
void CSampleView::AssertValid() const
{
	CView::AssertValid();
}

void CSampleView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSampleDoc* CSampleView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSampleDoc)));
	return (CSampleDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSampleView message handlers

void CSampleView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
/*	x=point.x-100;
	y=point.y-100;
	
	int temp_x,temp_y;
	temp_x=x/20;
	temp_y=y/20;

	if (temp_x*20 <= x)
		x=temp_x+1;
	else if (temp_x*20 > x)
		x=temp_x;

	if (temp_y*20 <= y)
		y=temp_y+1;
	else if (temp_y*20 > y)
		y=temp_y;
*/

	x=point.x;
	y=point.y;
	int temp_x=x%20;
	int temp_y=y%20;
	if (temp_x>10 )
		x=x+20-temp_x;
	else if (temp_x<10)
		x=x-temp_x;

	if (temp_y>10)
		y=y+20-temp_y;
	else if (temp_y<10)
		y=y-temp_y;

    x=x-100;
	y=y-100;

	x=x/20;
	y=y/20;


	if(board[x][y]==0)
	{
		cnt++;
		if(cnt%2==0)
			board[x][y]=1;
		else 
			board[x][y]=2;
	}
	
	Invalidate();

	for( int i=0; i<20; i++)
	{
		for( int j=0; j<20; j++)
		{
			if(board[i][j]!=0)
			{
				int temp=board[i][j];
					if(board[i+1][j]==temp && board[i+2][j]==temp && board[i+3][j]==temp && board[i+4][j]==temp)
						win=1;
					if(board[i][j+1]==temp && board[i][j+2]==temp && board[i][j+3]==temp && board[i][j+4]==temp)
						win=1;
					if(board[i+1][j+1]==temp && board[i+2][j+2]==temp && board[i+3][j+3]==temp && board[i+4][j+4]==temp)
						win=1;
					if(board[i-1][j+1]==temp && board[i-2][j+2]==temp && board[i-3][j+3]==temp && board[i-4][j+4]==temp)
						win=1;
			}
		}
	}
		if(win==1)
		{
			if(cnt%2==1)
				MessageBox("흑이 승리했습니다");
			if(cnt%2==0)
				MessageBox("백이 승리했습니다");
		}

//	OnPaint();

	CView::OnLButtonDown(nFlags, point);

}

void CSampleView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnMouseMove(nFlags, point);
}

실행파일

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