37 lines
No EOL
981 B
C#
37 lines
No EOL
981 B
C#
namespace Domain {
|
|
public class Score {
|
|
public int Value { private set; get; }
|
|
|
|
public readonly int SpawnRate;
|
|
public readonly int GrowIterations;
|
|
|
|
public float GrowPercentage { private set; get; }
|
|
|
|
public Score(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }
|
|
|
|
public Score(int value, int spawnRate, int growIterations) {
|
|
Value = value;
|
|
SpawnRate = spawnRate;
|
|
GrowIterations = growIterations;
|
|
}
|
|
|
|
public void SetFromOtherScore(Score other) {
|
|
Value = other.Value;
|
|
UpdateGrowPercentage();
|
|
}
|
|
|
|
public void Add() {
|
|
Value++;
|
|
UpdateGrowPercentage();
|
|
}
|
|
|
|
private void UpdateGrowPercentage() {
|
|
int value = Value % GrowIterations == 0 ? Value : Value / GrowIterations * GrowIterations;
|
|
|
|
float relativeScore = value % (GrowIterations * SpawnRate);
|
|
if (relativeScore == 0 && value != 0)
|
|
relativeScore = GrowIterations * SpawnRate;
|
|
GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
|
|
}
|
|
}
|
|
} |