⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkfdoc.cpp

📁 五子棋核心算法,一级完整的应用程序演示
💻 CPP
字号:
// LinkFDoc.cpp : implementation of the CLinkFDoc class
//

#include "stdafx.h"
#include "LinkF.h"

#include "LinkFDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLinkFDoc

IMPLEMENT_DYNCREATE(CLinkFDoc, CDocument)

BEGIN_MESSAGE_MAP(CLinkFDoc, CDocument)
	//{{AFX_MSG_MAP(CLinkFDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLinkFDoc construction/destruction

CLinkFDoc::CLinkFDoc()
{
	// TODO: add one-time construction code here

}

CLinkFDoc::~CLinkFDoc()
{
}

BOOL CLinkFDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	int i,j,k;
	int count=0;
	for(i=0;i<NUM;i++)
		for(j=0;j<NUM;j++)
			Board[i][j]=0;


	for(i=0;i<NUM;i++)
		for(j=0;j<NUM;j++)
			for(int k=0;k<1020;k++)
			{
				ComputerTable[i][j][k]=false;
				PlayerTable[i][j][k]=false;
			}

	for(i=0;i<NUM;i++)
		for(j=0;j<15;j++)
		{
			for(k=0;k<5;k++)
			{
				ComputerTable[i][k+j][count]=true;
				PlayerTable[i][j+k][count]=true;
			}
			count++;
		}
	for(j=0;j<NUM;j++)
		for(i=0;i<15;i++)
		{
			for(k=0;k<5;k++)
			{
				ComputerTable[i+k][j][count]=true;
				PlayerTable[i+k][j][count]=true;
			}
			count++;
		}

	for(j=0;j<15;j++)
		for(i=0;i<15;i++)
		{
			for(k=0;k<5;k++)
			{
				ComputerTable[i+k][j+k][count]=true;
				PlayerTable[i+k][j+k][count]=true;
			}
			count++;
		}

	for(i=0;i<15;i++)
		for(j=18;j>=4;j--)
		{
			for(k=0;k<5;k++)
			{
				ComputerTable[i+k][j-k][count]=true;
				PlayerTable[i+k][j-k][count]=true;
				
			}
			count++;
		}


	for(i=0;i<1020;i++)
	{
			PlayerScore[i]=0;
			ComputerScore[i]=0;
	}
	Over=0;
	WinPoint=-1;


	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CLinkFDoc serialization

void CLinkFDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		for(int i=0;i<NUM;i++)
			for(int j=0;j<NUM;j++)
				ar<<Board[i][j];
		for(i=0;i<1020;i++)
		{
			ar<<ComputerScore[i];
			ar<<PlayerScore[i];
		}
		for(i=0;i<NUM;i++)
			for(int j=0;j<NUM;j++)
				for(int k=0;k<1020;k++)
				{
					ar<<ComputerTable[i][j][k];
					ar<<PlayerTable[i][j][k];
				}
		ar<<Over;
	}
	else
	{
		for(int i=0;i<NUM;i++)
			for(int j=0;j<NUM;j++)
				ar>>Board[i][j];
		for(i=0;i<1020;i++)
		{
			ar>>ComputerScore[i];
			ar>>PlayerScore[i];
		}
		for(i=0;i<NUM;i++)
			for(int j=0;j<NUM;j++)
				for(int k=0;k<1020;k++)
				{
					ar>>ComputerTable[i][j][k];
					ar>>PlayerTable[i][j][k];
				}
		ar>>Over;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CLinkFDoc diagnostics

#ifdef _DEBUG
void CLinkFDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CLinkFDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLinkFDoc commands

BOOL CLinkFDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	WinPoint=-1;
	// TODO: Add your specialized creation code here
	
	return TRUE;
}

void CLinkFDoc::DeleteContents() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CDocument::DeleteContents();
}

void CLinkFDoc::OnCloseDocument() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CDocument::OnCloseDocument();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -