コード例 #1
0
        public void Move(IRover rover, int places)
        {
            switch (rover.Direction)
            {
            case Direction.North:
                rover.Direction = Direction.East;
                rover.MoveEast(places);
                break;

            case Direction.East:
                rover.Direction = Direction.South;
                rover.MoveSouth(places);
                break;

            case Direction.South:
                rover.Direction = Direction.West;
                rover.MoveWest(places);
                break;

            case Direction.West:
                rover.Direction = Direction.North;
                rover.MoveNorth(places);
                break;
            }
        }
コード例 #2
0
ファイル: Facing.cs プロジェクト: masudio/MarsRover
 public override void Execute(IRover rover, Instruction instruction)
 {
     switch(instruction.GetInstruction())
     {
         case Instruction.TurnLeft:
             rover.SetFacing(West);
             break;
         case Instruction.TurnRight:
             rover.SetFacing(East);
             break;
         case Instruction.MoveForward:
             rover.MoveNorth();
             break;
         default:
             throw new ArgumentException("Incorrect facing code.");
     }
 }