U E D R , A S I H C RSS

오목/곽세환,조재화

오목

재미있다. ~~ 앞으로도 열심히

ohbokView.h
~cpp 
// ohbokView.h : interface of the COhbokView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_OHBOKVIEW_H__1263A16D_AC1C_11D7_8B87_00105A0D3B1A__INCLUDED_)
#define AFX_OHBOKVIEW_H__1263A16D_AC1C_11D7_8B87_00105A0D3B1A__INCLUDED_

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


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

// Attributes
public:
	COhbokDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COhbokView)
	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:
	void VictoryMessage(int count, int z);
	void WhoIsVictory(int y,int x, int z);
	int turn;
	int array[10][10];
	virtual ~COhbokView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

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

#ifndef _DEBUG  // debug version in ohbokView.cpp
inline COhbokDoc* COhbokView::GetDocument()
   { return (COhbokDoc*)m_pDocument; }
#endif

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

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

#endif // !defined(AFX_OHBOKVIEW_H__1263A16D_AC1C_11D7_8B87_00105A0D3B1A__INCLUDED_)



ohbokView.cpp
~cpp 
// ohbokView.cpp : implementation of the COhbokView class
//

#include "stdafx.h"
#include "ohbok.h"

#include "ohbokDoc.h"
#include "ohbokView.h"

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

/////////////////////////////////////////////////////////////////////////////
// COhbokView

IMPLEMENT_DYNCREATE(COhbokView, CView)

BEGIN_MESSAGE_MAP(COhbokView, CView)
	//{{AFX_MSG_MAP(COhbokView)
	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()

/////////////////////////////////////////////////////////////////////////////
// COhbokView construction/destruction

COhbokView::COhbokView()
{
	// TODO: add construction code here
	turn = 0;
	for(int i=0; i<10; i++)
		for(int j=0; j<10; j++)
			array[i][j]=-1;
}

COhbokView::~COhbokView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// COhbokView drawing

void COhbokView::OnDraw(CDC* pDC)
{
	COhbokDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	for(int i=0; i<10; i++ )
	{
		CBrush brush(RGB(255,0,0));
		pDC->SelectObject(&brush);
		pDC->MoveTo(50 ,50+30*i); // 줄을 입력
		pDC->LineTo(320 ,50+30*i);
	}
	for(i=0; i<10; i++ )
	{
		pDC->MoveTo(50+30*i ,50);
		pDC->LineTo(50+30*i ,320);
	}
	//MessageBox("Test");

	for(i=0; i<10; i++)
	{
		for(int j=0; j<10; j++)
		{
			if(array[i][j]==0)
			{
				CBrush brush(RGB(0,0,0));
				pDC->SelectObject(&brush);
				pDC->Ellipse(35+30*j,35+30*i, 65+30*j,65+30*i);
			
			}
			if(array[i][j]==1)
			{
				CBrush brush(RGB(255,255,255));
				pDC->SelectObject(&brush);
				pDC->Ellipse(35+30*j,35+30*i, 65+30*j,65+30*i);
			}
		}
	}
	//if()
	//;
}

/////////////////////////////////////////////////////////////////////////////
// COhbokView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// COhbokView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// COhbokView message handlers

void COhbokView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(point.x <35 || point.x>334||point.y <35 || point.y>334)
	{
		//MessageBox("그곳에는 입력할 수 없습니다.", "경1");
	}
	else if(array[(point.y+15-50)/30][(point.x+15-50)/30] != -1)
	{
		//MessageBox("같은곳에는 입력하실 수 없습니다.", "경2");
	}
	else
	{
		array[(point.y+15-50)/30][(point.x+15-50)/30] = turn % 2;
		Invalidate();//순간순간마다 출력됨
		WhoIsVictory((point.y+15-50)/30, (point.x+15-50)/30, turn % 2);
		turn++;
	}
	//Invalidate();
	CView::OnLButtonDown(nFlags, point);
}

void COhbokView::WhoIsVictory(int y, int x, int z)
{
	int a,b;
	int count = 1;
	a=y;
	
	//세로선
	while(array[a-1][x] == z && a > 0 )
	{
		count++;
		a=a-1;
	}
	a=y;
	while(array[a+1][x] == z && a<10)
	{
		count++;
		a=a+1;
	}	
	VictoryMessage(count, z);
	
	//가로선
	b=x;
	count =1;
	while(array[y][b-1] == z && b>0)
	{
		count++;
		b=b-1;
	}
	b=x;
	while(array[y][b+1] == z && b<10)
	{
		count++;
		b=b+1;
	}	
	VictoryMessage(count, z);
		
	//대각선 1
	a=y;
	b=x;
	count =1;
	while(array[a-1][b-1] == z && a>0 && b>0)
	{
		count++;
		b=b-1;
		a=a-1;
	}
	a=y;
	b=x;
	while(array[a+1][b+1] == z && a<10 && b<10)
	{
		count++;
		b=b+1;
		a=a+1;
	}	
	VictoryMessage(count, z);

	//대각선 2
	a=y;
	b=x;
	count =1;
	while(array[a+1][b-1] == z && a<10 && b>0 )
	{
		count++;
		b=b-1;
		a=a+1;
	}
	a=y;
	b=x;
	while(array[a-1][b+1] == z && a>0 && b<10 )
	{
		count++;
		b=b+1;
		a=a-1;
	}	
	
	VictoryMessage(count, z);
	if (turn == 99)
	{
		MessageBox("비겼다","비김");
		for(int i=0; i<10; i++)
			{
				for(int j=0; j<10; j++)
					array[i][j]=-1;
			}
			turn = -1;
			Invalidate();
			return ;
	}
		
}

void COhbokView::VictoryMessage(int count, int z)
{
	if(count==5)
	{
		if(z==0)
		{
			MessageBox("흑이 이겼다.","승리");
		}
		else
		{
			MessageBox("백이 이겼다.","승리");
		}
		for(int i=0; i<10; i++)
		{
			for(int j=0; j<10; j++)
				array[i][j]=-1;
		}
		turn = -1;
		Invalidate(count);
		return ;
	}	
}

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