茫然,不知道自己想的对不对,希望高手指点一二,不胜感激!
我按照书上的程序做了个中国象棋程序,只能显示棋盘,棋子,及显示该谁下棋。能移动棋子,能吃子。
想完善一点,比如,车的走法,马的走法,士的走法!!以前没有自己做过程序,自己没有思路,不知道该改哪个函数?是否需要派生棋子类??还是要加一个函数或者if语句等等,比较茫然。http://sybook.icpcn.com/xiangqi.exe上有源程序,谢谢帮忙指点一下!!本人不胜感激,会马上结帖给您分的!!!共有(CPlate)棋盘类,(CStone)棋子类,(CMyWnd)框架窗口类,(CMyApp)应用窗口类四个类,各类的成员函数如下:
class CPlate //棋盘类
{
CPlate(); //构造函数
void ShowPlate(CDC *pDC); //显示棋盘
void DrawConer(CDC *pDC,int row,int col,int type); //画兵炮标志
CPoint GetPosition(int col,int row); //取棋盘上交叉点的坐标
}
class CStone//棋子类
{
CStone(){}
CStone(BOOL red,int col,int row,LPCSTR name,int type,CPlate &plate);
void ShowStone(CDC *pDC);
void MoveTo(int col,int row,CPlate &plate);
CRect GetRect() {return m_rectStone;}
int GetType() {return m_nType;}
BOOL BeKilled(int col,int row)
{return m_bShow && m_nCol==col&&m_nRow==row;}
BOOL MouseOnStone(CPoint point)
{return m_rectStone.PtInRect(point)&&m_bShow;}
void KillIt() {m_bShow=FALSE;}
void SelectStone(){m_bSelected=!m_bSelected;}
}; class CMyWnd:public CFrameWnd//框架窗口类
{
CMyWnd(){InitGame();}
void InitGame();
void ShowInfo(CDC *pDC);
BOOL KillSelfStone(int col,int row,BOOL red);
int KillEnemy(int col,int row,BOOL red);
void MoveStone(CPoint point);
void SelectStone(CPoint point);
void Go(CPoint);
BOOL MoveTo(int,int);class CMyApp:public CWinApp//应用窗口类
{
public:
BOOL InitInstance();
};
我按照书上的程序做了个中国象棋程序,只能显示棋盘,棋子,及显示该谁下棋。能移动棋子,能吃子。
想完善一点,比如,车的走法,马的走法,士的走法!!以前没有自己做过程序,自己没有思路,不知道该改哪个函数?是否需要派生棋子类??还是要加一个函数或者if语句等等,比较茫然。http://sybook.icpcn.com/xiangqi.exe上有源程序,谢谢帮忙指点一下!!本人不胜感激,会马上结帖给您分的!!!共有(CPlate)棋盘类,(CStone)棋子类,(CMyWnd)框架窗口类,(CMyApp)应用窗口类四个类,各类的成员函数如下:
class CPlate //棋盘类
{
CPlate(); //构造函数
void ShowPlate(CDC *pDC); //显示棋盘
void DrawConer(CDC *pDC,int row,int col,int type); //画兵炮标志
CPoint GetPosition(int col,int row); //取棋盘上交叉点的坐标
}
class CStone//棋子类
{
CStone(){}
CStone(BOOL red,int col,int row,LPCSTR name,int type,CPlate &plate);
void ShowStone(CDC *pDC);
void MoveTo(int col,int row,CPlate &plate);
CRect GetRect() {return m_rectStone;}
int GetType() {return m_nType;}
BOOL BeKilled(int col,int row)
{return m_bShow && m_nCol==col&&m_nRow==row;}
BOOL MouseOnStone(CPoint point)
{return m_rectStone.PtInRect(point)&&m_bShow;}
void KillIt() {m_bShow=FALSE;}
void SelectStone(){m_bSelected=!m_bSelected;}
}; class CMyWnd:public CFrameWnd//框架窗口类
{
CMyWnd(){InitGame();}
void InitGame();
void ShowInfo(CDC *pDC);
BOOL KillSelfStone(int col,int row,BOOL red);
int KillEnemy(int col,int row,BOOL red);
void MoveStone(CPoint point);
void SelectStone(CPoint point);
void Go(CPoint);
BOOL MoveTo(int,int);class CMyApp:public CWinApp//应用窗口类
{
public:
BOOL InitInstance();
};
各派生类中限制各自的走法,无非是重载MoveTo(int col,int row,CPlate &plate)函数,当然,你的CStone的MoveTo设置成纯虚函数例如,车的MoveTo限制,同一时刻只能是col或者row其中之一变化,不能同时变化,否则不移动棋子
其他的类似
希望对你有所帮助
在你的MoveTo,MouseOnStone函数中根据棋类型,来判断用户请求的这步棋是否合法.
最好是派生棋子类,每种棋子一个类,然后16个棋子组成对局双方的类。很直观的思路。
相应的事件中处理一下操作不就可以了!