refactor: renamed Model.cs to Score.cs
This commit is contained in:
parent
2be3b572fb
commit
5d470a57af
8 changed files with 48 additions and 48 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
29
Assets/Scripts/Domain/Score.cs
Normal file
29
Assets/Scripts/Domain/Score.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,21 +2,21 @@
|
||||||
|
|
||||||
namespace Presenter {
|
namespace Presenter {
|
||||||
public class ExpressionClick {
|
public class ExpressionClick {
|
||||||
private readonly Model _model;
|
private readonly Score _score;
|
||||||
private readonly IExpressionInput _view;
|
private readonly IExpressionInput _view;
|
||||||
private readonly IRoseSpawner _spawner;
|
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) {
|
public ExpressionClick(Score score, IExpressionInput view, IRoseSpawner spawner) {
|
||||||
_model = model;
|
_score = score;
|
||||||
_view = view;
|
_view = view;
|
||||||
_spawner = spawner;
|
_spawner = spawner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute() {
|
public void Execute() {
|
||||||
_model.AddScore();
|
_score.Add();
|
||||||
_view.UpdateView(_model.Score);
|
_view.UpdateView(_score.Value);
|
||||||
|
|
||||||
if (CanSpawn)
|
if (CanSpawn)
|
||||||
_spawner.SpawnRose();
|
_spawner.SpawnRose();
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
public class ModelTests {
|
public class ScoreTests {
|
||||||
[Test]
|
[Test]
|
||||||
public void OneIteration_UpdatesGrowPercentage() {
|
public void OneIteration_UpdatesGrowPercentage() {
|
||||||
Model sut = new(5, 5);
|
Score sut = new(5, 5);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
sut.AddScore();
|
sut.Add();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.AreEqual(1f / 5f, sut.GrowPercentage);
|
Assert.AreEqual(1f / 5f, sut.GrowPercentage);
|
||||||
|
@ -16,10 +16,10 @@ namespace Tests {
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AllIterations_GrowCompleted() {
|
public void AllIterations_GrowCompleted() {
|
||||||
Model sut = new(5, 5);
|
Score sut = new(5, 5);
|
||||||
|
|
||||||
for (int i = 0; i < 5 * 5; i++) {
|
for (int i = 0; i < 5 * 5; i++) {
|
||||||
sut.AddScore();
|
sut.Add();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.AreEqual(1f, sut.GrowPercentage);
|
Assert.AreEqual(1f, sut.GrowPercentage);
|
||||||
|
@ -27,10 +27,10 @@ namespace Tests {
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void MoreIterations_ResetsGrowPercentage() {
|
public void MoreIterations_ResetsGrowPercentage() {
|
||||||
Model sut = new(5, 5);
|
Score sut = new(5, 5);
|
||||||
|
|
||||||
for (int i = 0; i < 6 * 5; i++) {
|
for (int i = 0; i < 6 * 5; i++) {
|
||||||
sut.AddScore();
|
sut.Add();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.AreEqual(1f / 5f, sut.GrowPercentage);
|
Assert.AreEqual(1f / 5f, sut.GrowPercentage);
|
|
@ -7,11 +7,11 @@ using View.UI;
|
||||||
namespace View {
|
namespace View {
|
||||||
public class Dependencies : MonoBehaviour {
|
public class Dependencies : MonoBehaviour {
|
||||||
public ExpressionClick ExpressionClick { private set; get; }
|
public ExpressionClick ExpressionClick { private set; get; }
|
||||||
public Model Model { private set; get; }
|
public Score Score { private set; get; }
|
||||||
public CustomInput CustomInput { private set; get; }
|
public CustomInput CustomInput { private set; get; }
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
Model = new Model(20, 5);
|
Score = new Score(20, 5);
|
||||||
|
|
||||||
IExpressionInput input = FindObjectOfType<ExpressionInput>();
|
IExpressionInput input = FindObjectOfType<ExpressionInput>();
|
||||||
IExpressionInput visibility = FindObjectOfType<UIVisibility>();
|
IExpressionInput visibility = FindObjectOfType<UIVisibility>();
|
||||||
|
@ -19,7 +19,7 @@ namespace View {
|
||||||
|
|
||||||
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
|
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
|
||||||
|
|
||||||
ExpressionClick = new ExpressionClick(Model, inputCollections, spawner);
|
ExpressionClick = new ExpressionClick(Score, inputCollections, spawner);
|
||||||
|
|
||||||
CustomInput = new CustomInput();
|
CustomInput = new CustomInput();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,12 @@ namespace View.UI {
|
||||||
|
|
||||||
private ExpressionClick _click;
|
private ExpressionClick _click;
|
||||||
private CustomInput _customInput;
|
private CustomInput _customInput;
|
||||||
private Model _model;
|
private Score _score;
|
||||||
|
|
||||||
[SerializeField] private FramedAnimator.FramedAnimator animator;
|
[SerializeField] private FramedAnimator.FramedAnimator animator;
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
_model = FindObjectOfType<Dependencies>().Model;
|
_score = FindObjectOfType<Dependencies>().Score;
|
||||||
|
|
||||||
_click = FindObjectOfType<Dependencies>().ExpressionClick;
|
_click = FindObjectOfType<Dependencies>().ExpressionClick;
|
||||||
_customInput = FindObjectOfType<Dependencies>().CustomInput;
|
_customInput = FindObjectOfType<Dependencies>().CustomInput;
|
||||||
|
@ -27,7 +27,7 @@ namespace View.UI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateView(int score) {
|
public void UpdateView(int score) {
|
||||||
animator.PlayUntil(_model.GrowPercentage);
|
animator.PlayUntil(_score.GrowPercentage);
|
||||||
text.text = score.ToString();
|
text.text = score.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue