資源簡介
不支持人機對弈,必須逐步跳躍,不能只指定起點終點自動計算路徑,此點可設計適當算法進行完善。鼠標右鍵表示移動取消/完成。C++ VS2005

代碼片段和文件信息
//?Chess.cpp:?implementation?of?the?CChess?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“JumpChess.h“
#include?“Chess.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CChess?Cobject?0)
CChess::CChess()
{
PutChess(true);
}
CChess::~CChess()
{
}
void?CChess::InitChess(int?p_block)
{
m_nBlockNumber?=?p_block;
m_nCurrentPlayer?=?0;
m_nPrevLine?=?0;
m_nPrevCol?=?0;
m_nStartLine?=?0;
m_nStartCol?=?0;
bPending=false;
m_bFirstJump?=?true;
bContinueMove?=?false;
m_bWin[0]=false;
m_bWin[1]=false;
PutChess(false);
}
int?CChess::Who(int?i?int?j)
{
return?m_arrChess[i][j];
}
bool?CChess::IsValid(int?line?int?col)
{
return?(col?>=?JC_COL_BEGIN[line])?&&?(col?<=?JC_COL_END[line]);
}
int?CChess::ClickAt(int?line?int?col?int?&?prev_line?int?&?prev_col)
{
if(bPending)
{
if(m_arrChess[line][col]?!=?0)?//?try?to?move?to?a?non-empty?hole
return?0;
?//judge?whether?the?move?is?valid
int?nCanMove?=?CanMove(m_nPrevLinem_nPrevCollinecol);
if(nCanMove?==?0)
return?0;
else
{
if(nCanMove?==?1)?//last?drop
{
int?nOriChess?=?m_arrOriChess[line][col];
int?nChess?=?m_arrChess[m_nPrevLine][m_nPrevCol];
if(nOriChess?!=?0)
{
if(nOriChess?!=?nChess?&&?nOriChess?!=?GetRevChess(nChess))
return?6;?//?try?to?stop?at?other?chess‘s?base?except?it‘s?and?it‘s?rev?chess
}
}
prev_line?=?m_nPrevLine;
prev_col?=?m_nPrevCol;
m_arrChess[line][col]?=?m_arrChess[m_nPrevLine][m_nPrevCol];
m_arrChess[m_nPrevLine][m_nPrevCol]?=?0;
m_nPrevLine?=?line;
m_nPrevCol?=?col;
}
if(nCanMove?==?1)?//last?drop
{
bPending?=?false;
if(IsWin(linecol))
{
int?nOther?=?(m_nCurrentPlayer?==?0)???1?:?0;
m_bWin[m_nCurrentPlayer]?=?true;
if(m_bWin[nOther])?//Game?is?end!?another?win!
return?4;
else?//?current?player?win!?Let?another?continue?moving
{
bContinueMove?=?true;
m_nCurrentPlayer?=?nOther;
return?5;
}
}
//?next?player
if(!bContinueMove)
{
if(m_nCurrentPlayer?==?0)
m_nCurrentPlayer?=?1;
else
m_nCurrentPlayer?=?0;
}
return?3;
}
else?//?not?last?drop
{
m_bFirstJump?=?false;
return?2;
}
}
else
{
int?nCurChess?=?m_arrChess[line][col];
if?(nCurChess?==?0)?//first?click?should?not?be?in?a?empty?hole
return?0;
if(m_nCurrentPlayer?==?0)?//?left?player
if(nCurChess?==?4?||?nCurChess?==?5?||?nCurChess?==?6)?
//try?to?move?another?player‘s?chess
return?0;
if(m_nCurrentPlayer?==?1)?//?right?player
if(nCurChess?==?1?||?nCurChess?==?2?||?nCurCh
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3564??2007-12-22?21:58??JumpChess.clw
?????文件???????4138??2016-09-07?21:52??JumpChess.cpp
?????文件???????6145??2006-02-15?18:58??JumpChess.dsp
?????文件????????541??2004-11-29?21:20??JumpChess.dsw
?????文件???????1399??2004-08-02?11:33??JumpChess.h
?????文件????8252416??2016-09-07?21:53??JumpChess.ncb
?????文件??????56832??2011-06-20?23:15??JumpChess.opt
?????文件???????1883??2011-06-20?23:06??JumpChess.plg
?????文件??????12713??2004-08-06?08:08??JumpChess.rc
?????文件????????882??2015-08-25?22:37??JumpChess.sln
?????文件??????10444??2015-08-25?22:37??JumpChess.vcproj
?????文件???????1427??2016-09-07?21:53??JumpChess.vcproj.UBPJ19NPZWDN1SU.Administrator.user
?????文件???????2044??2004-08-05?13:17??JumpChessDoc.cpp
?????文件???????1549??2004-08-02?19:43??JumpChessDoc.h
?????文件??????17822??2006-02-16?13:02??JumpChessView.cpp
?????文件???????2622??2004-08-08?17:13??JumpChessView.h
?????文件???????1498??2004-08-05?14:04??MainFrm.cpp
?????文件???????1426??2004-08-02?11:33??MainFrm.h
?????文件???????3832??2004-08-02?11:33??ReadMe.txt
?????文件???????1320??2004-08-05?20:27??Resource.h
?????文件???????1016??2004-08-05?13:13??SetBlockDlg.cpp
?????文件???????1267??2004-08-05?13:12??SetBlockDlg.h
?????文件????????207??2004-08-02?11:33??StdAfx.cpp
?????文件????????928??2004-08-02?11:33??StdAfx.h
?????文件????????822??2006-02-16?12:43??res\Bmp\chess1.bmp
?????文件????????822??2006-02-16?12:43??res\Bmp\chess2.bmp
?????文件????????822??2006-02-16?12:44??res\Bmp\chess3.bmp
?????文件????????822??2006-02-16?12:44??res\Bmp\chess4.bmp
?????文件????????822??2006-02-16?12:44??res\Bmp\chess5.bmp
?????文件????????822??2006-02-16?12:45??res\Bmp\chess6.bmp
............此處省略33個文件信息
評論
共有 條評論