[Add] Dice & Refactor private names

This commit is contained in:
2026-03-02 11:22:01 +07:00
parent 4890fa946e
commit f65976796d
36 changed files with 883 additions and 489 deletions
+25 -25
View File
@@ -11,15 +11,15 @@ namespace YachtDice.Game
[Header("Settings")]
[SerializeField] private int maxRollsPerTurn = 3;
private DiceManager diceManager;
private ScoringSystem scoringSystem;
private DiceManager _diceManager;
private ScoringSystem _scoringSystem;
public int CurrentRoll { get; private set; }
public int CurrentTurn { get; private set; }
public bool CanRoll => CurrentRoll < maxRollsPerTurn && !diceManager.IsAnyRolling;
public bool CanScore => CurrentRoll > 0 && !diceManager.IsAnyRolling;
public bool IsGameOver => scoringSystem.IsComplete;
public bool CanRoll => CurrentRoll < maxRollsPerTurn && !_diceManager.IsAnyRolling;
public bool CanScore => CurrentRoll > 0 && !_diceManager.IsAnyRolling;
public bool IsGameOver => _scoringSystem.IsComplete;
public event Action<int> OnTurnStarted;
public event Action<int> OnRollComplete;
@@ -29,13 +29,13 @@ namespace YachtDice.Game
[Inject]
public void Construct(DiceManager diceManager, ScoringSystem scoringSystem)
{
this.diceManager = diceManager;
this.scoringSystem = scoringSystem;
this._diceManager = diceManager;
this._scoringSystem = scoringSystem;
}
public void StartNewGame()
{
scoringSystem.ResetScorecard();
_scoringSystem.ResetScorecard();
CurrentTurn = 0;
StartNewTurn();
}
@@ -44,7 +44,7 @@ namespace YachtDice.Game
{
CurrentTurn++;
CurrentRoll = 0;
diceManager.UnlockAll();
_diceManager.UnlockAll();
OnTurnStarted?.Invoke(CurrentTurn);
Debug.Log($"=== Turn {CurrentTurn} ===");
}
@@ -54,15 +54,15 @@ namespace YachtDice.Game
if (!CanRoll) return;
CurrentRoll++;
diceManager.OnAllDiceSettled += HandleAllDiceSettled;
diceManager.RollUnlocked();
_diceManager.OnAllDiceSettled += HandleAllDiceSettled;
_diceManager.RollUnlocked();
}
private void HandleAllDiceSettled()
{
diceManager.OnAllDiceSettled -= HandleAllDiceSettled;
_diceManager.OnAllDiceSettled -= HandleAllDiceSettled;
int[] values = diceManager.GetCurrentValues();
int[] values = _diceManager.GetCurrentValues();
Debug.Log($"Roll {CurrentRoll}/{maxRollsPerTurn} | Dice: [{string.Join(", ", values)}]");
OnRollComplete?.Invoke(CurrentRoll);
@@ -70,31 +70,31 @@ namespace YachtDice.Game
public void ToggleDiceLock(int index)
{
if (diceManager.IsAnyRolling) return;
if (_diceManager.IsAnyRolling) return;
if (CurrentRoll == 0) return;
diceManager.ToggleLock(index);
_diceManager.ToggleLock(index);
bool isLocked = diceManager.IsLocked(index);
Debug.Log($"Dice {index + 1} (value={diceManager.GetValue(index)}): {(isLocked ? "LOCKED" : "UNLOCKED")}");
bool isLocked = _diceManager.IsLocked(index);
Debug.Log($"Dice {index + 1} (value={_diceManager.GetValue(index)}): {(isLocked ? "LOCKED" : "UNLOCKED")}");
}
public void ScoreInCategory(CategoryDefinition category)
{
if (!CanScore) return;
if (scoringSystem.IsCategoryUsed(category)) return;
if (_scoringSystem.IsCategoryUsed(category)) return;
var dice = diceManager.GetDice();
ScoreResult result = scoringSystem.ScoreCategory(dice, category);
var dice = _diceManager.GetDice();
ScoreResult result = _scoringSystem.ScoreCategory(dice, category);
Debug.Log($"Scored {category.DisplayName}: base={result.BaseScore}, " +
$"bonus=+{result.FlatBonus}, mult=x{result.Multiplier:F1}, " +
$"FINAL={result.FinalScore} | Total={scoringSystem.TotalScore}");
Debug.Log($"Scored {category.DisplayName}: base={result.baseScore}, " +
$"bonus=+{result.flatBonus}, mult=x{result.multiplier:F1}, " +
$"FINAL={result.FinalScore} | Total={_scoringSystem.TotalScore}");
OnScored?.Invoke(category, result.FinalScore);
if (scoringSystem.IsComplete)
if (_scoringSystem.IsComplete)
{
int total = scoringSystem.TotalScore;
int total = _scoringSystem.TotalScore;
Debug.Log($"*** GAME OVER *** Total Score: {total}");
OnGameOver?.Invoke(total);
}