Refactoring game logic
This commit is contained in:
@@ -5,27 +5,51 @@ namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public interface IGameRepo : IDisposable
|
||||
{
|
||||
event Action? Ended;
|
||||
|
||||
event Action? OpenInventory;
|
||||
|
||||
event Action? CloseInventory;
|
||||
|
||||
event Action<string>? AnnounceMessage;
|
||||
|
||||
event Action<int>? DoubleExpTimeStart;
|
||||
|
||||
event Action? DoubleExpTimeEnd;
|
||||
|
||||
void Pause();
|
||||
|
||||
void Resume();
|
||||
|
||||
IAutoProp<bool> IsPaused { get; }
|
||||
|
||||
public void StartDoubleEXP(TimeSpan lengthOfEffect);
|
||||
|
||||
public void EndDoubleExp();
|
||||
|
||||
public double ExpRate { get; }
|
||||
}
|
||||
|
||||
public class GameRepo : IGameRepo
|
||||
{
|
||||
public event Action? Ended;
|
||||
public event Action? OpenInventory;
|
||||
public event Action? CloseInventory;
|
||||
public event Action<string>? AnnounceMessage;
|
||||
public event Action<int>? DoubleExpTimeStart;
|
||||
public event Action? DoubleExpTimeEnd;
|
||||
|
||||
public IAutoProp<bool> IsPaused => _isPaused;
|
||||
private readonly AutoProp<bool> _isPaused;
|
||||
|
||||
public int MaxItemSize => 20;
|
||||
public double ExpRate { get; private set; }
|
||||
|
||||
private bool _disposedValue;
|
||||
|
||||
public GameRepo()
|
||||
{
|
||||
_isPaused = new AutoProp<bool>(true);
|
||||
ExpRate = 1;
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
@@ -40,6 +64,20 @@ public class GameRepo : IGameRepo
|
||||
GD.Print("Resume");
|
||||
}
|
||||
|
||||
public void StartDoubleEXP(TimeSpan lengthOfEffect)
|
||||
{
|
||||
CloseInventory?.Invoke();
|
||||
AnnounceMessage?.Invoke("Experience points temporarily doubled.");
|
||||
DoubleExpTimeStart?.Invoke(lengthOfEffect.Seconds);
|
||||
ExpRate = 2;
|
||||
}
|
||||
|
||||
public void EndDoubleExp()
|
||||
{
|
||||
AnnounceMessage?.Invoke("Experience points effect wore off.");
|
||||
ExpRate = 1;
|
||||
}
|
||||
|
||||
public void OnGameEnded()
|
||||
{
|
||||
Pause();
|
||||
|
||||
Reference in New Issue
Block a user