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

📄 fjj.txt

📁 实现中国象棋的功能
💻 TXT
📖 第 1 页 / 共 5 页
字号:
					}
				}
				else
				{
					if(yfrom<yto)
					{
						for(j=yfrom+1;j<yto;j++)
							if(manmap[xfrom][j]!=32)return FALSE;
					}
					else
					{
						for(j=yto+1;j<yfrom;j++)
							if(manmap[xfrom][j]!=32)return FALSE;
					}
				}
			}
			//以上是炮不吃子-------------------------------------
			//吃子时:=======================================
			else	
			{
				int count=0;
				if(yfrom==yto)
				{
					if(xfrom<xto)
					{
						for(i=xfrom+1;i<xto;i++)
							if(manmap[i][yfrom]!=32)count++;
						if(count!=1)return FALSE;
					}
					else
					{
						for(i=xto+1;i<xfrom;i++)
							if(manmap[i][yfrom]!=32)count++;
						if(count!=1)return FALSE;
					}
				}
				else
				{
					if(yfrom<yto)
					{
						for(j=yfrom+1;j<yto;j++)
							if(manmap[xfrom][j]!=32)count++;
						if(count!=1)return FALSE;
					}
					else
					{
						for(j=yto+1;j<yfrom;j++)
							if(manmap[xfrom][j]!=32)count++;
						if(count!=1)return FALSE;
					}
				}
			}
			//以上是炮吃子时================================
			break;	

		case RED_M:
		case BLACK_M:
			//马走日:
			if(!(
				(abs(xto-xfrom)==1&&abs(yto-yfrom)==2)
				||(abs(xto-xfrom)==2&&abs(yto-yfrom)==1)
				))return FALSE;
			
			//找马脚:
			if		(xto-xfrom==2){i=xfrom+1;j=yfrom;}
			else if	(xfrom-xto==2){i=xfrom-1;j=yfrom;}
			else if	(yto-yfrom==2){i=xfrom;j=yfrom+1;}
			else if	(yfrom-yto==2){i=xfrom;j=yfrom-1;}
			
			//绊马脚:
			if(manmap[i][j]!=32)return FALSE;
			break;

		default:	
			break;
		}

	return TRUE;	//上面的规则全通过!
}

BOOL  IsNormal(const int & mantype,const int & x,const int & y)
{
	if(x<1||x>9||y<1||y>10)return FALSE;
	switch(mantype)
	{
	case RED_K:	
		//帅不能在红方宫外:
		if( x>6|| x<4|| y<8)return FALSE;
		break;

	case RED_S:	
		//仕只能在宫内特定点:
		if(!(
			( x==4&& y==10)||
			( x==4&& y==8)||
			( x==5&& y==9)||
			( x==6&& y==10)||
			( x==6&& y==8)
			))return FALSE;
		break;

	case RED_X:
		//七个相位:
		if(!(
			( x==1&& y==8)||
			( x==3&& y==10)||
			( x==3&& y==6)||
			( x==5&& y==8)||
			( x==7&& y==10)||
			( x==7&& y==6)||
			( x==9&& y==8)
			))return FALSE;
		break;

	case RED_B:
		//兵不能在兵位后:
		if( y>7)return FALSE;
		//兵过河前不能左右移动:
		if( y>5&& x%2==0)return FALSE;
		break;

	case BLACK_K:
		//帅不能在红方宫外:
		if( x>6|| x<4|| y>3)return FALSE;
		break;

	case BLACK_S:
		//仕只能在宫内特定点:
		if(!(
			( x==4&& y==1)||
			( x==4&& y==3)||
			( x==5&& y==2)||
			( x==6&& y==1)||
			( x==6&& y==3)
			))return FALSE;
		break;

	case BLACK_X:
		//七个相位:
		if(!(
			( x==1&& y==3)||
			( x==3&& y==1)||
			( x==3&& y==5)||
			( x==5&& y==3)||
			( x==7&& y==1)||
			( x==7&& y==5)||
			( x==9&& y==3)
			))return FALSE;
		break;

	case BLACK_B:
		//兵不能在兵位后:
		if( y<4)return FALSE;
		//兵过河前不能左右移动:
		if( y<6&& x%2==0)return FALSE;
		break;

	default:
		break;
	}
	return TRUE;
}

void  FixManMap(CFace & face, int map[11][12])
{
	memcpy(map,_defaultmap,132*sizeof(int));

	static CXY * pman;
	static int i;
	for(i=0;i<32;i++)
	{
		pman = & face.man[i];
		if(pman->x)
			map[pman->x][pman->y]=i;
	}
		
}



