代码拉取完成,页面将自动刷新
#include "Cutter.h"
#include "GameMap.h"
#include <QDebug>
Cutter::Cutter(GridVec pos, int name, int direction)
: Building(pos, name, direction)
{
FirstRequire_ms = 2700;
SecondRequire_ms = 1800;
}
std::vector<GridVec> Cutter::BuildingAllPos()
{
std::vector<GridVec> allpos;
allpos.push_back(pos);
GridVec temps[] = {GridVec{pos.j + 1, pos.i},
GridVec{pos.j - 1, pos.i},
GridVec{pos.j, pos.i - 1},
GridVec{pos.j, pos.i + 1},
};
allpos.push_back(temps[direction]);
return allpos;
}
bool Cutter::IsPlace(const GridVec &click, int picdirection, GameMap &gamemap)
{
for (auto pos : BuildingAllPos())
{
// 如果超出地图范围,返回false
if (pos.i < 0 || pos.i >= GameInfo::HEIGHT || pos.j < 0 || pos.j >= GameInfo::WIDTH)
{
return false;
}
// 如果在矿地上,或有障碍物,返回false
if (gamemap.GetResource(pos))
{
return false;
}
// 如果点击的是hub,返回false
if (gamemap.GetBuilding(pos))
{
if (gamemap.GetBuilding(pos)->name == BuildingType::HUB || gamemap.GetBuilding(pos)->name == BuildingType::CUTTER || gamemap.GetBuilding(pos)->name == BuildingType::TRASH)
{
return false;
}
}
}
return true;
}
bool Cutter::CanReceive(GridVec target, int directionin, int shapename)
{
if (state == TickableStatus::EMPTY)
{
if (directionin == direction)
{
if (shapename == Goods::CYCLE)
{
return true;
}
}
}
return false;
}
void Cutter::Receive(GridVec target, int directionin, int shapename)
{
shape.name = shapename;
state = TickableStatus::RUNNING;
timer.Reset();
}
void Cutter::TickableRunning()
{
timer.UpdateRuningTime(FirstRequire_ms);
running_ms = timer.runningMs;
return;
}
void Cutter::UpdateTickableState(GameMap &gamemap)
{
switch (state)
{
case TickableStatus::EMPTY:
running_ms = 0;
break;
case TickableStatus::RUNNING:
if (running_ms >= FirstRequire_ms)
{
// cutter好了,准备运输
state = TickableStatus::BLOCK;
running_ms = 0;
}
else
{
TickableRunning();
}
break;
case TickableStatus::BLOCK:
switch (direction)
{
case UP:
case RIGHT:
if (CanSend(BuildingAllPos()[0], direction, Goods::LEFT_CYCLE, gamemap) && CanSend(BuildingAllPos()[1], direction, Goods::RIGHT_CYCLE, gamemap))
{
Send(BuildingAllPos()[0], direction, Goods::LEFT_CYCLE, gamemap);
Send(BuildingAllPos()[1], direction, Goods::RIGHT_CYCLE, gamemap);
state = TickableStatus::EMPTY;
shape.name = NONE;
}
break;
case DOWN:
case LEFT:
if (CanSend(BuildingAllPos()[0], direction, Goods::RIGHT_CYCLE, gamemap) && CanSend(BuildingAllPos()[1], direction, Goods::LEFT_CYCLE, gamemap))
{
Send(BuildingAllPos()[0], direction, Goods::RIGHT_CYCLE, gamemap);
Send(BuildingAllPos()[1], direction, Goods::LEFT_CYCLE, gamemap);
state = TickableStatus::EMPTY;
shape.name = NONE;
}
break;
default:
break;
}
default:
break;
}
return;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。