private void CalculateFinalScore(GameMetrics gameMetrics, MetricsTable metricsTable) { for (int i = 0; i < metricsTable.RangeMetricsInfos.Count; i++) { RangeMetricsInfo currentRangeMetricInfo = metricsTable.RangeMetricsInfos[i]; if (gameMetrics.GetWrongAnswers() <= currentRangeMetricInfo.MaxErrors && gameMetrics.GetLapsedSeconds() <= currentRangeMetricInfo.MaxTime) { Range range = (Range) (i); float deltaRange = (range.GetDelta() / (currentRangeMetricInfo.MaxErrors - currentRangeMetricInfo.MinErrors + 1)); float baseForErrorsQuantity = deltaRange * ( currentRangeMetricInfo.MaxErrors - gameMetrics.GetWrongAnswers()); float score = range.GetMinScore() + baseForErrorsQuantity; float bonusFromTime = 0; if (gameMetrics.GetLapsedSeconds() <= currentRangeMetricInfo.MaxTimeToBonus) { float secondsToSubtract = gameMetrics.GetLapsedSeconds() - metricsTable.FreeTime; bonusFromTime = deltaRange; if (secondsToSubtract > 0) { bonusFromTime -= secondsToSubtract*(deltaRange / currentRangeMetricInfo.MaxTimeToBonus); } } score += bonusFromTime; gameMetrics.SetScore(Mathf.RoundToInt(score)); gameMetrics.SetBonusTime(Mathf.RoundToInt(bonusFromTime)); gameMetrics.SetRange(range); return; } } gameMetrics.SetScore(500); gameMetrics.SetBonusTime(0); gameMetrics.SetRange(Range.Rookie); }