#if !defined CCT_CHINESECHESS_DEF
#define CCT_CHINESECHESS_DEF

#include "BaseClasses.h"

const int MW=32,SW=1;				//MW-棋子宽度;SW-棋子间隔的一半
const int BWA=MW+SW*2;				//BWA-棋格宽度

const int XC[2]={BWA/2,BWA/2-1};	//XC,YC-棋子宽的一半
const int YC[2]={BWA/2,BWA/2-2};	//[0].[1]分别为阴影和明线的偏移量

const int XBW=BWA*9,YBW=BWA*10;		//棋盘的长宽
const int XOFFSET=15,YOFFSET=10;	//棋盘左上角相对窗口用户区的偏移

#define MAN 0			//人
#define COM 1			//计算机

#define RED 0			//红方
#define BLACK 1			//黑方

#define RED_K 0			//红帅
#define RED_S 1			//仕
#define RED_X 2			//相
#define RED_M 3			//马
#define RED_J 4			//车
#define RED_P 5			//炮
#define RED_B 6			//兵

#define BLACK_K 7		//黑将
#define BLACK_S 8		//士
#define BLACK_X 9		//象
#define BLACK_M 10		//马
#define BLACK_J 11		//车
#define BLACK_P 12		//炮
#define BLACK_B 13		//卒


//以下是全局函数定义:

//把棋子序号转换为对应图标的序号
const int  ManToIcon[33]=	{0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6
,7,8,8,9,9,10,10,11,11,12,12,13,13,13,13,13,-1};							

//棋子类型与图标的序号相同
#define ManToType  ManToIcon

const int ManToType7[33]=	{0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6
	,0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6,-1};


//随即函数,返回小于n的随机整数
int  rnd(const int& n);

//给出棋子序号!!,判断是红是黑
const int SideOfMan[33]=	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1};

const int _defaultmap[11][12]=	
{
//	[0][1][2][3][4][5][6][7][8][9][10][11]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[0]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[1]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[2]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[3]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[4]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[5]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[6]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[7]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[8]
	{32,32,32,32,32,32,32,32,32,32,32,32},//[9]
	{32,32,32,32,32,32,32,32,32,32,32,32}//[10]
};

//
const int FistOfSide[2]={0,16};
const int LastOfSide[2]={15,31};

//给出棋子排列数组和走法,判断是否能走
BOOL CanGo(int manmap[11][12],
		   const int & man,
		   const int & xfrom,
		   const int & yfrom,
		   const int & xto,
		   const int & yto);

//判断某种棋子能否放在某点
BOOL  IsNormal(const int & mantype,const int & x,const int & y);

void FixManMap(CFace & face, int map[11][12]);


#endif// Chess.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Chess.h"
#include "ChessDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChessApp

BEGIN_MESSAGE_MAP(CChessApp, CWinApp)
	//{{AFX_MSG_MAP(CChessApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChessApp construction

CChessApp::CChessApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CChessApp object

CChessApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CChessApp initialization

BOOL CChessApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CChessDlg dlg;
	m_pMainWnd = &dlg;


	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
// Chess.h : main header file for the CHESS application
//

#if !defined(AFX_CHESS_H__AA41CA9C_A877_11D4_9A6C_973E5A1E3F59__INCLUDED_)
#define AFX_CHESS_H__AA41CA9C_A877_11D4_9A6C_973E5A1E3F59__INCLUDED_

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

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols

/////////////////////////////////////////////////////////////////////////////
// CChessApp:
// See Chess.cpp for the implementation of this class
//

class CChessApp : public CWinApp
{
public:
	CChessApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CChessApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL

// Implementation

