Ejemplo n.º 1
0
        private void randomTicketButton_Click(object sender, EventArgs e)
        {
            var myTicket = new PowerBallTicket(random);

            myTicketLabel.Text = myTicket.ToString();
            tickets++;
        }
Ejemplo n.º 2
0
        public int CompareTo(object obj)
        {
            PowerBallTicket other = obj as PowerBallTicket;

            if (other == null)
            {
                return(-1);
            }

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

            myWhiteBalls.AddRange(whiteBalls);
            myWhiteBalls.Sort();

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

            otherWhiteBalls.AddRange(other.whiteBalls);
            otherWhiteBalls.Sort();

            for (int index = 0; index < myWhiteBalls.Count; index++)
            {
                if (myWhiteBalls[index] < otherWhiteBalls[index])
                {
                    return(-1);
                }
                else if (myWhiteBalls[index] > otherWhiteBalls[index])
                {
                    return(1);
                }
            }

            return(RedBall - other.RedBall);
        }
Ejemplo n.º 3
0
        public int getWinnings(PowerBallTicket winningTicket)
        {
            // this would be better as static variables,
            //  but, anonymous is cool
            var prizes = new
            {
                Jackpot   = 1000000000,
                FiveWhite = 1000000
            };


            int winnings = 0;

            bool redMatch = RedBall == winningTicket.RedBall;

            int whiteMatches = 0;

            foreach (var number in whiteBalls)
            {
                foreach (var winningNumber in winningTicket.whiteBalls)
                {
                    if (number == winningNumber)
                    {
                        whiteMatches++;
                    }
                }
            }

            if (whiteMatches == 5 && redMatch)
            {
                winnings = prizes.Jackpot;
            }
            else if (whiteMatches == 5)
            {
                winnings = prizes.FiveWhite;
            }
            else if (whiteMatches == 4 && redMatch)
            {
                winnings = 50000;
            }
            else if ((whiteMatches == 4) ||
                     (whiteMatches == 3 && redMatch))
            {
                winnings = 100;
            }
            else if ((whiteMatches == 3) ||
                     (whiteMatches == 2 && redMatch))
            {
                winnings = 7;
            }
            else if (redMatch)
            {
                winnings = 4;
            }

            return(winnings);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            // checks to see if the sender that triggered the event is a control
            if (sender == button2)
            {
                // basically a Try Cast
                Button button = sender as Button;
                // if it didn't cast, we get null
                if (button != null)
                {
                    button.Text = "You clicked me";
                }

                MessageBox.Show("YOU DID IT!");
                button1.Enabled = true;
                tickets         = 0;
            }

            else
            {
                var numbersString = numbersTextBox.Text;

                var numbersSplit = numbersString.Split();

                if (numbersSplit.Length != 6)
                {
                    myTicketLabel.Text = "Please enter 6 numbers separated by spaces";
                }
                else
                {
                    int[] numbers = new int[6];

                    for (int index = 0; index < numbersSplit.Length; index++)
                    {
                        numbers[index] = Int32.Parse(numbersSplit[index]);
                    }

                    var myTicket = new PowerBallTicket(numbers);

                    myTicketLabel.Text = myTicket.ToString();
                    tickets++;

                    if (tickets == 3)
                    {
                        button1.Enabled = false;
                    }
                }
            }
        }