⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datatype.h

📁 很经典的用C++编的空当接龙的程序
💻 H
字号:
#if !defined __DATATYPE_H__
#define __DATATYPE_H__

#define CARD(num,type)   (num + type*13)
#define IS_CARD(card)    (card<=52 && card>=1)
#define TYPE(card)       ((card-1)/13)
#define NUM(card)        ((card-1)%13+1)

#define COL_IN_CARD(c)   (c<=8)
#define COL_IN_BUFF(c)   (c>=9 && c<=12)
#define COL_IN_RECY(c)   (c>=13)

const CPoint ptOrg(1,17);//牌局左上角

const CARD_HEI = 94; // 每张牌的高度height
const CARD_WID = 69; // 每张牌的宽度width
const CARD_INT = 8;
	// 代表1-8列中每两堆牌之间的间隔(interval)
	// (第9,16两列分别与窗口两边的间距也是这个值)
const PILE_VINT = 8; // 牌列与缓存列间垂直方向上的间隔
const PILE_HINT = 9*CARD_INT; //缓存列与回收列之间的水平间隔
const CARD_UNCOVER = 18; // 当被一张牌压着的时候,此露出的部分的高度

//usage: clr[BIG/SML][HT/HX/MH/FK][UP/DN][X/Y]...
const UCHAR BIG=0, SML=1, big=16, sml=8;
const UCHAR clr[2][4][2][2] = {
		{	{	{0 *big,1 *big},//黑桃上
				{1 *big,1 *big},//黑桃下
			},{	{0 *big,2 *big},//红桃上
				{1 *big,2 *big},//红桃下
			},{	{0 *big,3 *big},//梅花上
				{1 *big,3 *big},//梅花下
			},{	{0 *big,4 *big},//方块上
				{1 *big,4 *big},//方块下
			}
		},{	{	{0 *sml,0 *sml},
				{0 *sml,1 *sml}
			},{	{1 *sml,0 *sml},
				{1 *sml,1 *sml}
			},{	{2 *sml,0 *sml},
				{2 *sml,1 *sml}
			},{	{3 *sml,0 *sml},
				{3 *sml,1 *sml}
			}
		}
	};
//牌A--牌10的图像数据
const UCHAR x12   = CARD_WID      /  2;
const UCHAR x13   = CARD_WID *  9 / 30;
const UCHAR x23   = CARD_WID * 21 / 30;
const UCHAR y12   = CARD_HEI      /  2;
const UCHAR y15   = CARD_HEI      /  5;
const UCHAR y25   = CARD_HEI *  2 /  5;
const UCHAR y35   = CARD_HEI *  3 /  5;
const UCHAR y45   = CARD_HEI *  4 /  5;
const UCHAR y310  = CARD_HEI *  3 / 10;
const UCHAR y710  = CARD_HEI *  7 / 10;
const UCHAR y720  = CARD_HEI *  7 / 20;
const UCHAR y1320 = CARD_HEI * 13 / 20;

const UCHAR cA[] = { x12 , y12 , 1, };
const UCHAR c2[] = { x12 , y15 , 1, x12 , y45 , 0, };
const UCHAR c3[] = { x12 , y15 , 1, x12 , y45 , 0, x12 , y12 , 1, };
const UCHAR c4[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y45 , 0, x23 , y45 , 0, };
const UCHAR c5[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y45 , 0, x23 , y45 , 0, x12 , y12 , 1, };
const UCHAR c6[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y45 , 0, x23 , y45 , 0, x13 , y12 , 1, x23 , y12 , 1, };
const UCHAR c7[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y45 , 0, x23 , y45 , 0, x13 , y12 , 1, x23 , y12 , 1, x12 , y720 , 1 , };
const UCHAR c8[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y25 , 1, x23 , y25 , 1, x13 , y35 , 0, x23 , y35 , 0, x13 , y45  , 0 , x23 , y45   , 0 };
const UCHAR c9[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y25 , 1, x23 , y25 , 1, x13 , y35 , 0, x23 , y35 , 0, x13 , y45  , 0 , x23 , y45   , 0 , x12 , y12  , 1 , };
const UCHAR c10[]= { x13 , y15 , 1, x23 , y15 , 1, x13 , y25 , 1, x23 , y25 , 1, x13 , y35 , 0, x23 , y35 , 0, x13 , y45  , 0 , x23 , y45   , 0 , x12 , y310 , 1 , x12 , y710 , 0 , };
const UCHAR c8FK[] = { x13 , y15 , 1, x23 , y15 , 1, x13 , y45 , 0, x23 , y45 , 0, x13 , y12 , 1, x23 , y12 , 1, x12 , y720 , 1 , x12 , y1320 , 0 , };