	//{{AFX_MSG(CChessApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


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

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

#endif // !defined(AFX_CHESS_H__AA41CA9C_A877_11D4_9A6C_973E5A1E3F59__INCLUDED_)
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: Chess - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating command line "rc.exe /l 0x804 /fo"Debug/Chess.res" /d "_DEBUG" "G:\中国象棋源代码\Chess.rc"" 
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8.tmp" with contents
[
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR"Debug/" /Fp"Debug/Chess.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c 
"G:\中国象棋源代码\BaiDlg.cpp"
"G:\中国象棋源代码\BaseClasses.cpp"
"G:\中国象棋源代码\BaseDef.cpp"
"G:\中国象棋源代码\Chess.cpp"
"G:\中国象棋源代码\ChessDlg.cpp"
"G:\中国象棋源代码\CoolButton.cpp"
"G:\中国象棋源代码\OpenDlg.cpp"
"G:\中国象棋源代码\OptionDlg.cpp"
"G:\中国象棋源代码\StepList.cpp"
"G:\中国象棋源代码\Thinker.cpp"
"G:\中国象棋源代码\ThinkOptionDlg.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8.tmp" 
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp" with contents
[
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR"Debug/" /Fp"Debug/Chess.pch" /Yc"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c 
"G:\中国象棋源代码\StdAfx.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp" 
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp" with contents
[
/nologo /subsystem:windows /incremental:yes /pdb:"Debug/Chess.pdb" /debug /machine:I386 /out:"Debug/Chess.exe" /pdbtype:sept 
".\Debug\BaiDlg.obj"
".\Debug\BaseClasses.obj"
".\Debug\BaseDef.obj"
".\Debug\Chess.obj"
".\Debug\ChessDlg.obj"
".\Debug\CoolButton.obj"
".\Debug\OpenDlg.obj"
".\Debug\OptionDlg.obj"
".\Debug\StdAfx.obj"
".\Debug\StepList.obj"
".\Debug\Thinker.obj"
".\Debug\ThinkOptionDlg.obj"
".\Debug\Chess.res"
]
Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp"
<h3>Output Window</h3>
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
BaiDlg.cpp
BaseClasses.cpp
BaseDef.cpp
Chess.cpp
ChessDlg.cpp
CoolButton.cpp
OpenDlg.cpp
OptionDlg.cpp
StepList.cpp
Thinker.cpp
ThinkOptionDlg.cpp
Generating Code...
Linking...



<h3>Results</h3>
Chess.exe - 0 error(s), 0 warning(s)
</pre>
</body>
</html>
// ChessDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Chess.h"
#include "ChessDlg.h"
#include "CoolButton.h"
#include "BaseDef.h"
#include "OptionDlg.h"
#include "ThinkOptionDlg.h"
#include "BaiDlg.h"
#include "OpenDlg.h"

#define CHESS_C_UNDO 0
#define CHESS_C_REDO 1
#define CHESS_C_HELP 2
#define CHESS_C_CUT	 3


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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CCoolButton	m_btWeb;
	CCoolButton	m_btEmail;
	CCoolButton	m_btOK;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnButtonweb();
	afx_msg void OnButtonemail();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_BUTTONWEB, m_btWeb);
	DDX_Control(pDX, IDC_BUTTONEMAIL, m_btEmail);
	DDX_Control(pDX, IDOK, m_btOK);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDC_BUTTONWEB, OnButtonweb)
	ON_BN_CLICKED(IDC_BUTTONEMAIL, OnButtonemail)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChessDlg dialog

CChessDlg::CChessDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CChessDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChessDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	CWinApp* pApp=AfxGetApp();

	m_hIcon		= pApp->LoadIcon(IDR_MAINFRAME);
	m_hIconUndo = pApp->LoadIcon(IDI_UNDO);
	m_hIconRedo = pApp->LoadIcon(IDI_REDO);
	m_hIconHelp = pApp->LoadIcon(IDI_HELP);
	m_hIconCut	= pApp->LoadIcon(IDI_CUT );

	//棋子图标
	m_hIconMan[RED_K]=pApp->LoadIcon(IDI_R_K);
	m_hIconMan[RED_S]=pApp->LoadIcon(IDI_R_S);
	m_hIconMan[RED_X]=pApp->LoadIcon(IDI_R_X);
	m_hIconMan[RED_M]=pApp->LoadIcon(IDI_R_M);
	m_hIconMan[RED_J]=pApp->LoadIcon(IDI_R_J);
	m_hIconMan[RED_P]=pApp->LoadIcon(IDI_R_P);
	m_hIconMan[RED_B]=pApp->LoadIcon(IDI_R_B);

	m_hIconMan[BLACK_K]=pApp->LoadIcon(IDI_B_K);
	m_hIconMan[BLACK_S]=pApp->LoadIcon(IDI_B_S);
	m_hIconMan[BLACK_X]=pApp->LoadIcon(IDI_B_X);
	m_hIconMan[BLACK_M]=pApp->LoadIcon(IDI_B_M);
	m_hIconMan[BLACK_J]=pApp->LoadIcon(IDI_B_J);
	m_hIconMan[BLACK_P]=pApp->LoadIcon(IDI_B_P);
	m_hIconMan[BLACK_B]=pApp->LoadIcon(IDI_B_B);

⌨️ 快捷键说明

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