public void Apply(int rotationChange, int powerChange, MarsLanderEnvironment environment) { if (Status != LanderStatus.Flying) return; if (Situation.Fuel < Situation.Power + powerChange) powerChange = 0; if (Situation.Fuel < Situation.Power) powerChange = -1; Situation.Power += LimitPower(powerChange); Situation.Rotation += LimitRotation(rotationChange); Situation.Fuel -= Situation.Power; Situation.HorizontalSpeed += Trigonometry.GetHorizontalSpeedFraction(Situation.Rotation, ZeroDegreesDirection.Top) * Situation.Power; if (Situation.HorizontalSpeed > MarsLanderRules.MaxHorizontalSpeed) Situation.HorizontalSpeed = MarsLanderRules.MaxHorizontalSpeed; if (Situation.HorizontalSpeed < MarsLanderRules.MinHorizontalSpeed) Situation.HorizontalSpeed = MarsLanderRules.MinHorizontalSpeed; Situation.VerticalSpeed += Trigonometry.GetVerticalSpeedFraction(Situation.Rotation, ZeroDegreesDirection.Top) * Situation.Power - MarsLanderRules.Gravity; if (Situation.VerticalSpeed > MarsLanderRules.MaxVerticalSpeed) Situation.VerticalSpeed = MarsLanderRules.MaxVerticalSpeed; if (Situation.VerticalSpeed < MarsLanderRules.MinVerticalSpeed) Situation.VerticalSpeed = MarsLanderRules.MinVerticalSpeed; Situation.X += Situation.HorizontalSpeed; Situation.Y += Situation.VerticalSpeed; RoundValues(); Situations.Add(Situation.Clone()); Actions.Add($"{rotationChange} {powerChange}"); SetStatus(environment); }
public void GetHorizontalSpeed_ValidParameters_ReturnsValidSpeed(int angle, double result) { Assert.That(Trigonometry.GetHorizontalSpeedFraction(angle), Is.EqualTo(Math.Round(result, 3))); }