/* When inserting a Rover in the Plateau you need to insert the Position to avoid the Rover to * start in a invalid position in the Plateau. * Because of that I did not a overload method where you only insert the rover without the Position. */ public void InsertRover(IRover rover, Position roverPosition) { if (IsValidPosition(roverPosition)) rover.Position = roverPosition; else throw new Exception("Invalid coordinates."); Rovers.Add(rover); }
/* It is the responsibility of the Rover to manipulate your own direction and localization. */ public void MoveForward() { switch (Position.Orientation) { case Orientation.North: Position = Position.IncreaseOneMoreInPositionY(); break; case Orientation.East: Position = Position.IncreaseOneMoreInPositionX(); break; case Orientation.South: Position = Position.DecreaseOneMoreInPositionY(); break; case Orientation.West: Position = Position.DecreaseOneMoreInPositionX(); break; } }
public bool IsValidPosition(Position position) { return !(position.PositionX > LengthX || position.PositionY > LengthY); }
public void Spin90DegreesRight() { Position = Position.Spin90DegreesRight(); }
public void Spin90DegreesLeft() { Position = Position.Spin90DegreesLeft(); }
/* Constructor with Position parameter to allow more flexibility. */ public Rover(Position position) { Position = position; }