• 大小: 33KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-19
  • 语言: C/C++
  • 标签: VC  七巧板  人工智能  

资源简介

用VC开发的七巧板,可以用于C,C++,MFC,人工智能等的大作业

资源截图

代码片段和文件信息

// 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)
// 设置拼图块参数
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);
}
// 检测一点是否在拼图块中
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 ▭
}
// 旋转拼图块
void CChip::Rotation()
{
CRect rect;
CRgn rgn;
rgn.CreatePolygonRgn(m_pointList m_nPointCount ALTERNATE);
rgn.GetRgnBox(&rect);
double x = rect.left+rect.Width()/2; // 计算旋转中心
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);
}
}
// 移动拼图块
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 << m_nType;
ar << m_nPointCount;
for(int i=0; i ar << m_pointList[i];
}
else
{
ar >> m_nType;
ar >> m_nPointCount;
for(int i=0; i ar >> m_pointList[i];
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       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


评论

共有 条评论