// Create a true comparison method
        public bool isEqual(Lottery compareTo)
        {
            bool result = false;

            if ((this.firstPick.teamName.Equals(compareTo.firstPick.teamName)) && (this.secondPick.teamName.Equals(compareTo.secondPick.teamName)) && (this.thirdPick.teamName.Equals(compareTo.thirdPick.teamName)) && (this.fourthPick.teamName.Equals(compareTo.fourthPick.teamName)) && (this.fifthPick.teamName.Equals(compareTo.fifthPick.teamName)) && (this.sixthPick.teamName.Equals(compareTo.sixthPick.teamName)) && (this.seventhPick.teamName.Equals(compareTo.seventhPick.teamName)) && (this.eighthPick.teamName.Equals(compareTo.eighthPick.teamName)) && (this.ninthPick.teamName.Equals(compareTo.ninthPick.teamName)) && (this.tenthPick.teamName.Equals(compareTo.tenthPick.teamName)) && (this.eleventhPick.teamName.Equals(compareTo.eleventhPick.teamName)) && (this.twelfthPick.teamName.Equals(compareTo.twelfthPick.teamName)) && (this.thirteenthPick.teamName.Equals(compareTo.thirteenthPick.teamName)) && (this.fourteenthPick.teamName.Equals(compareTo.fourteenthPick.teamName)))
            {
                result = true;
            }
            return(result);
        }
Beispiel #2
0
        private async void lottoGenBtn_Click(object sender, RoutedEventArgs e)
        {
            var progress = new Progress <int>(value => lotteryProgress.Value = value);
            await Task.Run(() =>
            {
                results        = new LotteryResults();
                realLottoIndex = -1;
                // Timer to track amount of time has passed.
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                offButtons();

                this.Dispatcher.Invoke((Action)(() =>
                {
                    // Grab number of text box
                    runs = Convert.ToInt32(test_txtBox.Text);

                    lotteryProgress.Maximum = runs + 5;
                    progMax = (int)lotteryProgress.Maximum;
                }));

                for (int i = 0; i < runs; i++)
                {
                    Lottery lotto    = new Lottery(lotteryYear);
                    bool incOutcomes = false;
                    int whereToInc   = 0;
                    for (int j = 0; j < results.results.Count; j++)
                    {
                        if (lotto.isEqual(results.results[j]))
                        {
                            incOutcomes = true;
                            whereToInc  = j;
                        }
                    }
                    if (incOutcomes)
                    {
                        results.results[whereToInc].addOutcome();
                    }
                    else
                    {
                        results.results.Add(lotto);
                    }
                    ((IProgress <int>)progress).Report(i + 1);
                }

                results.sortResults();

                ((IProgress <int>)progress).Report(progMax - 5);

                if (results.results.Count >= 10)
                {
                    setButtons(10);
                }
                else
                {
                    setButtons(results.results.Count);
                }
                ((IProgress <int>)progress).Report(progMax - 4);

                for (int i = 0; i < results.results.Count; i++)
                {
                    if (results.results[i].isEqual(Years.getTrueLottery(lotteryYear)))
                    {
                        realLottoIndex = i;
                        break;
                    }
                }

                ((IProgress <int>)progress).Report(progMax - 3);

                if (realLottoIndex == -1)
                {
                    realLottoTimes = 0;
                }
                else
                {
                    realLottoTimes = results.results[realLottoIndex].outcomes;
                }

                ((IProgress <int>)progress).Report(progMax);

                this.Dispatcher.Invoke((Action)(() =>
                {
                    actLottoBtn.IsEnabled = true;

                    mainLabel.Content = "Your lottery has been generated. Click a button on the left to see a result.";
                }));

                stopWatch.Stop();
                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                   ts.Hours, ts.Minutes, ts.Seconds,
                                                   ts.Milliseconds / 10);
                this.Dispatcher.Invoke((Action)(() =>
                {
                    timerLbl.Content = "RunTime: " + elapsedTime;
                }));
            });
        }