src/NasaRover.Domain/Business/Terrain/TerrainEntity.cs
/// <summary>
/// Method used to walk in a terrain.
/// I decided to put this method here because a terrain could have other shapes.
/// </summary>
Method used to walk in a terrain.
I decided to put this method here because a terrain could have other shapes.
Method used to walk in a terrain . I decided to put this method here because a terrain could have other shapes .
public (Location location, int moves, string message) Walk(Location location, Direction direction)
    {
        if(location.X < 0 || location.X > Width)
            return (location, 0, "Out of bounds");
        if(location.Y < 0 || location.Y > Height)
            return (location, 0, "Out of bounds");
        var newLocation = new Location(location.X, location.Y);
        switch (direction)
        {
            case Direction.North:
                newLocation.Y = location.Y == Height ? 0 : location.Y + 1;
                break;
            case Direction.South:
                newLocation.Y = location.Y == 0 ? Height : location.Y - 1;
                break;
            case Direction.East:
                newLocation.X = location.X == Width ? 0 : location.X + 1;
                break;
            case Direction.West:
                newLocation.X = location.X == 0 ? Width : location.X - 1;
                break;
        }
        if (Obstacles.Any(o => o.X == newLocation.X && o.Y == newLocation.Y))
            return (location, 0, "We could not move, there is an obstacle");
        return (newLocation, 1, "Congratulations, we could move without any problems");
    }
public ( Location location , int moves , string message ) Walk ( Location location , Direction direction ) { if ( location . X < 0 || location . X > Width ) return ( location , 0 , " " ) ; if ( location . Y < 0 || location . Y > Height ) return ( location , 0 , " " ) ; var newLocation = new Location ( location . X , location . Y ) ; switch ( direction ) { case Direction . North : newLocation . Y = location . Y == Height ? 0 : location . Y + 1 ; break ; case Direction . South : newLocation . Y = location . Y == 0 ? Height : location . Y - 1 ; break ; case Direction . East : newLocation . X = location . X == Width ? 0 : location . X + 1 ; break ; case Direction . West : newLocation . X = location . X == 0 ? Width : location . X - 1 ; break ; } if ( Obstacles . Any ( o => o . X == newLocation . X && o . Y == newLocation . Y ) ) return ( location , 0 , " " ) ; return ( newLocation , 1 , " " ) ; }
Method used to walk in a terrain.
Method used to walk in a terrain .
location
Location
direction
Direction