Пример #1
0
 /// <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;
     }
 }