refactor: renamed Model.cs to Score.cs

This commit is contained in:
Gerard Gascón 2024-04-17 00:05:36 +02:00
parent 2be3b572fb
commit 5d470a57af
8 changed files with 48 additions and 48 deletions

View file

@ -1,29 +0,0 @@
namespace Domain {
public class Model {
public int Score { private set; get; }
public readonly int SpawnRate;
public readonly int GrowIterations;
public float GrowPercentage { private set; get; }
public Model(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }
public Model(int score, int spawnRate, int growIterations) {
Score = score;
SpawnRate = spawnRate;
GrowIterations = growIterations;
}
public void AddScore() {
Score++;
if (Score % GrowIterations == 0) {
float relativeScore = Score % (GrowIterations * SpawnRate);
if (relativeScore == 0 && Score != 0)
relativeScore = GrowIterations * SpawnRate;
GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
}
}
}
}

View file

@ -0,0 +1,29 @@
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 Add() {
Value++;
if (Value % GrowIterations == 0) {
float relativeScore = Value % (GrowIterations * SpawnRate);
if (relativeScore == 0 && Value != 0)
relativeScore = GrowIterations * SpawnRate;
GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
}
}
}
}

View file

@ -2,21 +2,21 @@
namespace Presenter {
public class ExpressionClick {
private readonly Model _model;
private readonly Score _score;
private readonly IExpressionInput _view;
private readonly IRoseSpawner _spawner;
private bool CanSpawn => _model.Score % (_model.GrowIterations * _model.SpawnRate) == 0;
private bool CanSpawn => _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;
public ExpressionClick(Model model, IExpressionInput view, IRoseSpawner spawner) {
_model = model;
public ExpressionClick(Score score, IExpressionInput view, IRoseSpawner spawner) {
_score = score;
_view = view;
_spawner = spawner;
}
public void Execute() {
_model.AddScore();
_view.UpdateView(_model.Score);
_score.Add();
_view.UpdateView(_score.Value);
if (CanSpawn)
_spawner.SpawnRose();

View file

@ -2,13 +2,13 @@
using NUnit.Framework;
namespace Tests {
public class ModelTests {
public class ScoreTests {
[Test]
public void OneIteration_UpdatesGrowPercentage() {
Model sut = new(5, 5);
Score sut = new(5, 5);
for (int i = 0; i < 5; i++) {
sut.AddScore();
sut.Add();
}
Assert.AreEqual(1f / 5f, sut.GrowPercentage);
@ -16,10 +16,10 @@ namespace Tests {
[Test]
public void AllIterations_GrowCompleted() {
Model sut = new(5, 5);
Score sut = new(5, 5);
for (int i = 0; i < 5 * 5; i++) {
sut.AddScore();
sut.Add();
}
Assert.AreEqual(1f, sut.GrowPercentage);
@ -27,10 +27,10 @@ namespace Tests {
[Test]
public void MoreIterations_ResetsGrowPercentage() {
Model sut = new(5, 5);
Score sut = new(5, 5);
for (int i = 0; i < 6 * 5; i++) {
sut.AddScore();
sut.Add();
}
Assert.AreEqual(1f / 5f, sut.GrowPercentage);

View file

@ -7,11 +7,11 @@ using View.UI;
namespace View {
public class Dependencies : MonoBehaviour {
public ExpressionClick ExpressionClick { private set; get; }
public Model Model { private set; get; }
public Score Score { private set; get; }
public CustomInput CustomInput { private set; get; }
private void Awake() {
Model = new Model(20, 5);
Score = new Score(20, 5);
IExpressionInput input = FindObjectOfType<ExpressionInput>();
IExpressionInput visibility = FindObjectOfType<UIVisibility>();
@ -19,7 +19,7 @@ namespace View {
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
ExpressionClick = new ExpressionClick(Model, inputCollections, spawner);
ExpressionClick = new ExpressionClick(Score, inputCollections, spawner);
CustomInput = new CustomInput();
}

View file

@ -11,12 +11,12 @@ namespace View.UI {
private ExpressionClick _click;
private CustomInput _customInput;
private Model _model;
private Score _score;
[SerializeField] private FramedAnimator.FramedAnimator animator;
private void Start() {
_model = FindObjectOfType<Dependencies>().Model;
_score = FindObjectOfType<Dependencies>().Score;
_click = FindObjectOfType<Dependencies>().ExpressionClick;
_customInput = FindObjectOfType<Dependencies>().CustomInput;
@ -27,7 +27,7 @@ namespace View.UI {
}
public void UpdateView(int score) {
animator.PlayUntil(_model.GrowPercentage);
animator.PlayUntil(_score.GrowPercentage);
text.text = score.ToString();
}