[Add] Dice & Refactor private names
This commit is contained in:
@@ -14,37 +14,37 @@ namespace YachtDice.Game
|
||||
|
||||
public int DiceCount => diceRollers.Count;
|
||||
|
||||
private DiceInstance[] diceInstances;
|
||||
private int pendingCount;
|
||||
private DiceInstance[] _diceInstances;
|
||||
private int _pendingCount;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
int count = diceRollers.Count;
|
||||
diceInstances = new DiceInstance[count];
|
||||
_diceInstances = new DiceInstance[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var definition = diceRollers[i].Definition;
|
||||
diceInstances[i] = new DiceInstance(definition);
|
||||
_diceInstances[i] = new DiceInstance(definition);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLocked(int index) => diceInstances[index].IsLocked;
|
||||
public bool IsLocked(int index) => _diceInstances[index].IsLocked;
|
||||
|
||||
public void ToggleLock(int index)
|
||||
{
|
||||
diceInstances[index].IsLocked = !diceInstances[index].IsLocked;
|
||||
_diceInstances[index].IsLocked = !_diceInstances[index].IsLocked;
|
||||
}
|
||||
|
||||
public void SetLocked(int index, bool isLocked)
|
||||
{
|
||||
diceInstances[index].IsLocked = isLocked;
|
||||
_diceInstances[index].IsLocked = isLocked;
|
||||
}
|
||||
|
||||
public void UnlockAll()
|
||||
{
|
||||
for (int i = 0; i < diceInstances.Length; i++)
|
||||
diceInstances[i].IsLocked = false;
|
||||
for (int i = 0; i < _diceInstances.Length; i++)
|
||||
_diceInstances[i].IsLocked = false;
|
||||
}
|
||||
|
||||
public void RollUnlocked()
|
||||
@@ -52,23 +52,23 @@ namespace YachtDice.Game
|
||||
for (int i = 0; i < diceRollers.Count; i++)
|
||||
if (diceRollers[i].IsRolling) return;
|
||||
|
||||
pendingCount = 0;
|
||||
_pendingCount = 0;
|
||||
|
||||
for (int i = 0; i < diceRollers.Count; i++)
|
||||
{
|
||||
if (diceInstances[i].IsLocked) continue;
|
||||
if (_diceInstances[i].IsLocked) continue;
|
||||
|
||||
pendingCount++;
|
||||
_pendingCount++;
|
||||
int capturedIndex = i;
|
||||
|
||||
void Handler(int value)
|
||||
{
|
||||
diceRollers[capturedIndex].OnRollFinished -= Handler;
|
||||
diceInstances[capturedIndex].Value = value;
|
||||
_diceInstances[capturedIndex].Value = value;
|
||||
OnDiceSettled?.Invoke(capturedIndex, value);
|
||||
|
||||
pendingCount--;
|
||||
if (pendingCount <= 0)
|
||||
_pendingCount--;
|
||||
if (_pendingCount <= 0)
|
||||
OnAllDiceSettled?.Invoke();
|
||||
}
|
||||
|
||||
@@ -76,23 +76,23 @@ namespace YachtDice.Game
|
||||
diceRollers[i].Roll();
|
||||
}
|
||||
|
||||
if (pendingCount == 0)
|
||||
if (_pendingCount == 0)
|
||||
OnAllDiceSettled?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>Возвращает абстрактный список дайсов (основной API).</summary>
|
||||
public IReadOnlyList<IDice> GetDice() => diceInstances;
|
||||
public IReadOnlyList<IDice> GetDice() => _diceInstances;
|
||||
|
||||
/// <summary>Возвращает копию текущих значений (обратная совместимость).</summary>
|
||||
public int[] GetCurrentValues()
|
||||
{
|
||||
int[] values = new int[diceInstances.Length];
|
||||
for (int i = 0; i < diceInstances.Length; i++)
|
||||
values[i] = diceInstances[i].Value;
|
||||
int[] values = new int[_diceInstances.Length];
|
||||
for (int i = 0; i < _diceInstances.Length; i++)
|
||||
values[i] = _diceInstances[i].Value;
|
||||
return values;
|
||||
}
|
||||
|
||||
public int GetValue(int index) => diceInstances[index].Value;
|
||||
public int GetValue(int index) => _diceInstances[index].Value;
|
||||
|
||||
public bool IsAnyRolling
|
||||
{
|
||||
@@ -110,7 +110,7 @@ namespace YachtDice.Game
|
||||
{
|
||||
var diceComponent = diceRollers[i].GetComponent<Dice.Dice>();
|
||||
if (diceComponent != null && diceComponent.TryGetTopValue(out int val))
|
||||
diceInstances[i].Value = val;
|
||||
_diceInstances[i].Value = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user