U E D R , A S I H C RSS

오목/재선,동일

Header

~cpp 
// singleView.h : interface of the CSingleView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SINGLEVIEW_H__E826914F_AE74_11D7_8B87_000102915DD4__INCLUDED_)
#define AFX_SINGLEVIEW_H__E826914F_AE74_11D7_8B87_000102915DD4__INCLUDED_

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


class CSingleView : public CView
{
private:
	int arr[100][100];
	int i,j;
	int x,y;
	int a,b;
	int count,count1,count2;




protected: // create from serialization only
	CSingleView();
	DECLARE_DYNCREATE(CSingleView)

// Attributes
public:
	CSingleDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSingleView)
	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:
	virtual ~CSingleView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CSingleView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in singleView.cpp
inline CSingleDoc* CSingleView::GetDocument()
   { return (CSingleDoc*)m_pDocument; }
#endif

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

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

#endif // !defined(AFX_SINGLEVIEW_H__E826914F_AE74_11D7_8B87_000102915DD4__INCLUDED_)

Source

~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);
}

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