Files
godot-host-test/Game/Score/TotalScore.cs
T
2026-07-29 11:05:27 +02:00

28 lines
741 B
C#

using System;
using GodotHostTest.Interfaces;
using R3;
namespace GodotHostTest.Game.Score;
public class TotalScore : IScore, IDisposable
{
public TotalScore(ITargetEventBus targetEventBus)
{
Score =
// map every hit target to +20 points
targetEventBus.Hit.Select(_ => 20)
// map every missed target to -5 points
.Merge(targetEventBus.TimedOut.Select(_ => -5))
// sum them all (starting with 0)
.Scan(0, (x1, x2) => x1 + x2)
.ToReadOnlyReactiveProperty();
}
public void Dispose()
{
Score.Dispose();
GC.SuppressFinalize(this);
}
public ReadOnlyReactiveProperty<int> Score { get; }
}