const UINT modeCrWr = CFile::modeWrite | CFile::modeCreate;
const UINT modeRead = CFile::modeRead;
const DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
static const char * filter = "接龙存档文件(*.rep)|*.rep||";//文件名过滤器

//步骤计数的字体高度
const UINT stepFont = 22;

//解码
void Decoding(CFile & desFile, CFile & srcFile);

//////////////////////////////////////////////////////////
class COperation : public CObject
{
	DECLARE_SERIAL(COperation)

public:
	UCHAR src,des,cnt;//记录从第src列移动cnt张牌到第des列

	COperation() 
		: des(0),src(0),cnt(0) 
	{ }

	COperation(UINT d,UINT s,UINT n) 
		: des(d),src(s),cnt(n) 
	{ }

	void Serialize(CArchive &ar) {
		//CObject does not serialize anything by default
		//CObject::Serialize(ar);
		if(ar.IsStoring()) { 
			ar<<src<<des<<cnt;
		} else {
			ar>>src>>des>>cnt;
		}
	}
};
//////////////////////////////////////////////////////////
class COperations : public CObject
{
public:
	COperations() 
	{	
		pOps = new CObList;
	}

	COperations(UINT des,UINT src,UINT n) 
	{
		pOps = new CObList;
		pOps->AddHead(new COperation(des,src,n)); 
	}

	void AddOperation(UINT des,UINT src,UINT n) { 
		pOps->AddHead(new COperation(des,src,n)); 
	}

	void ClrOps() {
		POSITION p = pOps->GetHeadPosition();
		while(p) {
			COperation *pOp = (COperation *)pOps->GetNext(p);
			delete pOp;
		}
		pOps->RemoveAll();
	}

	~COperations() { 
		ClrOps();
		delete pOps;
	}

	void Serialize(CArchive &ar) {
		//CObject does not serialize anything by default
		//CObject::Serialize(ar);
		pOps->Serialize(ar);
	}

	CObList *pOps;
	DECLARE_SERIAL(COperations)
};

//////////////////////////////////////////////////////////
//记录下一步的所有可能的移动步骤用于提示
class HINTS : public COperations
{
	int curHint;
public:
	HINTS() {
		curHint = 0;
	}
	//
	// before call NextHint, you must firstly 
	// call COperations::AddOperation to fill
	// the operation list, for it should NOT be 
	// empty
	//
	const COperation* NextHint(void) {
		ASSERT(!pOps->IsEmpty());
		int cnt = pOps->GetCount();
		if(curHint >= cnt) {
			curHint = 0;
		}
		//最先提示链尾的动作
		const COperation* pOp = (const COperation*)
			pOps->GetAt(pOps->FindIndex(cnt - ++curHint));
		return pOp;
	}
	void ClrHints(void) {
		ClrOps();
		curHint = 0;
	}
	BOOL IsEmpty() {
		return pOps->IsEmpty();
	}
};

///////////////////////////////////
struct CARD_POS { UINT col,idx; };
///////////////////////////////////

#define MIN_GAME_NUMBER 1
#define MAX_GAME_NUMBER 0x7FFFFFFF

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -