[Add] Game Loop Playable

This commit is contained in:
2026-03-28 12:53:34 +07:00
parent 78ad76120f
commit f2173d2c73
20 changed files with 1433 additions and 122 deletions
+22 -10
View File
@@ -23,10 +23,10 @@ namespace YachtDice.Game
public int MaxRollsPerTurn => _runLoopService != null ? _runLoopService.State.CurrentStageRollBudget : 0;
public RunPhase CurrentPhase => _runLoopService != null ? _runLoopService.State.Phase : RunPhase.None;
public bool CanRoll => _runLoopService != null && _runLoopService.CanRoll() && !_diceManager.IsAnyRolling;
public bool CanRoll => _runLoopService != null && _runLoopService.CanBeginRoll() && !_diceManager.IsAnyRolling;
public bool CanScore => _runLoopService != null && CurrentPhase == RunPhase.CategorySelection && !_diceManager.IsAnyRolling;
public bool IsGameOver => _runLoopService != null && _runLoopService.State.IsFailed;
public bool IsShopOpen => CurrentPhase == RunPhase.Shop;
public bool IsShopAvailable => _runLoopService != null && _runLoopService.State.IsShopAvailable;
public event Action<int> OnTurnStarted;
public event Action<int> OnRollComplete;
@@ -41,6 +41,7 @@ namespace YachtDice.Game
public event Action<int> OnQuotaChanged;
public event Action<int, int> OnCycleCompleted;
public event Action<RunPhase> OnPhaseChanged;
public event Action<bool> OnShopAvailabilityChanged;
[Inject]
public void Construct(DiceManager diceManager, RunLoopService runLoopService, ScoringSystem scoringSystem)
@@ -50,6 +51,7 @@ namespace YachtDice.Game
_scoringSystem = scoringSystem;
_runLoopService.OnStageStarted += HandleStageStarted;
_runLoopService.OnCategoryRecorded += HandleCategoryRecorded;
_runLoopService.OnStageCleared += HandleStageCleared;
_runLoopService.OnRunFailed += HandleRunFailed;
_runLoopService.OnBetStarted += HandleBetStarted;
@@ -59,6 +61,7 @@ namespace YachtDice.Game
_runLoopService.OnQuotaChanged += HandleQuotaChanged;
_runLoopService.OnCycleCompleted += HandleCycleCompleted;
_runLoopService.OnPhaseChanged += HandlePhaseChanged;
_runLoopService.OnShopAvailabilityChanged += HandleShopAvailabilityChanged;
}
private void OnDestroy()
@@ -67,6 +70,7 @@ namespace YachtDice.Game
return;
_runLoopService.OnStageStarted -= HandleStageStarted;
_runLoopService.OnCategoryRecorded -= HandleCategoryRecorded;
_runLoopService.OnStageCleared -= HandleStageCleared;
_runLoopService.OnRunFailed -= HandleRunFailed;
_runLoopService.OnBetStarted -= HandleBetStarted;
@@ -76,6 +80,7 @@ namespace YachtDice.Game
_runLoopService.OnQuotaChanged -= HandleQuotaChanged;
_runLoopService.OnCycleCompleted -= HandleCycleCompleted;
_runLoopService.OnPhaseChanged -= HandlePhaseChanged;
_runLoopService.OnShopAvailabilityChanged -= HandleShopAvailabilityChanged;
}
public void StartNewGame()
@@ -86,23 +91,21 @@ namespace YachtDice.Game
public void CompleteShop()
{
if (!IsShopOpen)
return;
_runLoopService.CompleteShop();
OnShopClosed?.Invoke();
}
public void Roll()
public bool Roll()
{
if (!CanRoll)
return;
return false;
if (!_runLoopService.TryBeginRoll())
return;
return false;
_diceManager.OnAllDiceSettled += HandleAllDiceSettled;
_diceManager.RollUnlocked();
return true;
}
private void HandleAllDiceSettled()
@@ -139,7 +142,7 @@ namespace YachtDice.Game
public bool CanOpenShopManually()
{
return IsShopOpen;
return IsShopAvailable && !IsGameOver;
}
private void HandleStageStarted(RunStageState stage)
@@ -148,10 +151,14 @@ namespace YachtDice.Game
OnTurnStarted?.Invoke(stage.Index + 1);
}
private void HandleCategoryRecorded(CategoryDefinition category, ScoreResult result)
{
OnScored?.Invoke(category, result.FinalScore);
}
private void HandleStageCleared(RunStageState stage, CategoryDefinition category, ScoreResult result)
{
_diceManager.UnlockAll();
OnScored?.Invoke(category, result.FinalScore);
}
private void HandleRunFailed(RunState state)
@@ -193,5 +200,10 @@ namespace YachtDice.Game
{
OnPhaseChanged?.Invoke(phase);
}
private void HandleShopAvailabilityChanged(bool isAvailable)
{
OnShopAvailabilityChanged?.Invoke(isAvailable);
}
}
}