本文整理汇总了C#中Robot.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Robot.Contains方法的具体用法?C# Robot.Contains怎么用?C# Robot.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robot
的用法示例。
在下文中一共展示了Robot.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: canMoveOnConveyor
/// <summary>
/// Helper method for conveyor movement. Checks to see if a robot on a conveyor is able to move
/// </summary>
/// <param name="moving">The robot that is moving</param>
/// <param name="onCoveyors">An array of all robots that are on conveyors</param>
/// <param name="movable">A reference to a list of robots on conveyors that are able to move</param>
/// <returns>True if the robot can move</returns>
private static bool canMoveOnConveyor(Robot moving, Robot[] onCoveyors, ref List<conveyorModel> movable)
{
// See if robot has already been cleared to move
if (movable.Any(m => m.bot == moving))
{
return true;
}
int[] destination;
// Get the conveyor space the robot is on
conveyor space = gameStatus.gameBoard.conveyors.FirstOrDefault(c => (c.location[0] == moving.x_pos && c.location[1] == moving.y_pos));
if (space == null)
{
space = gameStatus.gameBoard.expressConveyors.First(c => (c.location[0] == moving.x_pos && c.location[1] == moving.y_pos));
}
// Find the robot's destination
switch (space.exit)
{
case Robot.orientation.X:
destination = new int[] { moving.x_pos + 1, moving.y_pos };
break;
case Robot.orientation.Y:
destination = new int[] { moving.x_pos, moving.y_pos + 1 };
break;
case Robot.orientation.NEG_X:
destination = new int[] { moving.x_pos - 1, moving.y_pos };
break;
case Robot.orientation.NEG_Y:
destination = new int[] { moving.x_pos, moving.y_pos - 1 };
break;
// This default should never execute
default:
destination = new int[0];
break;
}
// See if there's a robot on the space the bot is trying to move to
Robot inWay = gameStatus.robots.FirstOrDefault(r => (r.x_pos == destination[0] && r.y_pos == destination[1] && !r.controllingPlayer.dead));
if (inWay != null)
{
// Check if the robot in the way is also on a conveyor
if (onCoveyors.Contains(inWay))
{
// Recursively check if the robot in the way is able to move
if (canMoveOnConveyor(inWay, onCoveyors, ref movable))
{
// The robot can move
movable.Add(
new conveyorModel
{
space = space,
destination = destination,
bot = moving
});
return true;
}
}
return false;
}
else
{
// No bot in the way, the robot can move
movable.Add(
new conveyorModel
{
space = space,
destination = destination,
bot = moving
});
return true;
}
}