/// <summary> /// Program entry point. /// </summary> /// <param name="args">Startup arguments.</param> private static void Main(string[] args) { Console.WriteLine("What dice would you like to roll?"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("> "); var input = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); var diceBag = new DiceBag(new RandomNumberGenerator()); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(diceBag.Roll(input).Total); Console.WriteLine(); }
static void Main(string[] args) { DiceBag toHit = "1d20 + 4"; var summedResult = toHit.Roll(new BasicPresenter()); Console.WriteLine("Final result: " + summedResult); DiceBag damage = DiceBag.Create( new List <Die> { new Die("1d6", 1, 6) }, new List <Modifier> { new Modifier(2) }); summedResult = damage.Roll(new BasicPresenter()); Console.WriteLine("Final result: " + summedResult); try { DiceBag error = "-12dd"; } catch (DiceParseException ex) { Console.Error.WriteLine(ex.Message); } }
public void Roll1Plus3D6_6s() { var randomMock = new Mock <IRandomNumberGenerator>(); randomMock.Setup(x => x.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(6); var diceBag = new DiceBag(randomMock.Object); var result = diceBag.Roll("1+3d6"); Assert.AreEqual(19, result.Total); }
public void TestRollEach() { DiceBag dice = new DiceBag(); int[] sides = { 2, 3, 4, 6, 8, 10, 12 }; foreach (int side in sides) { for (int i = 1; i < 6; i++) { Console.WriteLine($"Rolling {i}d{side}"); var result = dice.Roll(i, side); Assert.IsTrue(Enumerable.Range(i, side * i).Contains(result)); } } }
static void RollFromDiceBag() { DiceBag dice = new DiceBag(); System.Console.WriteLine("What type of dice would you like to roll?"); System.Console.WriteLine("1. d2"); System.Console.WriteLine("2. d3"); System.Console.WriteLine("3. d4"); System.Console.WriteLine("4. d6"); System.Console.WriteLine("5. d8"); System.Console.WriteLine("6. d10"); System.Console.WriteLine("7. d12"); System.Console.WriteLine("8. d20"); System.Console.WriteLine("9. Percentage Dice"); char typeKey = System.Console.ReadKey().KeyChar; System.Console.WriteLine(); string quantityAttempt; if (typeKey != '9') { System.Console.WriteLine("How many would you like to roll?"); quantityAttempt = System.Console.ReadLine(); System.Console.WriteLine(); } else { quantityAttempt = "1"; } if (quantityAttempt != null) { int quantity = int.Parse(quantityAttempt); switch (typeKey) { case '1': dice.Roll(quantity, 2); break; case '2': dice.Roll(quantity, 3); break; case '3': dice.Roll(quantity, 4); break; case '4': dice.Roll(quantity, 6); break; case '5': dice.Roll(quantity, 8); break; case '6': dice.Roll(quantity, 10); break; case '7': dice.Roll(quantity, 12); break; case '8': dice.Roll(quantity, 20); break; case '9': dice.Roll_Percent(); break; } } }
public override bool OnDispelAttempted() { return(DiceBag.Roll(1, Dice.D100) <= baseResistance); }