Exemplo n.º 1
0
        public void DrawWinningTicket()
        {
            //TODO: stop any other 'purchases' from happening
            //      by changing the state

            WinningTicket = new LotteryTicket("WinningTicket");
        }
Exemplo n.º 2
0
        public LotteryTicket SellTicket(string playerName, int [] sixnums)
        {
            var lt = new LotteryTicket(playerName, sixnums);

            ProcessSale(lt);
            return(lt);
        }
Exemplo n.º 3
0
        public LotteryTicket SellTicket(string playerName)
        {
            var lt = new LotteryTicket(playerName);

            //better concurrency option
            ProcessSale(lt);
            return(lt);
        }
Exemplo n.º 4
0
        public void CheckWinningTicket(LotteryTicket lt)
        {
            int whiteMatches = NumberMatchingWhiteBalls(lt);

            if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 5)
            {
                lt.winLevel      = 1;
                lt.winAmtDollars = GrandPrizeAmount;
            }
            else if (whiteMatches == 5)
            {
                lt.winLevel      = 2;
                lt.winAmtDollars = 1000000;//$1M
            }
            else if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 4)
            {
                lt.winLevel      = 3;
                lt.winAmtDollars = 50000;//$50k
            }
            else if (whiteMatches == 4)
            {
                lt.winLevel      = 4;
                lt.winAmtDollars = 100;//$100
            }
            else if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 3)
            {
                lt.winLevel      = 5;
                lt.winAmtDollars = 100;//$100
            }
            else if (whiteMatches == 3)
            {
                lt.winLevel      = 6;
                lt.winAmtDollars = 7;//$7
            }
            else if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 2)
            {
                lt.winLevel      = 7;
                lt.winAmtDollars = 7;//$7
            }
            else if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 1)
            {
                lt.winLevel      = 8;
                lt.winAmtDollars = 4;//$4
            }
            else if (lt.powerBall == WinningTicket.powerBall && whiteMatches == 0)
            {
                lt.winLevel      = 9;
                lt.winAmtDollars = 4;//$4
            }
            else
            {
                lt.winLevel      = 0;
                lt.winAmtDollars = 0;
            }

            lt.isGraded = true;
        }
Exemplo n.º 5
0
 public bool DrawWinningTicket()
 {
     if (SalesState == TicketSales.CLOSED)
     {
         WinningTicket = new LotteryTicket("WinningTicket");
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 6
0
 public void PurchaseTickets(LotteryPeriod period, int sellLimit)
 {
     if (sellLimit < 1)
     {
         throw new System.ArgumentException("Parameter cannot be <1", "sellLimit");
     }
     for (int i = 0; i < sellLimit; i++)
     {
         LotteryTicket t1 = new LotteryTicket();
         ProcessSale(t1);
     }
 }
Exemplo n.º 7
0
 public int NumberMatchingWhiteBalls(LotteryTicket lt)
 {
     int numMatches = 0;
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             if (lt.balls[i] == WinningTicket.balls[j])
             {
                 numMatches++;
             }
         }//end for
     }
     return numMatches;
 }
Exemplo n.º 8
0
        private void ProcessSale(LotteryTicket lt)
        {
            //to make this threadsafe, the rule will be:
            // 1) always take lock of p.soldTickets
            // 2) check if TickeSales.OK

            if (p.SalesState == TicketSales.OK)
            {
                p.soldTickets.Push(lt);
            }
            else
            {
                throw new TicketSalesClosedException();
            }
        }