📄 cell.cpp
字号:
#include "Cell.h"
#include "Map.h"
#include "Predeclarations.h"
#include <iostream>
using namespace _base;
////////////////////////////////////////////////////////////
Cell::Cell(Map * const map)
: m_pMap(map)
{
this->mCellType = CT_None;
this->m_pCellUp = NULL;
this->m_pCellDown = NULL;
this->m_pCellLeft = NULL;
this->m_pCellRight = NULL;
}
////////////////////////////////////////////////////////////
Cell::Cell(const Cell &from)
: m_pMap(from.m_pMap)
{
mCellType = from.mCellType;
};
////////////////////////////////////////////////////////////
Cell::~Cell(void)
{
}
////////////////////////////////////////////////////////////
Cell Cell::operator =(const Cell & right)
{
this->mCellType = right.mCellType;
return *this;
}
////////////////////////////////////////////////////////////
unsigned int Cell::GetDrawInfo(void) const
{
if (this->GetType() & CT_HasCame) { return CT_HasCame; }
if (this->GetType() & CT_Up) { return CT_Up; }
if (this->GetType() & CT_Down) { return CT_Down; }
if (this->GetType() & CT_Left) { return CT_Left; }
if (this->GetType() & CT_Right) { return CT_Right; }
if (this->GetType() & CT_Trap) { return CT_Trap; }
if (this->GetType() & CT_Gold) { return CT_Gold; }
if (this->GetType() & CT_Wumpus) { return CT_Wumpus; }
return CT_None;
}
////////////////////////////////////////////////////////////
unsigned int Cell::GetX(void) const
{
ASSERT(m_pMap && m_pMap->_su_GetCells().size());
const Cell * base = &m_pMap->_su_GetCells()[0];
return (this - base) / m_pMap->GetYBorder();
}
////////////////////////////////////////////////////////////
unsigned int Cell::GetY(void) const
{
ASSERT(m_pMap && m_pMap->_su_GetCells().size());
const Cell * base = &m_pMap->_su_GetCells()[0];
return this - base - GetX() * m_pMap->GetYBorder();
}
////////////////////////////////////////////////////////////
unsigned int Cell::GetType(void) const
{
return mCellType;
}
////////////////////////////////////////////////////////////
void Cell::_su_AddType(unsigned int cell_type)
{
mCellType |= cell_type;
}
////////////////////////////////////////////////////////////
void Cell::_su_SetType(unsigned int cell_type)
{
mCellType = cell_type;
}
////////////////////////////////////////////////////////////
void Cell::_su_DeleteType(unsigned int cell_type)
{
mCellType &= ~cell_type;
}
////////////////////////////////////////////////////////////
void Cell::_su_SetCellUp(Cell *pcell)
{
m_pCellUp = pcell;
}
////////////////////////////////////////////////////////////
void Cell::_su_SetCellDown(Cell *pcell)
{
m_pCellDown = pcell;
}
////////////////////////////////////////////////////////////
void Cell::_su_SetCellLeft(Cell *pcell)
{
m_pCellLeft = pcell;
}
////////////////////////////////////////////////////////////
void Cell::_su_SetCellRight(Cell *pcell)
{
m_pCellRight = pcell;
}
////////////////////////////////////////////////////////////
Cell * Cell::CellUp() const
{
return m_pCellUp;
}
////////////////////////////////////////////////////////////
Cell * Cell::CellDown() const
{
return m_pCellDown;
}
////////////////////////////////////////////////////////////
Cell * Cell::CellLeft() const
{
return m_pCellLeft;
}
////////////////////////////////////////////////////////////
Cell * Cell::CellRight() const
{
return m_pCellRight;
}
////////////////////////////////////////////////////////////
const Cell * Cell::CellUp_const() const
{
return m_pCellUp;
}
////////////////////////////////////////////////////////////
const Cell * Cell::CellDown_const() const
{
return m_pCellDown;
}
////////////////////////////////////////////////////////////
const Cell * Cell::CellLeft_const() const
{
return m_pCellLeft;
}
////////////////////////////////////////////////////////////
const Cell * Cell::CellRight_const() const
{
return m_pCellRight;
}
////////////////////////////////////////////////////////////
bool Cell::IsWumpusAround(void) const
{
if (m_pCellUp &&
m_pCellUp->mCellType & CT_Wumpus)
{
return true;
}
if (m_pCellDown &&
m_pCellDown->mCellType & CT_Wumpus)
{
return true;
}
if (m_pCellLeft &&
m_pCellLeft->mCellType & CT_Wumpus)
{
return true;
}
if (m_pCellRight &&
m_pCellRight->mCellType & CT_Wumpus)
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////
bool Cell::IsTrapAround(void) const
{
if (m_pCellUp &&
m_pCellUp->mCellType & CT_Trap)
{
return true;
}
if (m_pCellDown &&
m_pCellDown->mCellType & CT_Trap)
{
return true;
}
if (m_pCellLeft &&
m_pCellLeft->mCellType & CT_Trap)
{
return true;
}
if (m_pCellRight &&
m_pCellRight->mCellType & CT_Trap)
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////
bool Cell::IsGoldAround(void) const
{
if (m_pCellUp &&
m_pCellUp->mCellType & CT_Gold)
{
return true;
}
if (m_pCellDown &&
m_pCellDown->mCellType & CT_Gold)
{
return true;
}
if (m_pCellLeft &&
m_pCellLeft->mCellType & CT_Gold)
{
return true;
}
if (m_pCellRight &&
m_pCellRight->mCellType & CT_Gold)
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////
bool Cell::IsNear(unsigned int type) const
{
if (m_pCellUp &&
m_pCellUp->mCellType & type)
{
return true;
}
if (m_pCellDown &&
m_pCellDown->mCellType & type)
{
return true;
}
if (m_pCellLeft &&
m_pCellLeft->mCellType & type)
{
return true;
}
if (m_pCellRight &&
m_pCellRight->mCellType & type)
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////
bool Cell::IsHasCame() const
{
return (mCellType & CT_HasCame) != 0;
}
////////////////////////////////////////////////////////////
#ifdef CONSOLE
void Cell::Print() const
{
std::cout << '(';
if (mCellType == CT_None)
{
std::cout << 'N';
}
if (mCellType & CT_Wumpus)
{
std::cout << 'W';
}
if (mCellType & CT_Trap)
{
std::cout << 'T';
}
if (mCellType & CT_Gold)
{
std::cout << 'G';
}
if (mCellType & CT_Stench)
{
std::cout << 'S';
}
if (mCellType & CT_Breeze)
{
std::cout << 'B';
}
if (mCellType & CT_Gleam)
{
std::cout << 'G';
}
std::cout << ')';
}
#endif
/////////////////////////////////////////////////////
void Cell::_su_SetX(unsigned int x)
{
this->mPositionX = x;
}
/////////////////////////////////////////////////////
void Cell::_su_SetY(unsigned int y)
{
this->mPositionY = y;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -