-
-
Save explorer14/ec19d6caccd5416999e21c4cd900d8e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Rover | |
{ | |
private readonly Terrain terrain; | |
public Rover( | |
Terrain terrain, | |
int startingPositionX, | |
int startingPositionY, | |
Direction startingHeading) | |
{ | |
if (terrain == null) | |
throw new ArgumentNullException( | |
nameof(terrain), | |
"Rover cannot navigate on a non-existent terrain!"); | |
if (IsStartingPositionOutsideTerrain( | |
terrain, | |
startingPositionX, | |
startingPositionY)) | |
throw new ArgumentOutOfRangeException( | |
$"{nameof(startingPositionX)},{nameof(startingPositionY)}", | |
"Rover cannot start outside the terrain"); | |
if (!Enum.IsDefined(typeof(Direction), startingHeading)) | |
throw new ArgumentOutOfRangeException( | |
nameof(startingHeading), | |
"Starting heading is invalid, must be one of NORTH, EAST, WEST or SOUTH"); | |
this.terrain = terrain; | |
StartingPositionX = startingPositionX; | |
StartingPositionY = startingPositionY; | |
NewPositionX = StartingPositionX; | |
NewPositionY = StartingPositionY; | |
StartingHeading = startingHeading; | |
NewHeading = StartingHeading; | |
Id = Guid.NewGuid(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment