📄 explorer.cpp
字号:
#include "Explorer.h"
#include "WorldModel.h"
#include "ServerMap.h"
#include "GameEngine.h"
#include <Wum_Base/src/Cell.h>
using namespace _server;
////////////////////////////////////////////////////
Explorer::Explorer(WorldModel &spwm)
{
this->mpWorldModel = &spwm;
this->mDirection = ED_Up;
this->mPositionX = 0;
this->mPositionY = 0;
this->mShootsLeft = 1;
this->TheWorldModel().TheServerMap().TheCell(this->mPositionX, this->mPositionY)._su_AddType(_base::Cell::CT_HasCame);
}
////////////////////////////////////////////////////
Explorer::Explorer(const _server::Explorer &from)
{
}
////////////////////////////////////////////////////
Explorer::~Explorer(void)
{
}
////////////////////////////////////////////////////
unsigned int Explorer::GetX(void) const
{
return mPositionX;
}
////////////////////////////////////////////////////
unsigned int Explorer::GetY(void) const
{
return mPositionY;
}
////////////////////////////////////////////////////
unsigned int Explorer::GetDirection(void) const
{
return mDirection;
}
////////////////////////////////////////////////////
bool Explorer::Escape(void)
{
this->TheWorldModel()._su_IsBump() = false;
if (this->mPositionX == 0 &&
this->mPositionY == 0)
{
this->TheWorldModel().TheServerMap().Reset();
this->Reset();
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
this->TheWorldModel()._su_IsNewlyCreated() = true;
return true;
}
this->TheWorldModel()._su_IsBump() = true;
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
return false;
}
////////////////////////////////////////////////////
void Explorer::Reset(void)
{
this->mPositionX = 0;
this->mPositionY = 0;
this->mDirection = ED_Up;
this->mShootsLeft = 1;
this->TheWorldModel().TheServerMap().TheCell(this->mPositionX, this->mPositionY)._su_AddType(_base::Cell::CT_HasCame);
}
////////////////////////////////////////////////////
bool Explorer::GoAhead(void)
{
int new_x = this->mPositionX;
int new_y = this->mPositionY;
switch (this->mDirection)
{
case ED_Up:
new_y += 1;
break;
case ED_Down:
new_y -= 1;
break;
case ED_Left:
new_x -=1;
break;
case ED_Right:
new_x += 1;
break;
default:
break;
}
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
if (this->TheWorldModel().TheServerMap().IsInMap(new_x, new_y))
{
this->mPositionX = (unsigned int) new_x;
this->mPositionY = (unsigned int) new_y;
this->TheWorldModel().TheServerMap().TheCell(this->mPositionX, this->mPositionY)._su_AddType(_base::Cell::CT_HasCame);
this->TheWorldModel().Update();
return true;
}
this->TheWorldModel().TheServerMap().TheCell(this->mPositionX, this->mPositionY)._su_AddType(_base::Cell::CT_HasCame);
return false;
}
////////////////////////////////////////////////////
unsigned int Explorer::GetShootsLeft(void) const
{
return mShootsLeft;
}
////////////////////////////////////////////////////
WorldModel &Explorer::TheWorldModel(void)
{
return *mpWorldModel;
}
////////////////////////////////////////////////////
const WorldModel &Explorer::GetWorldModel(void) const
{
return *mpWorldModel;
}
////////////////////////////////////////////////////
bool Explorer::Shoot(void)
{
this->TheWorldModel()._su_IsHawl() = false;
unsigned int x = this->GetX();
unsigned int y = this->GetY();
int diff_x = 0;
int diff_y = 0;
switch (this->GetDirection())
{
case ED_Up:
diff_y = 1;
break;
case ED_Down:
diff_y = -1;
break;
case ED_Left:
diff_x = -1;
break;
case ED_Right:
diff_x = 1;
break;
}
x += diff_x; y += diff_y;
while (this->TheWorldModel().TheServerMap().IsInMap(x,y))
{
if (this->TheWorldModel().TheServerMap().TheCell(x,y).GetType() & _base::Cell::CT_Wumpus)
{
this->TheWorldModel()._su_IsHawl() = true;
}
this->TheWorldModel().TheServerMap().TheCell(x,y)._su_DeleteType(_base::Cell::CT_Wumpus);
x += diff_x; y += diff_y;
}
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
return false;
}
////////////////////////////////////////////////////
bool Explorer::TurnLeft(void)
{
switch (mDirection)
{
case ED_Up:
mDirection = ED_Left;
break;
case ED_Down:
mDirection = ED_Right;
break;
case ED_Left:
mDirection = ED_Down;
break;
case ED_Right:
mDirection = ED_Up;
break;
default:
break;
}
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
return true;
}
////////////////////////////////////////////////////
bool Explorer::TurnRight(void)
{
switch (mDirection)
{
case ED_Up:
mDirection = ED_Right;
break;
case ED_Down:
mDirection = ED_Left;
break;
case ED_Left:
mDirection = ED_Up;
break;
case ED_Right:
mDirection = ED_Down;
break;
default:
break;
}
this->TheWorldModel().TheGameEngine()._su_TheScore()--;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -