📄 ctank.h
字号:
//////////////////////////////////////////////////////////////////////////////////////////////////
// # # //
// # * File Name: CTank.h # //
// # # //
// # * Function: the engine of the game # //
// # # //
// # * Instruction: Created by JIAN NAN FEI 2008 8 29 # //
// # # //
///////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------//
// DEFINES REFERENCES HERE //
//----------------------------------------------------------------------------------------------//
#define TANK_TYPE_1 0
#define TANK_TYPE_2 1
#define TANK_TYPE_3 2
#define TANK_TYPE_4 3
#define TANK_TYPE_5 4
#define TANK_TYPE_6 5
#define TANK_TYPE_7 6
#define TANK_TYPE_8 7
#define TANK_MOVE_UP 0
#define TANK_MOVE_DOWN 1
#define TANK_MOVE_LEFT 2
#define TANK_MOVE_RIGHT 3
#define TANK_SHOOT_UP 0
#define TANK_SHOOT_DOWN 1
#define TANK_SHOOT_LEFT 2
#define TANK_SHOOT_RIGHT 3
#define TANK_BASIC_POWER 500
#define TANK_BASIC_LIFECOUNT 1000
#define TANK_BASIC_LIFETIMES 3
#define TANK_BASIC_SPEED 1
#define TANK_STATE_ATTACK 10
#define TANK_STATE_BEATTACKED 11
#define TANK_STATE_MOVE 12
#define TANK_STATE_STOP 13
#define TANK_STATE_VIEW 14
#define TANK_BELONG_FRIENDS 1
#define TANK_BELONG_ENEMIES 0
#define TANK_WIDTH 56
#define TANK_HEIGHT 64
#define GAME_SCREEN_WIDTH 36*80
#define GAME_SCREEN_HEIGHT 21*80
#define GAME_SCREENREMOVEX 0
#define GAME_SCREENREMOVEY 40
//----------------------------------------------------------------------------------------------//
// HEADFILES REFERENCES HERE //
//----------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------//
// GLOBAL MEMBER VARIAYS REFERENCES HERE //
//----------------------------------------------------------------------------------------------//
struct CTankNode;
class CTank;
//-----------------------------------------------------------------------------
//
// Name: CTankNode
// Disc: the structure of the node of the tank
//-----------------------------------------------------------------------------
typedef struct CTankNode
{
BOOL m_bState; // the static state of the tank
int m_nType; // the type of the tank , it will effect the lifecount of the tank
int m_nPower; // the power of the tank
int m_nLifeCount; // the lifecount of the tank
int m_nLifeTimes; // the life that the the tank have
RECT m_rRect;
}TANKNODE,*PTANKNODE;
//-----------------------------------------------------------------------------
//
// Name: CTank
// Disc: the structure of the class of the tank
//-----------------------------------------------------------------------------
typedef class CTank
{
protected:
TANKNODE m_tTank; // the node of the tank
int m_nBelong; // the tank is belong to whom
POINT m_ptNowPos; // the present position of the tank
int m_nMoveDirection; // the move direction the tank
int m_nShootDirection; // the attack direction the tank
int m_nTankState; // the present dynamic state of the tank
int m_nSpeed; // the move speed of the tank
int m_nMapBoundryX;
int m_nMapBoundryY;
public:
CTank();
CTank(int Type,int power,int lifecount,int lifetimes,int belong,POINT point,
int movedirection,int shootdirection,int speed,int top,int bottom,int left,int right);
void SetLivingState(BOOL state) { m_tTank.m_bState=state; };
void SetType(int type) { m_tTank.m_nType=type; };
void SetPower(int power ) { m_tTank.m_nPower=power; };
void SetLifeCount(int lifecount) { m_tTank.m_nLifeCount=lifecount; };
void SetLifeTimes(int lifetimes) { m_tTank.m_nLifeTimes=lifetimes; };
void SetRect(int left,int right,
int bottom,int top) { m_tTank.m_rRect.top=top; m_tTank.m_rRect.bottom;
m_tTank.m_rRect.left=left; m_tTank.m_rRect.right=right; };
void SetTankState(int state) { m_nTankState=state; };
void SetTankBelong( int belong ) { m_nBelong=belong; };
void SetNowPos(int x,int y) { m_ptNowPos.x=x;
m_ptNowPos.y=y; };
void SetMoveDirection(int direction) { m_nMoveDirection=direction; };
void SetShootDirection(int direction) { m_nShootDirection=direction; };
void SetSpeed(int speed){ m_nSpeed=speed; };
void SetTank(int type,int belong);
BOOL IsVisible() { return m_nTankState==TANK_STATE_VIEW; };
BOOL IsLivable() { return m_tTank.m_bState==TRUE; };
BOOL IsBeAttacked() { return m_nTankState==TANK_STATE_BEATTACKED; };
BOOL IsMoveable() { return m_nTankState==TANK_STATE_MOVE; };
BOOL IsAttackable() { return m_nTankState==TANK_STATE_ATTACK; };
BOOL Attack();
void BeAttacked(int power);
int GetTankType() { return m_tTank.m_nType; };
int GetPower() { return m_tTank.m_nPower; };
RECT GetTankRect() { return m_tTank.m_rRect; };
int GetTankState() { return m_nTankState; };
int GetTankBelong(){ return m_nBelong; };
POINT GetNowPos() { return m_ptNowPos; };
int GetMDirection(){ return m_nMoveDirection; };
int GetSDirection(){ return m_nShootDirection;};
int GetLifecount() { return m_tTank.m_nLifeCount; };
int GetLifeTimes() { return m_tTank.m_nLifeTimes; };
int GetSpeed() { return m_nSpeed; };
void GetMapBoundry(int x,int y) { m_nMapBoundryX=x;
m_nMapBoundryY=y;};
int RandDirection();
int GetReverseDirection();
BOOL UpOk() { if(m_ptNowPos.y-m_nSpeed<GAME_SCREENREMOVEY&&
m_nMoveDirection==TANK_MOVE_UP ) return FALSE; return TRUE;};
BOOL DownOk() { if(m_ptNowPos.y+m_nSpeed>GAME_SCREEN_HEIGHT-WALL_HEIGHT+TANK_HEIGHT&&
m_nMoveDirection==TANK_MOVE_DOWN ) return FALSE; return TRUE;};
BOOL LeftOk() { if(m_ptNowPos.x-m_nSpeed<GAME_SCREENREMOVEX&&
m_nMoveDirection==TANK_MOVE_LEFT ) return FALSE; return TRUE;};
BOOL RightOk(){ if(m_ptNowPos.x+m_nSpeed>GAME_SCREEN_WIDTH-TANK_HEIGHT&&
m_nMoveDirection==TANK_MOVE_RIGHT ) return FALSE; return TRUE;};
void MoveUp() { if(UpOk()) m_ptNowPos.y-=m_nSpeed; };
void MoveDown() { if(DownOk()) m_ptNowPos.y+=m_nSpeed; };
void MoveLeft() { if(LeftOk()) m_ptNowPos.x-=m_nSpeed; };
void MoveRight(){ if(RightOk()) m_ptNowPos.x+=m_nSpeed; };
void Move();
}TANK,*PTANK;
//----------------------------------------------------------------------------------------------//
// FUNCTION MEMBERS REFERENCES HERE //
//----------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------//
// COMPLISHMENT OF THE FILE //
//----------------------------------------------------------------------------------------------//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -