Skip to content

Instantly share code, notes, and snippets.

@explorer14

explorer14/RoverInit.cs Secret

Created Jun 22, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.