1 Star 0 Fork 0

Mrack/ MyShapez

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Cutter.cpp 3.78 KB
一键复制 编辑 原始数据 按行查看 历史
Mrack 提交于 2024-06-25 13:02 . 5555555
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stucky/MyShapez-new.git
[email protected]:stucky/MyShapez-new.git
stucky
MyShapez-new
MyShapez
master

搜索帮助