/// <summary> /// Snaps provided coordinates to allowed value. /// </summary> /// <returns>Coordinates with correct values</returns> public static (int X, int Y) SnapToGrid(int X, int Y) { if (AllowedX.Contains(X) && AllowedY.Contains(Y)) { return(X, Y); } if ((((Y - 17) / 7.0) % 1) != 0.0) { Y = ((int)Math.Round((Y - 17) / 7.0) * 7) + 17; } if (Y < 17) { Y = 17; } if (Y > 598) { Y = 598; } if ((((X - 17) / 7.0) % 1) != 0.0) { X = ((int)Math.Round((X - 17) / 7.0) * 7) + 17; } if (X < 17) { X = 17; } if (X > 430) { X = 430; } return(X, Y); }
public Location(int X, int Y) { double test = (Y - 17) / 7.0; if (((test % 1 == 0) && test > -1 && test < 84) || AllowedY.Contains(Y)) { this.Y = Y; } else { throw new ArgumentOutOfRangeException("Y must have allowed value"); } test = (X - 17) / 7.0; if (((test % 1 == 0) && test > -1 && test < 60) || AllowedX.Contains(X)) { this.X = X; } else { throw new ArgumentOutOfRangeException("X must have allowed value"); } }