資源簡介
MFC 五子棋 VS2013。實現功能:悔棋、動態調整棋盤、棋譜保存與播放

代碼片段和文件信息
#include?“stdafx.h“
#include?“ChessCenter.h“
#include?“tool/GDIPlusEx.h“
CChessCenter::CChessCenter(int?row?int?col)
:?m_nRow(row)?m_nCol(col)
{
m_ChessInfo?=?new?tChessItem*[m_nRow];?
for?(int?i?=?0;?i? {
m_ChessInfo[i]?=?new?tChessItem[m_nCol];
}
Reset();
}
CChessCenter::~CChessCenter()
{
for?(int?i?=?0;?i? {
delete[]?m_ChessInfo[i];
}
delete?m_ChessInfo;
}
void?CChessCenter::Reset()
{
m_bBlackIndex?=?true;
m_ChessQueue.clear();
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {?
m_ChessInfo[i][j].type?=?ITEM_TYPE_NONE;
}
}
}
bool?CChessCenter::UndoChess()
{
if?(m_ChessQueue.empty())
return?false;
unsigned?sz?=?m_ChessQueue.size();
tSaveItem?item?=?m_ChessQueue.at(sz?-?1);
m_ChessInfo[item.x][item.y].type?=?ITEM_TYPE_NONE;
m_ChessQueue.erase(m_ChessQueue.end()?-?1);
m_bBlackIndex?=?!m_bBlackIndex;
return?true;
}
void?CChessCenter::UpdatePosition(CRect&?rc)
{
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {
float?left?=?float(j?*?rc.Width())?/?m_nCol;
float?right?=?float((j?+?1)?*?rc.Width())?/?m_nCol;
float?top?=?float(i?*?rc.Height())?/?m_nRow;
float?bottom?=?float((i?+?1)?*?rc.Height())?/?m_nRow;
m_ChessInfo[i][j].position?=?CRect((int)left?(int)top?(int)right?(int)bottom);??
}
}
}
void?CChessCenter::DrawChess(CDC&?dc?CRect&?rc)
{?
dc.FillSolidRect(&rc?RGB(150?150?150));
//?畫棋盤的水平線條
CRect?rcTemp?=?rc;?
rc.bottom?-=?1;?
for?(int?i?=?0;?i?<=?m_nRow;?++i)
{
float?y?=?float(i?*?rc.Height())?/?m_nRow;?
CPoint?pt1(rc.left?(long)y);
CPoint?pt2(rc.right?(long)y);
dc.MoveTo(pt1);
dc.LineTo(pt2);
}
//?畫棋盤的垂直線條
rcTemp?=?rc;
rc.right?-=?1;
for?(int?i?=?0;?i?<=?m_nCol;?++i)
{
float?x?=?float(i?*?rc.Width())?/?m_nCol;
CPoint?pt1((long)x?rc.top);
CPoint?pt2((long)x?rc.bottom);
dc.MoveTo(pt1);
dc.LineTo(pt2);
}
//?畫棋子
CGDIPlus?gdip;
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {??
switch?(m_ChessInfo[i][j].type)
{
case?ITEM_TYPE_BLACK:
gdip.usFillRound(dc.m_hDC?TestChessRect(m_ChessInfo[i][j].position)?RGB(0?0?0)?TRUE);
break;
case?ITEM_TYPE_WHITE:
gdip.usFillRound(dc.m_hDC?TestChessRect(m_ChessInfo[i][j].position)?RGB(255?255?255)?TRUE);
break;
default:
break;
}
}
}
?
//?畫五連子的連線(如果有五連子)
tChessItem?start?end;
if?(CheckEnd(start?end))
{
CPoint?pt1;
pt1.x?=?start.position.left?+?start.position.Width()?/?2;
pt1.y?=?start.position.top?+?start.position.Height()?/?2;
CPoint?pt2;
pt2.x?=?end.position.left?+?end.position.Width()?/?2;
pt2.y?=?end.position.top?+?end.position.Height()?/?2;
CPen?pen(PS_SOLID?4?RGB(255?0?0));
dc.Selectobject(pen);
dc.MoveTo(pt1);
dc.LineTo(pt2);
}
}
CRect?CChessCenter::TestChessRect(CRect&?rc)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????3651072??2017-05-15?12:11??ChessDemo.exe
?????目錄???????????0??2017-05-15?12:12??VS2013-ChessDemo-五子棋\
?????文件????????5893??2017-05-12?16:45??VS2013-ChessDemo-五子棋\ChessCenter.cpp
?????文件?????????881??2017-05-12?17:23??VS2013-ChessDemo-五子棋\ChessCenter.h
?????文件????????3463??2017-05-15?11:43??VS2013-ChessDemo-五子棋\ChessDemo.cpp
?????文件?????????523??2017-05-12?13:14??VS2013-ChessDemo-五子棋\ChessDemo.h
?????文件???????14970??2017-05-15?12:10??VS2013-ChessDemo-五子棋\ChessDemo.rc
?????文件????????6671??2017-05-15?11:22??VS2013-ChessDemo-五子棋\ChessDemo.vcxproj
?????文件????????3540??2017-05-15?11:22??VS2013-ChessDemo-五子棋\ChessDemo.vcxproj.filters
?????文件????????3784??2017-05-14?16:06??VS2013-ChessDemo-五子棋\ChessDemoDlg.cpp
?????文件????????1094??2017-05-12?16:11??VS2013-ChessDemo-五子棋\ChessDemoDlg.h
?????文件????????6809??2017-05-15?11:19??VS2013-ChessDemo-五子棋\ChessView.cpp
?????文件????????1131??2017-05-15?11:19??VS2013-ChessDemo-五子棋\ChessView.h
?????文件????????4516??2017-05-15?12:11??VS2013-ChessDemo-五子棋\MessageNote.cpp
?????文件?????????643??2017-05-15?12:09??VS2013-ChessDemo-五子棋\MessageNote.h
?????文件????????4692??2017-05-12?13:14??VS2013-ChessDemo-五子棋\ReadMe.txt
?????目錄???????????0??2017-05-15?12:10??VS2013-ChessDemo-五子棋\res\
?????文件????????2730??2017-05-15?11:22??VS2013-ChessDemo-五子棋\resource.h
?????文件????????1150??2017-05-14?16:07??VS2013-ChessDemo-五子棋\res\b.ico
?????文件???????67777??2013-07-22?01:18??VS2013-ChessDemo-五子棋\res\ChessDemo.ico
?????文件?????????802??2017-05-12?13:14??VS2013-ChessDemo-五子棋\res\ChessDemo.rc2
?????文件?????????326??2017-05-14?16:28??VS2013-ChessDemo-五子棋\res\cursor1.cur
?????文件?????????326??2017-05-14?16:28??VS2013-ChessDemo-五子棋\res\cursor2.cur
?????文件??????302638??2017-05-15?12:10??VS2013-ChessDemo-五子棋\res\note.png
?????文件????????1150??2017-05-14?16:08??VS2013-ChessDemo-五子棋\res\w.ico
?????文件?????????211??2017-05-12?13:14??VS2013-ChessDemo-五子棋\stdafx.cpp
?????文件????????1909??2017-05-14?15:48??VS2013-ChessDemo-五子棋\stdafx.h
?????文件?????????314??2017-05-12?13:14??VS2013-ChessDemo-五子棋\targetver.h
?????目錄???????????0??2017-05-12?14:57??VS2013-ChessDemo-五子棋\tool\
?????文件???????30287??2015-03-27?17:24??VS2013-ChessDemo-五子棋\tool\GDIPlusEx.cpp
?????文件???????13889??2015-10-15?13:32??VS2013-ChessDemo-五子棋\tool\GDIPlusEx.h
............此處省略1個文件信息
- 上一篇:51單片機C語言程序設計教程 王云書本PDF樣章
- 下一篇:C++ STL參考手冊
評論
共有 條評論