/// <summary> /// Simulate the die's actions. /// </summary> /// <param name="count">The count of rolles.</param> public void Simulate(int count) { List <int> valuesList = new List <int>(); bool wasThePreviousSix = false; while (count != 0) { int value = this.Roll(); Console.WriteLine(value); valuesList.Add(value); if (valuesList.Count() == 6) { if (valuesList.Sum() - value >= 20) { SumIsGreater?.Invoke(); } valuesList.RemoveRange(0, 5); } else if (valuesList.Count == 5) { if (valuesList.Sum() >= 20) { SumIsGreater?.Invoke(); } valuesList.Clear(); } if (value == 6) { if (wasThePreviousSix) { TwoSixesInARow?.Invoke(); } wasThePreviousSix = true; } else { wasThePreviousSix = false; } count--; Thread.Sleep(400); } EndOfTheProgram?.Invoke(); }
/// <summary> /// Method to roll a die. /// </summary> public void Roll() { //Getting random number from 1 to 6. int currentNext = current.Next(1, 7); //Condition to check if last 2 numbers are sixes or not. if (currentNext == 6 && listOfNumbers.Count >= 1 && listOfNumbers.Last() == 6) { countOfSixes++; TwoSixesInARow?.Invoke(); } listOfNumbers.Add(currentNext); //Condition to check if there are 5 elements already. if (listOfNumbers.Count() == 5) { //Checking if sum of elements greater or equal than 20. if (listOfNumbers.Sum() >= 20) { SumOfConsequentNumbers?.Invoke(listOfNumbers); } //Removing first element of the list. listOfNumbers.RemoveAt(0); } }