資源簡(jiǎn)介
用VC開發(fā)的七巧板,可以用于C,C++,MFC,人工智能等的大作業(yè)

代碼片段和文件信息
//?Chip.cpp:?implementation?of?the?CChip?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“My.h“
#include?“Chip.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CChip?Cobject?1)
//?設(shè)置拼圖塊參數(shù)
void?CChip::SetChip(int?type?POINT?*ppointlist?int?count)
{
m_nType =?type;
m_nPointCount =?count;
for(int?i=0;?i m_pointList[i]?=?ppointlist[i];
}
//?繪出拼圖塊
void?CChip::DrawChip(CDC?*pDC)
{
CPen penNew?*ppenOld;
CBrush brushNew?*pbrushOld;
switch(m_nType)
{
case?1:
brushNew.CreateSolidBrush(RGB(127?127?127));
break;
case?2:
brushNew.CreateSolidBrush(RGB(255?0?0));
break;
case?3:
brushNew.CreateSolidBrush(RGB(0?255?0));
break;
case?4:
brushNew.CreateSolidBrush(RGB(0?0?255));
break;
case?5:
brushNew.CreateSolidBrush(RGB(127?127?0));
break;
case?6:
brushNew.CreateSolidBrush(RGB(127?0?127));
break;
case?7:
brushNew.CreateSolidBrush(RGB(0?127?127));
break;
}
penNew.CreatePen(PS_SOLID?1?RGB(0?0?0));
ppenOld =?pDC->Selectobject(&penNew);
pbrushOld =?pDC->Selectobject(&brushNew);
pDC->Polygon(m_pointList?m_nPointCount);
pDC->Selectobject(ppenOld);
pDC->Selectobject(pbrushOld);
}
//?檢測(cè)一點(diǎn)是否在拼圖塊中
BOOL?CChip::PtInChip(POINT?point)
{
CRgn?rgn;
int?x=rgn.CreatePolygonRgn(m_pointList?m_nPointCount?ALTERNATE);
return?rgn.PtInRegion(point);
}
//?取拼圖塊的包含矩形
LPCRECT?CChip::GetRect()
{
static?RECT?rect;
CRgn?rgn;
rgn.CreatePolygonRgn(m_pointList?m_nPointCount?ALTERNATE);
rgn.GetRgnBox(&rect);
rect.right++;
rect.bottom++;
return?▭
}
//?旋轉(zhuǎn)拼圖塊
void?CChip::Rotation()
{
CRect?rect;
CRgn?rgn;
rgn.CreatePolygonRgn(m_pointList?m_nPointCount?ALTERNATE);
rgn.GetRgnBox(&rect);
double?x?=?rect.left+rect.Width()/2; //?計(jì)算旋轉(zhuǎn)中心
double?y?=?rect.top+rect.Height()/2;
double?dx?dy;
for(int?i=0;?i {
dx?=?m_pointList[i].x-x;
dy?=?m_pointList[i].y-y;
m_pointList[i].x?=?(int)(x+dx*0.7071-dy*0.7071);
m_pointList[i].y?=?(int)(y+dx*0.7071+dy*0.7071);
}
}
//?移動(dòng)拼圖塊
void?CChip::MoveTo(CSize?offset)
{
for(int?i=0;?i m_pointList[i]?=?m_pointList[i]+offset;
}
//?序列化
void?CChip::Serialize(CArchive?&ar)
{
if(ar.IsStoring())
{
ar?< ar?< for(int?i=0;?i ar?< }
else
{
ar?>>?m_nType;
ar?>>?m_nPointCount;
for(int?i=0;?i ar?>>?m_pointList[i];
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2880??2003-09-05?13:32??七巧板\Chip.cpp
?????文件????????916??2003-09-05?13:32??七巧板\Chip.h
?????文件???????2503??2003-09-05?13:32??七巧板\MainFrm.cpp
?????文件???????1581??2003-09-05?13:32??七巧板\MainFrm.h
?????文件??????29372??2006-11-14?01:06??七巧板\My.aps
?????文件???????2205??2003-09-05?13:32??七巧板\My.clw
?????文件???????4146??2003-09-05?13:32??七巧板\My.cpp
?????文件???????4591??2003-09-05?13:32??七巧板\My.dsp
?????文件????????527??2003-09-05?13:32??七巧板\My.dsw
?????文件???????1312??2003-09-05?13:32??七巧板\My.h
?????文件??????54784??2003-09-05?13:32??七巧板\My.opt
?????文件???????1072??2003-09-05?13:32??七巧板\My.plg
?????文件??????10485??2003-09-05?13:32??七巧板\My.rc
?????文件????????868??2010-10-27?10:41??七巧板\My.sln
????..A..H.??????7680??2010-10-27?10:41??七巧板\My.suo
?????文件???????3906??2003-09-05?13:32??七巧板\MyDoc.cpp
?????文件???????1549??2003-09-05?13:32??七巧板\MyDoc.h
?????文件???????4355??2003-09-05?13:32??七巧板\MyView.cpp
?????文件???????2007??2003-09-05?13:32??七巧板\MyView.h
?????文件???????4215??2003-09-05?13:32??七巧板\ReadMe.txt
?????文件????????486??2003-09-05?13:32??七巧板\Resource.h
?????文件????????204??2003-09-05?13:32??七巧板\StdAfx.cpp
?????文件???????1054??2003-09-05?13:32??七巧板\StdAfx.h
?????目錄??????????0??2013-07-20?14:20??七巧板
-----------?---------??----------?-----??----
???????????????142698????????????????????24
評(píng)論
共有 條評(píng)論