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

📄 fivechess.c

📁 MiniWinOuterSM MiniWinOuterSM
💻 C
📖 第 1 页 / 共 2 页
字号:
#include"osdwindows.h"
#define CELL_WIDTH 		20				/*格子大小*/
#define BOX_WIDTH 		19
#define BOX_HEIGHT		17

#define IDM_EXIT		11
#define IDM_BACKMUSIC	12
#define IDM_ABOUT		13
#define IDM_GAMELAW		14
#define IDM_START		65535
#define IDM_RESTART		16
#define IDB_GROUPBOX	18
#define IDC_MID1		19
#define IDC_MID2		20
#define IDC_MID3		21
#define IDC_NOMID		22
#define IDM_LOAD		23
#define IDM_SAVE		24
#define IDM_EASY		25
#define IDM_NORMAL		26
#define IDM_HARD		27
#define IDC_RECYCLE		1010

#define IDM_BACK_INSERTBMP 33
#define IDM_RETURNBOX	34
#define IDC_INSERTMID	35

UINT WndProc(HWND,UINT,UINT,LONG);   //窗口函数说明;
LRESULT FiveChessWndProc(HWND,UINT,WPARAM,LPARAM); 
/******************************************************************************

******************************************************************************/
typedef struct 
{
	POINT player;
	POINT com;
}BeforeBox;

enum ChessMan 
{
	NoMan,
	COMPUTER,
	PLAYER
};   //棋盘状态

/******************************************************************************

******************************************************************************/
static int  Action;
static int ChessBox[20][18];
BeforeBox ReturnBox[163];

static int OpenGame;					/*棋局是否开始*/		
static BOOL WIN;                        /*确定玩者是否赢*/
static int Level=2;
static int LastX,LastY;                 /*用户最后一次下子对应ChessBox 参数*/
static int oldx=-1;
static int oldy=-1;

static int LeftMan;                     /*棋盘未下子个数*/   
static int ActionNumber=0;				/*手数*/

/******************************************************************************

******************************************************************************/
static HMENU createmenu (void)
{
    HMENU hMenu;
#if 0
    MENUITEMINFO mii;

    hMenu = CreateMenu();

    memset (&mii, 0, sizeof(MENUITEMINFO));
    mii.fType        = MFT_STRING;
    mii.wID          = 100;
    mii.dwTypeData    = (LPWSTR)"File";
    //mii.hSubMenu    = createpmenufile();
    InsertMenuItem(hMenu, 0, TRUE, &mii);
/*
    mii.fType        = MFT_STRING;
    mii.wID          = 110;
    mii.dwTypeData    = (DWORD)"Edit";
    mii.hSubMenu    = createpmenuedit ();
    InsertMenuItem(hMenu, 1, TRUE, &mii);
    
    mii.fType        = MFT_STRING;
    mii.wID          = 120;
    mii.dwTypeData    = (DWORD)"Terminal";
    mii.hSubMenu    = createpmenuterminal();
    InsertMenuItem(hMenu, 2, TRUE, &mii);
    */
    memset (&mii, 0, sizeof(MENUITEMINFO));
    mii.fType        = MFT_STRING;
    mii.wID          = 130;
    mii.dwTypeData    = (LPWSTR)"About";
    //mii.hSubMenu    = createpmenuabout();
    InsertMenuItem(hMenu, 3, TRUE, &mii);
#endif
    return hMenu;
}
static void GetChessRect(int x,int y,RECT*rc)
{
	SetRect(rc,CELL_WIDTH*x,CELL_WIDTH*y,CELL_WIDTH*x+CELL_WIDTH,CELL_WIDTH*y+CELL_WIDTH);
}
/******************************************************************************
画棋子
******************************************************************************/
void DrawChess(HDC hdc,int mode,int x,int y)
{
	RECT rc;
	HBRUSH hbr,oldhbr;
	HPEN hp,op;
	GetChessRect(x,y,&rc);
	switch(mode){
	case PLAYER:	hbr=CreateSolidBrush(RGB(255,0,0));break;
	case COMPUTER:	hbr=CreateSolidBrush(RGB(0,0,255));break;
	default:		hbr=CreateSolidBrush(RGB(200,200,200));break;
	}
	InflateRect(&rc,-2,-2);
	hp=CreatePen(PS_NULL,1,0);
	op=(HPEN)SelectObject(hdc,(HGDIOBJ)hp);
	oldhbr=(HBRUSH)SelectObject(hdc,(HGDIOBJ)hbr);
	if(mode!=0)
		Ellipse(hdc,rc.left,rc.top, rc.right,rc.bottom);
	SelectObject(hdc,(HGDIOBJ)oldhbr);
	SelectObject(hdc,(HGDIOBJ)op);
	DeleteObject((HGDIOBJ)hp);
	DeleteObject((HGDIOBJ)hbr);
}
/******************************************************************************
画棋子
******************************************************************************/
void DrawChessRect(HWND hWnd,int mode,int x,int y)
{
	int oldmode;
	HDC hdc;
	RECT rc;
	HBRUSH hbr,oldhbr;
	COLORREF nColor;
	hdc=GetDC(hWnd);

	if (oldx >=0 && oldy >=0)
	{
		SetRect(&rc,CELL_WIDTH*oldx,CELL_WIDTH*oldy,CELL_WIDTH*oldx+CELL_WIDTH,CELL_WIDTH*oldy+CELL_WIDTH);
	}
	SetRect(&rc,CELL_WIDTH*x,CELL_WIDTH*y,CELL_WIDTH*x+CELL_WIDTH,CELL_WIDTH*y+CELL_WIDTH);
	if(mode==PLAYER)
		nColor=RGB(50,10,10);
	else
		nColor=RGB(0,0,250);
	hbr=CreateSolidBrush(nColor);
	SetDCPenColor(hdc,nColor);
	oldhbr=(HBRUSH)SelectObject(hdc,(HGDIOBJ)hbr);
	SelectObject(hdc,(HGDIOBJ)oldhbr);
	DeleteObject((HGDIOBJ)hbr);
	ReleaseDC(hWnd,hdc);
	oldx=x;oldy=y;
}


/******************************************************************************
初始化游戏
******************************************************************************/
void InitGame()                           
{
	int i,j;
    ActionNumber=0;
    WIN=FALSE;
	OpenGame=TRUE;
    Action=PLAYER;
	LeftMan=BOX_WIDTH *BOX_HEIGHT;
	oldx=oldy=-1;
	for(i=0;i<=BOX_WIDTH;i++){
	    for(j=0;j<=BOX_HEIGHT;j++)
    		*(*(ChessBox+i)+j)=NoMan;
	}	
	for(i=0;i<163;i++){
		ReturnBox[i].player.x=0;
		ReturnBox[i].player.y=0;
	    ReturnBox[i].com.x=0;
		ReturnBox[i].com.y=0;
	}
}
/******************************************************************************

******************************************************************************/
int Opposite(int man)             
{
	switch(man)
	{
	case PLAYER:	return COMPUTER;
	case COMPUTER:	return PLAYER;
	default:		return NoMan;
	}
}
/******************************************************************************
判断五子是否连线 
******************************************************************************/
BOOL CheckFive(int it,int jt)                   
{
	int m1=1,m2=1,n1=1,n2=1,a=1,b=1,total=1;
	for(;;)
	{
		if (a==1 && it-m1>=1 && *(*(ChessBox+it-(m1++))+jt)==Action) 
			total++;
		else a=0;
		if (b==1 && it+m2<=19 && *(*(ChessBox+it+(m2++))+jt)==Action) 
			total++;
		else b=0;
		if (a==0 && b==0 || total>=5) 
			break;
	}
	if (total>=5) 
		return TRUE;
	m1=1;n1=1;m2=1;n2=1;a=1;b=1;total=1;
	for(;;)
	{
		if (a==1 && jt-n1>=1 && *(*(ChessBox+it)+jt-(n1++))==Action) 
			total++;
		else 
			a=0;
		if (b==1 && jt+n2<=17 && *(*(ChessBox+it)+jt+(n2++))==Action) 
			total++;
		else 
			b=0;
		if (a==0 && b==0 || total>=5) 
			break;
	}
	if (total>=5) 
		return TRUE;
	m1=1;n1=1;m2=1;n2=1;a=1;b=1;total=1;
	for(;;)
	{
		if (a==1 && it-m1>=1 && jt-n1>=1 && *(*(ChessBox+it-(m1++))+jt-(n1++))==Action) 
			total++;
		else 
			a=0;
		if (b==1 && it+m2<=19  && jt+n2<=17 && *(*(ChessBox+it+(m2++))+jt+(n2++))==Action) 
			total++;
		else 
			b=0;
		if (a==0 && b==0 || total>=5) 
			break;
	}
	if (total>=5) 
		return TRUE;
	m1=1;n1=1;m2=1;n2=1;a=1;b=1;total=1;
	for(;;)
	{
		if (a==1 && it+m1<=19 && jt-n1>=1 && *(*(ChessBox+it+(m1++))+jt-(n1++))==Action) 
			total++;
		else 
			a=0;
		if (b==1 && it-m2>=1 && jt+n2<=17 && *(*(ChessBox+it-(m2++))+jt+(n2++))==Action) 
			total++;
		else 
			b=0;
		if (a==0 && b==0 || total>=5) 
			break;
	}
	if (total>=5) return 
		TRUE;
	return FALSE;
}

/******************************************************************************
得到该位置最大连线子个数
******************************************************************************/
float GetManNum(int style,int it,int jt)        
{
	float lasttotal=1;
	int m1=1,m2=1,n1=1,n2=1,a=1,b=1;
	float total=1;
	for(;;)
	{
		if (a==1)
			if(it-m1>=1 && *(*(ChessBox+it-(m1++))+jt)==style) 
				total++;
			else if(*(*(ChessBox+it-(m1++))+jt)==Opposite(style)) 
			{
				total-=0.5;
				a=0;
			}else 
				a=0;
			if (b==1)
				if (it+m2<=19 && *(*(ChessBox+it+(m2++))+jt)==style) 
					total++;
				else if( *(*(ChessBox+it+(m2++))+jt)==Opposite(style)) 
				{
					total-=0.5;
					b=0;
				}
				else 
					b=0;
				if (a==0 && b==0) 
					break;
	}
	if (total>=lasttotal) 
		lasttotal=total;

⌨️ 快捷键说明

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