This project is read-only.
1
Vote

SpeechBasics-WPF refactoring

description

At SpeechBasics-WPF one could get rid of two of the dictionaries defined in the code, by using a Direction enum with explicit degree values and adapting the LEFT and RIGHT recognition code accordingly
/// <summary>
/// Enumeration of directions in which turtle may be facing (using clock-wise degrees for values)
/// </summary>
private enum Direction
{
  Up = 0,
  Right = 90,
  Down = 180,
  Left = 270
}
...
      case "LEFT":
        leftSpan.Foreground = Brushes.DeepSkyBlue;
        leftSpan.FontWeight = FontWeights.Bold;
        curDirection = (Direction)(((int)curDirection + 270) % 360); //do not use - 90, do not want to end up with negative numbers (plus can't use Math.Abs on the result of the modulo operation, will end up with wrong number)
        turtleRotation.Angle = (int)curDirection;
        break;

      case "RIGHT":
        rightSpan.Foreground = Brushes.DeepSkyBlue;
        rightSpan.FontWeight = FontWeights.Bold;
        curDirection = (Direction)Math.Abs(((int)curDirection + 90) % 360);
        turtleRotation.Angle = (int)curDirection;
        break;

comments