📄 playzoneinc.h
字号:
#pragma once
inline void APlane::GetPlaneRect(CRect& rect) const
{
rect.left = Head.x + BoxOffsetX[D2N[Dir]][0];
rect.top = Head.y + BoxOffsetY[D2N[Dir]][0];
rect.right = Head.x + BoxOffsetX[D2N[Dir]][1];
rect.bottom = Head.y + BoxOffsetY[D2N[Dir]][1];
}
inline void APlane::GetPlaneTailPos(CTagPos& pos) const
{ GetNumPos(12,pos); }
inline void APlane::GetNumPos(int num,CTagPos& pos) const
{
ASSERT(num>0 && num<14);
int offset_r = HeadOffset[Dir_x[D2N[Dir]]][num];
int offset_b = HeadOffset[Dir_y[D2N[Dir]]][num];
pos.x = Head.x + offset_r;
pos.y = Head.y + offset_b;
}
/////////////////////////////////////////////////////////////////////
//
//
//
inline UINT CPlanes::AddPlane(const APlane& plane)
{
return AddPlane(plane.Head,plane.Dir);
}
inline void CPlanes::RemoveAllPlane()
{
planes.RemoveAll();
memset(Grid4Plane,0,sizeof(Grid4Plane));
}
inline void CPlanes::GetPlane(int num,APlane& plane) const
{
ASSERT(num>0 && num<=(int)GetMaxNum());
APlane t= planes.GetAt(num-1);
plane.Head = t.Head;
plane.Dir = t.Dir;
}
/////////////////////////////////////////////////////////////////////
//
//
//
inline CPlayZone::CPlayZone(int maxPlaneNum,bool IsGuessZone)
{
Planes.SetMaxPlaneNum(maxPlaneNum);
GuessZone = IsGuessZone;
IsStart = false;
IsActive = false;
}
inline CPlayZone::~CPlayZone()
{
if(PlaneDC){delete[] PlaneDC;PlaneDC=0;}
if(PlaneSize){delete[] PlaneSize;PlaneSize=0;}
if(BackgroundSize){delete[] BackgroundSize;BackgroundSize=0;}
if(BackgroundDC){delete[] BackgroundDC;BackgroundDC=0;}
}
inline void CPlayZone::DrawFlag()
{
//draw all flag
CTagPos TagPos;
_tag PosTag;
POSITION pos = TargetSet.GetStartPosition();
while (pos!=0)
{
TargetSet.GetNextAssoc(pos,TagPos,PosTag);
DoDrawFlag(TagPos,PosTag);
}
DUMP(L"------------OnPaint() DONE----------------");
}
inline BOOL CPlayZone::OnEraseBkgnd(CDC* pDC){(pDC);return true;}
inline void CPlayZone::NewGame()
{
Planes.RemoveAllPlane();
TargetSet.RemoveAll();
InvalidateRect(0,false);
}
inline _tag CPlayZone::GetFlag(CTagPos& pos) const
{
_tag t;
if(TargetSet.Lookup(pos,t))
return t;
else
return tagBLACK;
}
inline void CPlayZone::SetFlag(CTagPos& pos,const _tag flag)
{
CTagPos tp(pos);
_tag tt;
TargetSet.Lookup(tp,tt);
if(tt == flag)return;
TargetSet[pos] =flag;
InvalidateRect(0,false);
}
inline bool CPlanes::IsHead(int num,const CTagPos& pos) const
{
ASSERT(num>0 && num<=(int)GetMaxNum());
APlane plane;
GetPlane(num,plane);
//put Guesspalnes under flag;
CTagPos posHead;
plane.GetNumPos(1,posHead);
if(posHead == pos) return true;
return false;
}
inline int CPlanes::IsBody( const CTagPos& pos) const
{
APlane plane;
for(UINT i =1;i<=GetNum();++i)
{
GetPlane(i,plane);
if(plane.IsPlane(pos))return i;
}
return 0;
}
//inline bool CPlayZone::IsGuess(UINT x,UINT y){}
inline void CPlayZone::GetWindowRect(LPRECT lpRect) const
{
CWnd::GetWindowRect(lpRect);
lpRect->right = lpRect->left + Height;
lpRect->bottom = lpRect->top + Height;
}
inline void CPlayZone::CellToUnit(CRect& rect) const
{
CellToUnit(rect.left,rect.top);
CellToUnit(rect.right,rect.bottom);
}
inline void CPlayZone::UnitToCell(CTagPos& pos) const
{
UnitToCell(pos.x,pos.y);
}
inline void CPlayZone::UnitToCell(CRect& rect) const
{
UnitToCell(rect.left,rect.top);
UnitToCell(rect.right,rect.bottom);
}
#ifdef _DEBUG
inline void CPlayZone::ASSERT_CELL_RANGE(int cell_x,int cell_y) const
{
LONG min = 1;
//there could have the MaxCell+1 cell,
//it's using for identify the MaxCell's right
//not using for draw flag or somethin.
/*
MaxCell ------|
| |
| |
|------ MaxCell+1 usually == (14,14)
*/
LONG max = MaxCell+1;
ASSERT(cell_x>=min);
ASSERT(cell_y>=min);
ASSERT(cell_x<=max);
ASSERT(cell_y<=max);
}
inline void CPlayZone::ASSERT_UNIT_RANGE(int unit_x,int unit_y) const
{
LONG min = 0;
LONG max = Height;
ASSERT(unit_x>=min);
ASSERT(unit_y>=min);
ASSERT(unit_x<=max);
ASSERT(unit_y<=max);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -