Ejemplo n.º 1
0
 public void TurnRight()
 {
     currentDirection = currentDirection.MinusRadians(radianRotation);
 }
Ejemplo n.º 2
0
        private void MoveRover(Vector futurePosition)
        {
            var nextPosition = WrapAroundAxisIfNeeded(futurePosition);

            if (NextPositionIsBlockedByObstacle(nextPosition))
            {
                IsObstructed = true;
                Obstruction = nextPosition;
            }
            else
            {
                currentPoint = nextPosition;
            }
        }
Ejemplo n.º 3
0
 public void MoveForward()
 {
     var futurePosition = new Vector(currentPoint.X, currentPoint.Y);
     futurePosition += currentDirection;
     MoveRover(futurePosition);
 }
Ejemplo n.º 4
0
 public void TurnLeft()
 {
     currentDirection = currentDirection.PlusRadians(radianRotation);
 }
Ejemplo n.º 5
0
 public Rover(Point point, Char direction, Planet planet)
 {
     currentPoint = new Vector(point.X, point.Y);
     currentDirection = InitializeDirection(direction);
     this.planet = planet;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 7
0
 private Boolean NextPositionIsBlockedByObstacle(Vector nextPosition)
 {
     return planet.Obstacles.Any(o => o.X == nextPosition.X && o.Y == nextPosition.Y);
 }
Ejemplo n.º 8
0
 private Boolean Equals(Vector other)
 {
     return this.X == other.X && this.Y == other.Y;
 }
Ejemplo n.º 9
0
 private Vector CreateAndNormalizeVectorFor(double result)
 {
     var diffVector = new Vector((Int32)Math.Cos(result), (Int32)Math.Sin(result));
     diffVector.Normalize();
     return diffVector;
 }