コード例 #1
0
        static public void Print(LotteryCoupon lotteryCoupon, int luckyNumber)
        {
            var sb = new StringBuilder();
            var oldConsoleForegroundColour = Console.ForegroundColor;

            foreach (var row in lotteryCoupon.Rows)
            {
                foreach (int n in row)
                {
                    Console.Write(" ");
                    if (n == luckyNumber)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    Console.Write(n);
                    if (n == luckyNumber)
                    {
                        Console.ForegroundColor = oldConsoleForegroundColour;
                    }
                    Console.Write(ExtraPadding(n));
                    Console.Write("|");
                }
                Console.Out.WriteLine("");
            }
        }
コード例 #2
0
 public void SetLuckyLotteryCouponIfNull(LotteryCoupon lotteryCoupon)
 {
     lock (this)
     {
         if (LuckyLotteryCoupon == null)
         {
             LuckyLotteryCoupon = lotteryCoupon;
         }
     }
 }
コード例 #3
0
 public void RefillLotteryCoupon(LotteryCoupon lotteryCoupon)
 {
     for (int r = 0; r < lotteryCoupon.Rows.Count; r++)
     {
         var row = lotteryCoupon.Rows[r];
         for (int c = 0; c < row.Count; c++)
         {
             row[c] = RandomNumberGenerator.Next();
         }
     }
 }
コード例 #4
0
 public bool Check(LotteryCoupon lotteryCoupon)
 {
     if (lotteryCoupon.Rows.Count < 1)
     {
         return(false);  // We choose to consider an empty lottery coupon as unlucky
     }
     foreach (var row in lotteryCoupon.Rows)
     {
         if (!row.Contains(LuckyNumber))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #5
0
        private static void PrintResult(LotteryCoupon lotteryCoupon, Stopwatch stopwatch, long numberOfAttempts, int numberOfThreads, int luckyNumber)
        {
            LotteryCouponPrinter.Print(lotteryCoupon, luckyNumber);

            PrintExecutionInfo(stopwatch, numberOfAttempts, numberOfThreads);
        }