只是一个快速的人-你知道,当你的大脑痛,只是看看什么。只是看看是否有一种“更好”的方法来做到这一点的布尔逻辑。
private RegenerationType AccquireRegenerationState (int floor, int playerFloor)
{
bool entranceExists = (floorBlocks[floor].doorBlocks.Count != 0) ? true : false;
if (floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited)
{
if (entranceExists)
{
return RegenerationType.Still;
}
else
{
return RegenerationType.Limit;
}
}
else
{
if (entranceExists)
{
return RegenerationType.Prime;
}
else
{
return RegenerationType.Full;
}
}
}发布于 2016-06-18 14:18:20
我想这是你能做到的最好的了。当然,假设您保持代码的可读性和清晰性:
private RegenerationType AccquireRegenerationState (int floor, int playerFloor)
{
var entranceExists = floorBlocks[floor].doorBlocks.Count != 0;
var whatever = floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited;
if (whatever)
{
return entranceExists ? RegenerationType.Still : RegenerationType.Limit;
}
else
{
return entranceExists ? RegenerationType.Prime : RegenerationType.Full;
}
}发布于 2016-06-18 14:21:55
bool entranceExists = (floorBlocks[floor].doorBlocks.Count != 0);
return
(floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited)?
(entranceExists? RegenerationType.Still: RegenerationType.Limit):
(entranceExists? RegenerationType.Prime: RegenerationType.Full); https://stackoverflow.com/questions/37897904
复制相似问题