using System; using UnityEngine; using static Dice; public static class DiceRoller { /// <summary> /// Rolls each of the dice that are passed to the method and adds up their total value acquired /// </summary> /// <param name="dice">Specific dice taken by their base class</param> /// <returns>Sum total of the roll of dice</returns> public static int RollDice(params Dice[] dice) { if (dice == null) throw new ArgumentNullException("No Dice were passed into the RollDice Call, please pass dice into the call"); int sumOutput = 0; foreach (Dice d in dice) sumOutput += UnityEngine.Random.Range(1, d.Sides + 1); return sumOutput; } /// <summary> /// Dispenses a type of dice based on the enum indicated in the parameter /// </summary> /// <param name="dice">Type of Dice that is desired</param> /// <returns>Parent class of the Dice that was generated</returns> /// <exception cref="ArgumentException">Exception occurs when an unknown type is given</exception> public static Dice DispenseDice(DiceR dice) { return dice switch { DiceR.Four => new DFour(), DiceR.Six => new DSix(), DiceR.Eight => new DEight(), DiceR.Ten => new DTen(), DiceR.Twelve => new DTwelve(), DiceR.Twenty => new DTwenty(), DiceR.Hundred => new DHundred(), _ => throw new ArgumentException(), }; } }