public void RotateRight(int degrees)
        {
            var waypoint      = new Waypoint(UnitsNorth, UnitsEast, UnitsSouth, UnitsWest); // Because we are mutating this object, we need to preserve the original values.
            var newDirections = new List <string>();

            var allPropertiesWithValue = this.GetType().GetProperties().Where(p => (int)p.GetValue(this) > 0);

            foreach (PropertyInfo property in allPropertiesWithValue)
            {
                var    currentDirection = CardinalDirections.Points.FirstOrDefault(p => property.Name.Contains(p));
                string newDirection     = CardinalDirections.RotateRight(degrees, currentDirection);
                newDirections.Add(newDirection);
                this.GetType().GetProperties().FirstOrDefault(p => p.Name.Contains(newDirection))?.SetValue(this, property.GetValue(waypoint));
                if (!newDirections.Any(d => property.Name.Contains(d)))
                {
                    property.SetValue(this, 0);
                }
            }
        }
Exemple #2
0
 private void RotateLeft(int degrees)
 {
     Facing = CardinalDirections.RotateLeft(degrees, Facing);
 }