Files
match3-unity/Assets/Scripts/Presenter/ScorePresenter.cs
2025-12-17 00:55:30 +08:00

29 lines
881 B
C#

using System;
using Services.Interfaces;
using Views;
namespace Presenter {
public class ScorePresenter : IDisposable{
private readonly IScoreService scoreService;
private readonly ScoreView scoreView;
public ScorePresenter(IScoreService scoreService, ScoreView scoreView) {
this.scoreService = scoreService;
this.scoreView = scoreView;
this.scoreService.OnScoreChanged += OnScoreChanged;
this.scoreView.SetScore(this.scoreService.Score);
}
public void Tick(float scoreSpeed) {
this.scoreView.UpdateScore(scoreSpeed);
}
private void OnScoreChanged(int score) {
this.scoreView.SetScore(score);
}
public void Dispose() {
this.scoreService.OnScoreChanged -= OnScoreChanged;
}
}
}