Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("A Simulation of ROLLING DIE \n");
            Console.ResetColor();

            Random   rd  = new Random();
            DieEvent die = new DieEvent();

            die.TwoFour     += TwoFour_Handler;
            die.MoreThwenty += MoreThanTwenty_Handler;

            List <int> dieList = new List <int>();

            for (int i = 0; i < 50; i++)
            {
                die.Die(rd);
                dieList.Add(die.value);
                Thread.Sleep(100);
            }
            Console.WriteLine();

            die.InvokeTwoFour(die, dieList);
            die.InvokeMoreThanTwenty(die, dieList);
            Console.WriteLine();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that throws the die as much as we want.
        /// </summary>
        /// <param name="die"></param>
        /// <param name="i"></param>
        static List <int> MixThrow(DieEvent die, int i)
        {
            List <int> dieList = new List <int>();
            Random     rd      = new Random();

            for (int k = i; k > 0; k--)
            {
                die.Die(rd);
                dieList.Add(die.value);
            }
            return(dieList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks the sum of last 5 tosses.
        /// </summary>
        /// <param name="die"></param>
        static void MoreThanTwenty_Handler(DieEvent die, List <int> dieList)
        {
            int        count = 0;
            List <int> dieListFiveElement = new List <int>();

            for (int i = 0; i < dieList.Count; i++)
            {
                dieListFiveElement.Add(dieList[i]);
                if (dieListFiveElement.Count == 5)
                {
                    if (dieListFiveElement.Sum() >= 20)
                    {
                        count++;
                    }
                    dieListFiveElement.Remove(dieListFiveElement[0]);
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("There were {0} times ,when sum of 5 tosses greather than or equal to 20", count);
            Console.ResetColor();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks if ther are two fours in
        /// </summary>
        /// <param name="die"></param>
        static void TwoFour_Handler(DieEvent die, List <int> dieList)
        {
            int        count             = 0;
            List <int> dieListTwoElement = new List <int>();

            for (int i = 0; i < dieList.Count; i++)
            {
                dieListTwoElement.Add(dieList[i]);
                if (dieListTwoElement.Count >= 2)
                {
                    if (dieListTwoElement[0] == 4 && dieListTwoElement[1] == 4)
                    {
                        count++;
                    }
                    dieListTwoElement.Remove(dieListTwoElement[0]);
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nTwo of four repeated {0} times ", count);
            Console.ResetColor();
        }
Exemplo n.º 5
0
 public void InvokeMoreThanTwenty(DieEvent die, List <int> x)
 {
     MoreThwenty.Invoke(die, x);
 }
Exemplo n.º 6
0
 public void InvokeTwoFour(DieEvent var, List <int> x)
 {
     TwoFour.Invoke(var, x);
 }