MFC소스입니다..분석해야하는데..ㅠ
큰가람
학교에서 소스분석을 해오라고하는데..
오목부분인데.. 잘 모르겠습니다..ㅠㅠ 주석좀 달아주세요..
부탁드려요!!
// OmokSingleView.cpp : implementation of the COmokSingleView class
//
#include stdafx.h
#include OmokSingle.h
#include OmokSingleDoc.h
#include OmokSingleView.h
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView
IMPLEMENT_DYNCREATE(COmokSingleView, CView)
BEGIN_MESSAGE_MAP(COmokSingleView, CView)
//{{AFX_MSG_MAP(COmokSingleView)
ON_WM_CREATE()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_GAME_NEW, OnGameNew)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView construction/destruction
COmokSingleView::COmokSingleView()
{
// TODO: add construction code here
memBack = new CDC;
memBlack = new CDC;
memWhite = new CDC;
bBlackWhite = FALSE;
bIsWorking = TRUE;
memset(rPan, 0, sizeof(rPan));
}
COmokSingleView::~COmokSingleView()
{
}
BOOL COmokSingleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView drawing
void COmokSingleView::OnDraw(CDC* pDC)
{
COmokSingleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC-BitBlt(0,0,570,570, memBack,0,0,SRCCOPY);
}
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView printing
BOOL COmokSingleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COmokSingleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COmokSingleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView diagnostics
#ifdef _DEBUG
void COmokSingleView::AssertValid() const
{
CView::AssertValid();
}
void COmokSingleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COmokSingleDoc* COmokSingleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(COmokSingleDoc)));
return (COmokSingleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COmokSingleView message handlers
int COmokSingleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CClientDC dc(this);
CBitmap bitBack, bitBlack, bitWhite;
bitBack.LoadBitmap(IDB_BACK);
bitBlack.LoadBitmap(IDB_BLACK);
bitWhite.LoadBitmap(IDB_WHITE);
memBack-CreateCompatibleDC(&dc);
memBack-SelectObject(&bitBack);
memBlack-CreateCompatibleDC(&dc);
memBlack-SelectObject(&bitBlack);
memWhite-CreateCompatibleDC(&dc);
memWhite-SelectObject(&bitWhite);
//InitGame();
InitRect();
return 0;
}
void COmokSingleView::InitRect()//시작과동시에 오목 좌표 배열에 저장.
{
for(int row=0; row19;row++)
for(int col=0; col19; col++)
rect[row][col] = CRect(col*30, row*30, col*30+30, row*30+30);
}
void COmokSingleView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message code here and/or call default
if(FALSE == bIsWorking) return;
for(int row=0; row19; row++)
for(int col=0; col19; col++)
if(rect[row][col].PtInRect(point))
{
if(rPan[row][col] !=0) return;
DrawStone(row, col);
CheckWin();
bBlackWhite = !bBlackWhite;
return;
}
CView::OnLButtonUp(nFlags, point);
}
void COmokSingleView::DrawStone(int row, int col)
{
if(bBlackWhite == FALSE) //흑돌일 경우
{
rPan[row][col] = 1;
memBack-BitBlt(rect[row][col].left, rect[row][col].top, 30, 30, memBlack, 0, 30, SRCAND);
memBack-BitBlt(rect[row][col].left, rect[row][col].top, 30, 30, memBlack, 0, 0, SRCPAINT);
}
else//백돌일 경우
{
rPan[row][col] = 2;
memBack-BitBlt(rect[row][col].left, rect[row][col].top, 30, 30, memWhite, 0, 30, SRCAND);
memBack-BitBlt(rect[row][col].left, rect[row][col].top, 30, 30, memWhite, 0, 0, SRCPAINT);
}
InvalidateRect(&rect[row][col], TRUE);
}
void COmokSingleView::CheckWin()
{
int nBlackCount=0;
int nWhiteCount=0;
int row, col;
for(row=0; row19;row++)
{
for(col=0; col19; col++)
{
if(1==rPan[row][col])
{
nBlackCount++;
nWhiteCount = 0;
if(5==nBlackCount)
{
MessageBox(흑색의 가로 승리);
bIsWorking = FALSE;
}
}
else if(2==rPan[row][col])
{
nWhiteCount++;
nBlackCount = 0;
if(5==nWhiteCount)
{
MessageBox(백색의 가로 승리);
bIsWorking = FALSE;
}
}
else
{
nBlackCount=0;
nWhiteCount=0;
}
}
}for(col=0; col19;col++)
{
for(row=0; row19; row++)
{
if(1==rPan[row][col])
{
nBlackCount++;
nWhiteCount = 0;
if(5==nBlackCount)
{
MessageBox(흑색의 세로 승리);
&nbIsWorking = FALSE;
}
}
else if(2==rPan[row][col])
{
nWhiteCount++;
nBlackCount = 0;
if(5==nWhiteCount)
{
MessageBox(백색의 세로 승리);
bIsWorking = FALSE;
}
}
else
{
nBlackCount=0;
nWhiteCount=0;
}
}
nBlackCount=0;
nWhiteCount=0;
}
for(row=0; row19; row++)
for(col=0; col19; col++)
{
if(1 == rPan[row][col])
{
nBlackCount++;
for(int i = 1; (row+i19) && (col+i19); i++)
{
if(1==rPan[row+i][col+i]) nBlackCount++;
else nBlackCount = 0;
if(5==nBlackCount)
{
MessageBox(흑색의 대각선 승리);
bIsWorking = FALSE;
break;
}
}
}
else if(2 == rPan[row][col])
{
nWhiteCount++;
for(int i = 1; (row+i19) && (col+i19); i++)
{
if(2==rPan[row+i][col+i]) nWhiteCount++;
else nWhiteCount = 0;
if(5==nWhiteCount)
{
MessageBox(백색의 대각선 승리);
bIsWorking = FALSE;
break;
}
}
}
nBlackCount=0;
nWhiteCount=0;
}
for(row=18; row=0; row--)
for(col=0; col19; col++)
{
if(1 == rPan[row][col])
{
nBlackCount++;
for(int i = 1; (row-i=0) && (col+i19); i++)
{
if(1==rPan[row-i][col+i]) nBlackCount++;
else nBlackCount = 0;
if(5==nBlackCount)
{
MessageBox(흑색의 대각선 승리);
bIsWorking = FALSE;
break;
}
}
}
else if(2 == rPan[row][col])
{
nWhiteCount++;
for(int i = 1; (row-i=0) && (col+i19); i++)
{
if(2==rPan[row-i][col+i]) nWhiteCount++;
else nWhiteCount = 0;
if(5==nWhiteCount)
{
MessageBox(백색의 대각선 승리);
bIsWorking = FALSE;
break;
}
}
}
nBlackCount=0;
nWhiteCount=0;
}
}
void COmokSingleView::InitGame()
{
MessageBox(새게임);
}
void COmokSingleView::OnGameNew()
{
// TODO: Add your command handler code here
bBlackWhite = FALSE;
bIsWorking = TRUE;
memset(rPan, 0, sizeof(rPan));
CBitmap bitBack;
bitBack.LoadBitmap(IDB_BACK);
memBack-SelectObject(&bitBack);
Invalidate();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692483 | C언어 함수, Header | 떠나간그놈 | 2025-04-23 |
2692451 | 이 문제좀 풀어주세요 ^^ | 게자리 | 2025-04-23 |
2692424 | 2차원배열 자료입력질문이요! (1) | 똘끼 | 2025-04-22 |
2692401 | 유닉스안에서 C언어를 이용한 명함 만들기 입니다; 이해안가는 부분이있네요 | 2gether | 2025-04-22 |
2692374 | 고수님들 댓글 마니부탁해요!!! (2) | 엄지 | 2025-04-22 |
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |