bee20fd1f8
Wrap all 39 scripts and 6 test files in namespaces matching their folder structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace using directives where types are referenced across modules. Set rootNamespace in both .asmdef files (YachtDice, YachtDice.Tests). Namespace mapping: - YachtDice.Dice — Dice, DiceRoller - YachtDice.Economy — CurrencyBank - YachtDice.Game — GameManager, DiceManager, DebugGameInput - YachtDice.Inventory — InventoryController/Model/SlotView/View - YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target - YachtDice.Persistence — SaveData, SaveSystem - YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory - YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View - YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView - YachtDice.Editor — ModifierAssetCreator - YachtDice.Tests — all test files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
106 lines
2.9 KiB
C#
106 lines
2.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using YachtDice.Scoring;
|
|
|
|
namespace YachtDice.Game
|
|
{
|
|
|
|
public sealed class GameManager : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private DiceManager diceManager;
|
|
[SerializeField] private ScoringSystem scoringSystem;
|
|
|
|
[Header("Settings")]
|
|
[SerializeField] private int maxRollsPerTurn = 3;
|
|
|
|
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 event Action<int> OnTurnStarted;
|
|
public event Action<int> OnRollComplete;
|
|
public event Action<YachtCategory, int> OnScored;
|
|
public event Action<int> OnGameOver;
|
|
|
|
private void Start()
|
|
{
|
|
StartNewGame();
|
|
}
|
|
|
|
public void StartNewGame()
|
|
{
|
|
scoringSystem.ResetScorecard();
|
|
CurrentTurn = 0;
|
|
StartNewTurn();
|
|
}
|
|
|
|
private void StartNewTurn()
|
|
{
|
|
CurrentTurn++;
|
|
CurrentRoll = 0;
|
|
diceManager.UnlockAll();
|
|
OnTurnStarted?.Invoke(CurrentTurn);
|
|
Debug.Log($"=== Turn {CurrentTurn} ===");
|
|
}
|
|
|
|
public void Roll()
|
|
{
|
|
if (!CanRoll) return;
|
|
|
|
CurrentRoll++;
|
|
diceManager.OnAllDiceSettled += HandleAllDiceSettled;
|
|
diceManager.RollUnlocked();
|
|
}
|
|
|
|
private void HandleAllDiceSettled()
|
|
{
|
|
diceManager.OnAllDiceSettled -= HandleAllDiceSettled;
|
|
|
|
int[] values = diceManager.GetCurrentValues();
|
|
Debug.Log($"Roll {CurrentRoll}/{maxRollsPerTurn} | Dice: [{string.Join(", ", values)}]");
|
|
|
|
OnRollComplete?.Invoke(CurrentRoll);
|
|
}
|
|
|
|
public void ToggleDiceLock(int index)
|
|
{
|
|
if (diceManager.IsAnyRolling) return;
|
|
if (CurrentRoll == 0) return;
|
|
diceManager.ToggleLock(index);
|
|
|
|
bool isLocked = diceManager.IsLocked(index);
|
|
Debug.Log($"Dice {index + 1} (value={diceManager.GetValue(index)}): {(isLocked ? "LOCKED" : "UNLOCKED")}");
|
|
}
|
|
|
|
public void ScoreInCategory(YachtCategory category)
|
|
{
|
|
if (!CanScore) return;
|
|
if (scoringSystem.IsCategoryUsed(category)) return;
|
|
|
|
int[] values = diceManager.GetCurrentValues();
|
|
ScoreResult result = scoringSystem.ScoreCategory(values, category);
|
|
|
|
Debug.Log($"Scored {category}: 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)
|
|
{
|
|
int total = scoringSystem.TotalScore;
|
|
Debug.Log($"*** GAME OVER *** Total Score: {total}");
|
|
OnGameOver?.Invoke(total);
|
|
}
|
|
else
|
|
{
|
|
StartNewTurn();
|
|
}
|
|
}
|
|
}
|
|
}
|