/// <summary> /// Method to roll the dice /// </summary> /// <param name="dicerolled"></param> /// <param name="dicesides"></param> /// <returns></returns> public static DiceResults Rolling(int dicerolled, int dicesides) { // creates a random number and stores it as the variable rnd Random rnd = new Random(); // Creates a new empty array(list) of numbers List <int> arrayList = new List <int>(); // Rolling the dice 1 at a time until the full amount have been rolled for (int i = 0; i < dicerolled; i++) { // returns a random value between 1 and the number of sides+1 int roll = rnd.Next(1, (dicesides + 1)); // sets the value the roll landed on int totalRolled = roll; // adds the value of the roll to the array arrayList.Add(totalRolled); } string rolls = string.Join(", ", arrayList); int total = arrayList.Sum(); DiceResults Results = new DiceResults(rolls, total); return(Results); }
private void PerformRoll() { if (Number > MAX_DICE_COUNT) { throw new TooManyDicesException(Number); } RollResult = Add; Random random = new Random(); diceResults = new List <BigInteger>(); if (Faces == 1) { RollResult += Number; } else { byte[] bytes = Faces.ToByteArray(); for (int i = 0; i < Number; i++) { random.NextBytes(bytes); bytes[bytes.Length - 1] &= (byte)0x7F; BigInteger roll = new BigInteger(bytes) % Faces + 1; if (Number <= MAX_DICE_RESULT_COUNT) { DiceResults.Add(roll); } RollResult += roll; } } }
public void TestForAllSixes() { //Arrange var results = new DiceResults(6, 6, 6); //Assert Assert.IsTrue(results.AllSixes()); }
public void TestForDoubleTwo() { //Arrange var results = new DiceResults(2, 5, 2); //Assert Assert.IsTrue(results.AnyDouble()); }
public void TestForAllFives() { //Arrange var results = new DiceResults(5, 5, 5); //Assert Assert.IsTrue(results.SetLessThanSix()); }
public void TestBonusForAllFives() { //Arrange var results = new DiceResults(5, 5, 5); //Act int bonus = results.GetBonus(); //Assert Assert.AreEqual(10, bonus); }
public void TestBonusForAllSixes() { //Arrange var results = new DiceResults(6, 6, 6); //Act int bonus = results.GetBonus(); //Assert Assert.AreEqual(20, bonus); }
public void TestPrizeForAllSixesAndIncorrectGamble() { //Arrange var results = new DiceResults(6, 6, 6); //Act var prize = results.GetPrize(15, 50); //Assert Assert.AreEqual(20, prize); }
public void TestBonusWhenNoBonus() { //Arrange var results = new DiceResults(1, 2, 3); //Act int bonus = results.GetBonus(); //Assert Assert.AreEqual(0, bonus); }
public void TestBonusForDoubleTwo() { //Arrange var results = new DiceResults(2, 5, 2); //Act int bonus = results.GetBonus(); //Assert Assert.AreEqual(5, bonus); }
public void TestDiceTotal() { //Arrange var results = new DiceResults(1, 2, 3); //Act int diceTotal = results.GetDiceTotal(); //Assert Assert.AreEqual(6, diceTotal); }
public async Task Roll(string userInput) { //Validate the User input to make sure is in corret format Match diceValidation = RollController.ValidateDiceRoll(userInput); // If the Validation is Successful if (diceValidation.Success) { var msg = Context.Message; var discordId = msg.Author.Username; int numberOfDiceRolledInt = Convert.ToInt32(RollController.GetNumberOfDice(userInput).Value); int numberOfSidesOnDiceInt = Convert.ToInt32(RollController.GetNumberOfSides(userInput).Value); // If the number of dice or number of sides is above 100 display this message if (numberOfSidesOnDiceInt > 100 || numberOfDiceRolledInt > 100) { await ReplyAsync(Resources.error_Too_Many_Dice); } // If the number of sides is 1 display this message else if (numberOfSidesOnDiceInt == 1) { await ReplyAsync(Resources.error_OneSide_Dice); } // If the User input is correct and passes the checks run this else { DiceResults rolledDice = RollController.Rolling(numberOfDiceRolledInt, numberOfSidesOnDiceInt); // Send all the Information back into the chat to the user //await ReplyAsync($"{discordId} Rolled: \r\n{rolledDice.Results} \r\nTotal: {rolledDice.Total.ToString()}"); await ReplyAsync(string.Format(Resources.response_Dice_Roll, discordId, rolledDice.Results, rolledDice.Total)); } } else { //If the input is in an incorrect format display this message. await ReplyAsync(Resources.error_Incorrect_Format_Dice); } }
private void SumRolls() { Total = DiceResults.Sum() + _bonus.Sum(); }
public int NumDiceOf(int value) { return(DiceResults.Count(f => f == value)); }
public DiceResults IsThreeOfSameKind() { DiceResults r = new DiceResults(); // Handles how many ones if (HowManyOnes() == 3) { r.TrueFalse = true; r.Value1 = 1; } // Handles how many twos if (HowManyTwos() == 3) { r.TrueFalse = true; if (r.Value1 > 0) { r.Value2 = 2; } else { r.Value1 = 2; } } // Handles how many threes if (HowManyThrees() == 3) { r.TrueFalse = true; if (r.Value1 > 0) { r.Value2 = 3; } else { r.Value1 = 3; } } // Handles how many fours if (HowManyFours() == 3) { r.TrueFalse = true; if (r.Value1 > 0) { r.Value2 = 4; } else { r.Value1 = 4; } } // Handles how many fives if (HowManyFives() == 3) { r.TrueFalse = true; if (r.Value1 > 0) { r.Value2 = 5; } else { r.Value1 = 5; } } // Handles how many sixes if (HowManySixes() == 3) { r.TrueFalse = true; if (r.Value1 > 0) { r.Value2 = 6; } else { r.Value1 = 6; } } return(r); }