📄 playzone.h
字号:
#pragma once
#include <afxtempl.h>
const int MaxCell = 13;
//form 1(head) to 13 (tail:12)
//int offset_r = HeadOffset[Dir_x[D2N[Dir]]][12];
//int offset_b = HeadOffset[Dir_y[D2N[Dir]]][12];
//Tail.x = Head.x + offset_r;
//Tail.y = Head.y + offset_b;
const int HeadOffset[4][14] = {
{0, 0,-3,-2,-1, 0, 1, 2, 3, 0, 0,-1, 0, 1}, //down
{0, 0, 3, 2, 1, 0,-1,-2,-3, 0, 0, 1, 0,-1}, //up
{0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 4}, //right
{0, 0,-1,-1,-1,-1,-1,-1,-1,-2,-3,-4,-4,-4} //left
};
//dir: 1 - 4
//left-top:0 right-bottom:1
//left-top.x = Head.x + BoxOffsetX[D2N[Dir]][0]
//left-top.y = Head.y + BoxOffsetY[D2N[Dir]][0]
//right-bottom.x = Head.x + BoxOffsetX[D2N[Dir]][1]
//right-bottom.y = Head.y + BoxOffsetY[D2N[Dir]][1]
const int BoxOffsetX[4][2]={{-4,1},{-3,4},{0,5},{-3,4}};
const int BoxOffsetY[4][2]={{-3,4},{0,5},{-3,4},{-4,1}};
const int Dir_x[4] = {3,0,2,1};
const int Dir_y[4] = {0,2,1,3};
//Direction to indexNmber
//left:1(0) down:2(1) right:4(2) up:8(3)
const int D2N[9]= {0,0,1,0,2,0,0,0,3};
const PlaneDirect N2D[4]= {pdLEFT,pdDOWN,pdRIGHT,pdUP};
//typedef CPoint CTagPos
struct CTagPos
{
LONG y;//1 - 13
LONG x;//1 - 13
CTagPos(){x=y=0;}
CTagPos(UINT _x,UINT _y){x=_x;y=_y;}
//for the trash-class CMap
operator DWORD_PTR() const{ return (x<<16)|y; }
CTagPos& operator =(const CTagPos& key2);
CTagPos(const CTagPos& key){x = key.x; y = key.y;}
};
inline operator ==(const CTagPos& key1,const CTagPos& key2)
{ return (key1.x == key2.x)&&(key1.y == key2.y); }
inline CTagPos& CTagPos::operator =(const CTagPos& key2)
{ x = key2.x; y = key2.y; return *this;}
//class CTagPos:public CPoint
//{
//public:
// CTagPos(){};
// CTagPos(int initX, int initY):CPoint(initX,initY){}
// operator DWORD_PTR() const{ return x+y;}
//
//};
struct APlane{
CTagPos Head;
PlaneDirect Dir;
APlane(){}
APlane(const APlane& plane){ Head = plane.Head; Dir=plane.Dir; }
APlane(CTagPos head,PlaneDirect dir){ Head = head;Dir=dir; }
void GetPlaneRect(CRect& rect) const;
void GetPlaneTailPos(CTagPos& pos) const;
void GetNumPos(int num,CTagPos& pos) const;
bool IsPlane(CTagPos pos) const;
};
class CPlanes
{
UINT Max;
CArray<APlane> planes;
//[1..13] * [1..13] 0 is not used
bool Grid4Plane[MaxCell+1][MaxCell+1];
public:
CPlanes(){Max = 0; memset(Grid4Plane,0,sizeof(Grid4Plane)); }
CPlanes(UINT max){Max = max; memset(Grid4Plane,0,sizeof(Grid4Plane)); }
void SetMaxPlaneNum(int max){Max = max;}
//DO NOT NEED Point out which plane is;
UINT GetMaxNum() const;
UINT GetNum() const;
UINT AddPlane(const CTagPos& head,PlaneDirect dir);
UINT AddPlane(const APlane& plane);
//WARNING the bound is [1,max]
void GetPlane(int num,APlane& plane) const;
void GetPlane(const CTagPos& pos,APlane& plane) const;
void RemovePlane(int num);
void RemoveAllPlane();
bool NoAnotherPlane(const CTagPos& pos) const;
bool NoAnotherPlane(const APlane& plane) const;
bool IsHead(int num, const CTagPos& pos) const;
//the id of a plane
//or 0 is not in a body
int IsBody(const CTagPos& pos) const;
};
inline UINT CPlanes::GetMaxNum() const { return Max;}
inline UINT CPlanes::GetNum() const { return (UINT)planes.GetCount();}
//////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////
//using for
class CPlayZone : public CStatic
{
DECLARE_DYNAMIC(CPlayZone)
DECLARE_MESSAGE_MAP()
CRect ClientRect;
UINT Height;//zone height
UINT cell;//every cell height
//4 flag tag
static HICON HeadTag;//icon of a head tag
static HICON BodyTag;
static HICON GuessTag;
static HICON NoneTag;
//4 planes
static CDC* PlaneDC;
static CSize* PlaneSize;
//2 background
static CDC* BackgroundDC;
static CSize* BackgroundSize;
//using for test PosiblePos
static HICON TailTagHEAD;
static HICON TailTagTAIL;
CTagPos ShowTailTag[4];
CTagPos SetHeadPos;
//已经被对方确认的标记:
CMap<CTagPos,CTagPos&,_tag,_tag> TargetSet;
void DrawFlag();
void DoDrawFlag(const CTagPos& pos, _tag flag) const;
CPlanes Planes;
CDC MemDC;
MBU On1stMButtonUp(const CTagPos& point);
MBU On2ndMButtonUp(const CTagPos& point);
bool IsActive;
bool GuessZone;
protected:
void DrawBkGroud();
void DrawPosiblePos();
void DrawMainGrid();
void DrawPlane();
bool SetFourGuessPlaneTail(const CTagPos& head);
bool SetGuessPlane(const CTagPos& head,PlaneDirect dir);
void SetFlagGuess(const CTagPos& pos);
//这4个函数为了转换屏幕关系而设立
//如绘制 或 鼠标拾取
//返回的logical unit是本子窗口的本地坐标系,即 左上角为(0,0)
void CellToUnit(LONG& x,LONG& y) const;
void CellToUnit(CRect& rect) const;
void UnitToCell(CTagPos& pos) const;
void UnitToCell(LONG& x,LONG& y) const;
void UnitToCell(CRect& rect) const;
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
#ifdef _DEBUG
void ASSERT_CELL_RANGE(int cell_x,int cell_y) const;
void ASSERT_UNIT_RANGE(int unit_x,int unit_y) const;
#endif
public:
//此变量用来显示相应的字符串。
bool IsStart;
//MUST specify the max plane number.
CPlayZone(int maxPlaneNum,bool IsGuessZone);
~CPlayZone();
void OnInit();
void GetWindowRect(LPRECT lpRect) const;
void NewGame();
//this one is for GuessZone & SetZone
MBU OnMButtonUp(CPoint point);
//these two is for SetZone
bool OnGuessLButtonUp(CPoint point,int& cell_x,int& cell_y);
void OnGuessRButtonUp(CPoint point);
_tag GetFlag(CTagPos& pos) const;
void SetFlag(CTagPos& pos,const _tag flag);
void SetActive(bool act=true);
_tag IsBombed(int x,int y) const;
};
#include ".\PlayZoneInc.h"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -