예제 #1
0
 public void TurnRight()
 {
     currentDirection = currentDirection.MinusRadians(radianRotation);
 }
예제 #2
0
        private void MoveRover(Vector futurePosition)
        {
            var nextPosition = WrapAroundAxisIfNeeded(futurePosition);

            if (NextPositionIsBlockedByObstacle(nextPosition))
            {
                IsObstructed = true;
                Obstruction = nextPosition;
            }
            else
            {
                currentPoint = nextPosition;
            }
        }
예제 #3
0
 public void MoveForward()
 {
     var futurePosition = new Vector(currentPoint.X, currentPoint.Y);
     futurePosition += currentDirection;
     MoveRover(futurePosition);
 }
예제 #4
0
 public void TurnLeft()
 {
     currentDirection = currentDirection.PlusRadians(radianRotation);
 }
예제 #5
0
 public Rover(Point point, Char direction, Planet planet)
 {
     currentPoint = new Vector(point.X, point.Y);
     currentDirection = InitializeDirection(direction);
     this.planet = planet;
 }
예제 #6
0
        private Vector WrapAroundAxisIfNeeded(Vector futurePoint)
        {
            if (futurePoint.X > planet.PositiveBorder)
                futurePoint.X = planet.NegativeBorder;
            else if (futurePoint.X < planet.NegativeBorder)
                futurePoint.X = planet.PositiveBorder;

            if (futurePoint.Y > planet.PositiveBorder)
                futurePoint.Y = planet.NegativeBorder;
            else if (futurePoint.Y < planet.NegativeBorder)
                futurePoint.Y = planet.PositiveBorder;

            return futurePoint;
        }
예제 #7
0
 private Boolean NextPositionIsBlockedByObstacle(Vector nextPosition)
 {
     return planet.Obstacles.Any(o => o.X == nextPosition.X && o.Y == nextPosition.Y);
 }
예제 #8
0
 private Boolean Equals(Vector other)
 {
     return this.X == other.X && this.Y == other.Y;
 }
예제 #9
0
 private Vector CreateAndNormalizeVectorFor(double result)
 {
     var diffVector = new Vector((Int32)Math.Cos(result), (Int32)Math.Sin(result));
     diffVector.Normalize();
     return diffVector;
 }