我有一个二维数组,它应该包含不断移动的对象。
class ZombieLand : public Singleton<ZombieLand>
{
DECLARE_SINGLETON(ZombieLand);
public:
MachineState world [19][19];
MachineState getWorld()
{
std::cout<<"World";
return world[19][19];
}
void setWorld(MachineState & state)
{
world [state.x][state.y] = state;
}
}
我尝试检查某个位置是否为 Null,但“NULL”字不起作用,0 也不起作用
switch (state.m_Facing)
{
case (MachineState::UP):
if(ZombieLand::get().world[state.x][state.y-1] != NULL )
{
state.m_occupied = true;
break;
}
我的问题是,如何检查我的世界数组的位置是否已经包含一个对象?先感谢您。
我的 MachineState 类
struct MachineState
{
template <typename MachineTraits>
friend class Machine;
enum Facing { UP, RIGHT, DOWN, LEFT};
MachineState()
: m_ProgramCounter(1)
, m_ActionsTaken(0)
, m_Facing(UP)
, m_Test(false)
, m_Memory(nullptr)
,x(0)
,y(0)
,point1(25, 10)
,point2(10, 40)
,point3(40, 40)
{ }
int m_ProgramCounter;
int m_ActionsTaken;
Facing m_Facing;
bool m_Test;
bool m_occupied;
int x;
int y;
Point point1;
Point point2;
Point point3;
int GetActionsPerTurn() const throw() { return m_ActionsPerTurn; }
int GetMaxMemory() const throw() {return m_MaxMemory; }
bool GetInfect() const throw() { return m_InfectOnAttack; }
void setPoint(Point p1, Point p2, Point p3)
{
point1=p1;
point2=p2;
point3=p3;
}
};