資源簡介
VC6.0做的五子棋程序源碼(含禁手規則判斷和倒計時功能),對戰模式主要有人機對戰、機人對戰、人人對戰等三種智能對戰模式,還有黑棋的3-3、4-4禁手判定,以及6、7、8、9長連判斷規則,另外還設置了黑、白雙方倒計時功能,本程序為原創,特地與大家分享

代碼片段和文件信息
//?Chess.cpp:?implementation?of?the?CChess?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“MyChess.h“
#include?“Chess.h“
#include?“MyChessDlg.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
//?構造函數,初始化參數
CChess::CChess()
{
flagForbidHand=false;
memset(m_board0sizeof(m_board));?//初始化全局棋盤
m_turn=1;??//落子次序,1表示黑,2表示白
m_win=0;???//勝負標志,0表示初始值,1表示白勝,2表示黑勝
posflagNum=0;
tmpPos[0].x=-1;???//初始化最近落子位置
tmpPos[0].y=-1;
tmpPos[0].flag=0;
tmpPos[1].x=-1;???//初始化最近落子位置
tmpPos[1].y=-1;
tmpPos[1].flag=0;
isfirstnew1=true;
isfirstnew2=true;
isBackstep=false;
}
CChess::~CChess()
{
}
//?設置對戰模式,重置新棋局
void?CChess::NewGame(int?type)
{
isBackstep=false;
flagForbidHand=false;
memset(m_board0sizeof(m_board));
m_win=0;
m_turn=1;
posflagNum=1;
if(type==0)
m_board[7][7]=1;
ReDrawGame();
if(type==0)
m_turn=(m_turn==1?2:1);
else
m_turn=1;
}
//?重畫設置后的對戰模式
void?CChess::ReDrawGame()
{
isfirstnew1=true;
isfirstnew2=true;
DrawChessBoard();
DrawChessManAgain();
}
//?畫棋盤
void?CChess::DrawChessBoard()
{
dc->BitBlt(00470470qp00SRCCOPY);
}
//?重畫棋盤上已有的落子
void?CChess::DrawChessManAgain()
{
for(int?i=0;i<15;i++)
for(int?j=0;j<15;j++)
{
if(m_board[i][j]==1){DrawNewChessMan(ji1);}
if(m_board[i][j]==2){DrawNewChessMan(ji2);}
}
}
//?按下鼠標,開始落子
bool?CChess::DownMan(int?nx?int?nyint?typeHWND?hwnd)
{
isBackstep=false;
int?x?y;
//?判斷落子超界
if(nx<0||nx>14||ny<0||ny>14)?
{
AfxMessageBox(“超出棋盤位置!?請重新下子...“);
return?false;
}
//?判斷勝負
if(CChess::m_win!=0)?//0表示初始值,1表示白勝,2表示黑勝
{
if(m_win==1)?//黑勝
{
AfxMessageBox(“黑棋獲勝!?恭喜您!^_^“);
return?true;
}
else?//白勝
{
AfxMessageBox(“白棋獲勝!?恭喜您!^_^“);
return?true;
}
}
if(m_board[ny][nx]==0)
{
if(type==2)?//人人對戰
{
m_board[ny][nx]=m_turn;
DrawNewChessMan(nxnym_turn);
m_win=IsWinner(nxny);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋獲勝!?恭喜您!^_^“);return?true;}
if(m_win==2){AfxMessageBox(“白棋獲勝!?恭喜您!^_^“);return?true;}
return?true;
}
else??//人機對戰
{
m_board[ny][nx]=m_turn;
DrawNewChessMan(nxnym_turn);
m_win=IsWinner(nxny);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋獲勝!?恭喜您!^_^“);return?true;}
if(m_win==2){AfxMessageBox(“白棋獲勝!?恭喜您!^_^“);return?true;}
if(flagForbidHand)
{
m_turn=1;
return?false;
}
CChess::ComAlgo(xy);
m_board[y][x]=m_turn;
DrawNewChessMan(xym_turn);
m_win=IsWinner(xy);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋獲勝!?恭喜您!^_^“);return?true;}
if(m_win==2){AfxMessageBox(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????25392??2009-12-16?22:33??源代碼\Chess.cpp
?????文件???????1756??2009-12-15?15:45??源代碼\Chess.h
?????文件?????????40??2009-02-28?19:17??源代碼\info.h
?????文件?????260800??2009-12-16?22:11??源代碼\MyChess.aps
?????文件???????1945??2009-12-16?23:25??源代碼\MyChess.clw
?????文件???????2026??2009-12-15?17:19??源代碼\MyChess.cpp
?????文件???????4509??2009-12-13?19:28??源代碼\MyChess.dsp
?????文件????????522??2009-12-12?22:08??源代碼\MyChess.dsw
?????文件?????405581??2009-12-16?23:16??源代碼\MyChess.exe
?????文件???????1286??2009-02-27?13:43??源代碼\MyChess.h
?????文件?????640000??2009-12-16?23:25??源代碼\MyChess.ncb
?????文件??????53760??2009-12-16?23:25??源代碼\MyChess.opt
?????文件???????1405??2009-12-16?23:16??源代碼\MyChess.plg
?????文件???????6809??2009-12-16?22:11??源代碼\MyChess.rc
?????文件???????7094??2009-12-16?23:20??源代碼\MyChessDlg.cpp
?????文件???????1742??2009-12-16?23:07??源代碼\MyChessDlg.h
?????文件???????3567??2009-02-27?13:43??源代碼\ReadMe.txt
?????文件???????1078??2009-02-27?13:43??源代碼\res\MyChess.ico
?????文件????????398??2009-02-27?13:43??源代碼\res\MyChess.rc2
?????文件?????222920??2009-12-14?21:20??源代碼\res\qp.bmp
????..A.SH.??????9216??2009-12-14?21:20??源代碼\res\Thumbs.db
?????文件???????1693??2009-12-15?17:23??源代碼\resource.h
?????文件????????796??2009-12-12?21:30??源代碼\SettingDlg.cpp
?????文件???????1199??2009-12-12?21:29??源代碼\SettingDlg.h
?????文件????????947??2009-12-12?23:35??源代碼\SetupDlg.cpp
?????文件???????1208??2009-12-12?23:35??源代碼\SetupDlg.h
?????文件????????208??2009-02-27?13:43??源代碼\StdAfx.cpp
?????文件???????1054??2009-02-27?13:43??源代碼\StdAfx.h
?????目錄??????????0??2009-12-15?23:18??源代碼\res
?????目錄??????????0??2009-12-16?23:25??源代碼
............此處省略3個文件信息
評論
共有 條評論