コード例 #1
0
ファイル: Robot.cs プロジェクト: alwaysthecritic/RobotsCSharp
 public void ExecuteCommand(string command, Grid grid)
 {
     switch (command) {
         case "L": Left(); break;
         case "R": Right(); break;
         case "M": Move(grid); break;
         default: throw new ArgumentOutOfRangeException("Unknown command: " + command);
     }
 }
コード例 #2
0
ファイル: Robot.cs プロジェクト: alwaysthecritic/RobotsCSharp
 // The robot will ignore a Move that would take it off the edge of the grid.
 private void Move(Grid grid)
 {
     int newX = X, newY = Y;
     switch (Facing) {
         case Direction.N: newY += 1; break;
         case Direction.S: newY -= 1; break;
         case Direction.E: newX += 1; break;
         case Direction.W: newX -= 1; break;
     }
     if (grid.IsInBounds(newX, newY)) {
         X = newX;
         Y = newY;
     }
 }