internal void Move(TrainPosition position) { switch (this.Direction) { case TrackDirection.Horizontal: TrainMovement.MoveHorizontal(position); break; case TrackDirection.Vertical: TrainMovement.MoveVertical(position); break; case TrackDirection.LeftUp: TrainMovement.MoveLeftUp(position); break; case TrackDirection.RightUp: TrainMovement.MoveRightUp(position); break; case TrackDirection.RightDown: TrainMovement.MoveRightDown(position); break; case TrackDirection.LeftDown: TrainMovement.MoveLeftDown(position); break; case TrackDirection.RightUp_RightDown: MoveRightUpDown(position); break; case TrackDirection.RightDown_LeftDown: MoveLeftRightDown(position); break; case TrackDirection.LeftDown_LeftUp: MoveLeftUpDown(position); break; case TrackDirection.LeftUp_RightUp: MoveLeftRightUp(position); break; case TrackDirection.Cross: MoveCross(position); break; default: throw new InvalidOperationException("I don't know what that track is!"); } }
private void MoveRightUpDown(TrainPosition position) { // Right -> Up, Enters 180, Leaves 270 // Up -> Right, Enters 90, Leaves 0 // Down -> Right, Enters 270, Leaves 0 if (position.RelativeTop < 0.4f) { TrainMovement.MoveRightUp(position); } else if (position.RelativeTop > 0.6f) { TrainMovement.MoveRightDown(position); } else if (position.Angle >= 270.0) { TrainMovement.MoveRightDown(position); } else { if (this.AlternateState) { TrainMovement.MoveRightDown(position); } else { TrainMovement.MoveRightUp(position); } } }
private void MoveLeftRightUp(TrainPosition position) { if (position.RelativeLeft < 0.4f) { TrainMovement.MoveLeftUp(position); } else if (position.RelativeLeft > 0.6f) { TrainMovement.MoveRightUp(position); } else if (TrainMovement.BetweenAngles(position.Angle, 179, 271)) { TrainMovement.MoveRightUp(position); } else { if (this.AlternateState) { TrainMovement.MoveRightUp(position); } else { TrainMovement.MoveLeftUp(position); } } }
private static void MoveLeftRightUp(TrainPosition position) { if (TrainMovement.BetweenAngles(position.Angle, 179, 271)) { TrainMovement.MoveRightUp(position); } else { TrainMovement.MoveLeftUp(position); } }
private static void MoveRightUpDown(TrainPosition position) { if ((position.Angle >= 180 && position.Angle <= 90.0) || (position.Angle >= 270 && position.Angle <= 360)) { TrainMovement.MoveRightDown(position); } else { TrainMovement.MoveRightUp(position); } }