예제 #1
0
        //Updates labels related to personal best score and champion
        private void UpdateLeaderBoardPersonalBest()
        {
            try
            {
                LearningGames lg = new LearningGames();
                RegisterLogin rl = new RegisterLogin();

                ModelLeaderBoard mlb = new ModelLeaderBoard
                {
                    USER_LIBRARY_CARD_ID = currentUser
                };

                List <ModelLeaderBoard> getPersonalBest = lg.GetPersonalBestReplacingBooks(mlb, connectionString);

                if (getPersonalBest.Count == 1)
                {
                    lbPersonalBest.Text = getPersonalBest[0].REPLACING_BOOKS_PERSONAL_BEST.ToString();
                    pb = getPersonalBest[0].REPLACING_BOOKS_PERSONAL_BEST.ToString();
                }

                getAllRecords = lg.GetAllLeadBoardRecords(connectionString);

                SelectionSortBestTime();

                lbChampTime.Text = getAllRecords[0].REPLACING_BOOKS_PERSONAL_BEST;

                List <ModelLeaderBoard> getBestUserId = lg.GetChampionNameReplacingBooks(getAllRecords[0].REPLACING_BOOKS_PERSONAL_BEST.ToString(), connectionString);

                int id = getBestUserId[0].USER_LIBRARY_CARD_ID;

                List <ModelRegisterLogin> getBestUser = rl.GetUser(id, connectionString);
                tbChampionName.Text = getBestUser[0].USER_FNAME + " " + getBestUser[0].USER_LNAME;
                ChampTime           = getAllRecords[0].REPLACING_BOOKS_PERSONAL_BEST;
            }
            catch (Exception)
            {
                tbChampionName.Text = "No Champion Yet !";
            }
        }
예제 #2
0
        private void btStartStop_Click(object sender, RoutedEventArgs e)
        {
            if (btStartStop.Content.Equals("START") || btStartStop.Content.Equals("TRY AGAIN?"))
            {
                stopwatch.Reset();
                tbTimeDisplay.Text = startTimeDisplay;

                btStartStop.Content = "STOP";
                btDown.IsEnabled    = true;
                btUp.IsEnabled      = true;
                unsortedListString.Clear();
                usersList.Clear();
                userOrderLinkedList.Clear();
                sortedList.Clear();

                for (int i = 0; i < 10; i++)
                {
                    randomNumber = GenerateRandomNumber();
                    author       = GenerateRandomAuthor();
                    callNumber   = randomNumber + " " + author;

                    DataGridBind dgb = new DataGridBind
                    {
                        CALL_NUMBER = callNumber
                    };
                    unsortedListString.Insert(i, dgb);
                    usersList.Insert(i, dgb);
                }

                dgCallNumbers.Items.Clear();

                foreach (var callNumber in unsortedListString)
                {
                    DataGridBind dgb = new DataGridBind
                    {
                        CALL_NUMBER = callNumber.CALL_NUMBER
                    };


                    dgCallNumbers.Items.Add(dgb);
                }

                stopwatch.Start();
                timer.Start();
            }
            else if (btStartStop.Content.Equals("STOP"))
            {
                LearningGames lg = new LearningGames();

                string timeScore = tbTimeDisplay.Text;
                stopwatch.Stop();
                timer.Stop();


                for (int i = 0; i < 10; i++)
                {
                    DataGridBind dgb = new DataGridBind
                    {
                        CALL_NUMBER = usersList[i].CALL_NUMBER
                    };

                    userOrderLinkedList.AddLast(usersList[i].CALL_NUMBER.ToString());
                }

                SelectionSortUserBooks();

                foreach (var item in unsortedListString)
                {
                    sortedList.Add(item.CALL_NUMBER);
                }

                bool equal = userOrderLinkedList.SequenceEqual(sortedList);



                if (equal)
                {
                    ModelLeaderBoard ml = new ModelLeaderBoard
                    {
                        USER_LIBRARY_CARD_ID          = currentUser,
                        REPLACING_BOOKS_PERSONAL_BEST = timeScore
                    };

                    List <ModelLeaderBoard> getPersonalBest = lg.GetPersonalBestReplacingBooks(ml, connectionString);

                    if (pb.Equals("Not Set"))
                    {
                        List <ModelLeaderBoard> getLeaderBoardRecords = lg.GetAllLeadBoardRecords(connectionString);

                        if (getLeaderBoardRecords.Count == 0)
                        {
                            lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                            MessageBox.Show("Congratulations ! You won, set your first PERSONAL BEST and are the first CHAMPION for this game mode ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST !");
                        }
                        else if (TimeSpan.Compare(TimeSpan.Parse(timeScore), TimeSpan.Parse(ChampTime.ToString())) == -1)
                        {
                            lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                            MessageBox.Show("Congratulations ! You won, set your first PERSONAL BEST and are the new CHAMPION for this game mode ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST !");
                        }
                        else
                        {
                            lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                            MessageBox.Show("Congratulations ! You won and set your first PERSONAL BEST ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST !");
                        }

                        UpdateLeaderBoardPersonalBest();
                    }
                    else if (TimeSpan.Compare(TimeSpan.Parse(timeScore), TimeSpan.Parse(ChampTime.ToString())) == -1)
                    {
                        if (TimeSpan.Compare(TimeSpan.Parse(timeScore), TimeSpan.Parse(getPersonalBest[0].REPLACING_BOOKS_PERSONAL_BEST.ToString())) == -1)
                        {
                            lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                            MessageBox.Show("Congratulations ! You WON, beat your PERSONAL BEST time and are the new CHAMPION ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST for this game mode!");
                            UpdateLeaderBoardPersonalBest();
                        }
                        else
                        {
                            lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                            MessageBox.Show("Congratulations ! You WON and are the new CHAMPION ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST for this game mode!");
                            UpdateLeaderBoardPersonalBest();
                        }
                    }
                    else if (TimeSpan.Compare(TimeSpan.Parse(timeScore), TimeSpan.Parse(getPersonalBest[0].REPLACING_BOOKS_PERSONAL_BEST.ToString())) == -1)
                    {
                        lg.UpdateNewPersonalBestReplacingBooks(ml, connectionString);
                        MessageBox.Show("Congratulations ! You WON and beat your PERSONAL BEST time ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST or to become library CHAMPION for this game mode!");
                        UpdateLeaderBoardPersonalBest();
                    }
                    else
                    {
                        MessageBox.Show("Congratulations ! You WON ! It took you " + timeScore + " to complete the game! Try again to beat your PERSONAL BEST or to become library CHAMPION for this game mode!");
                    }
                }
                else
                {
                    MessageBox.Show("SORRY You LOSE ! Unfortunately the CALL NUMBER order was INCORRECT! TRY AGAIN to have another chance at WINNING this game mode !");
                }

                btStartStop.Content = "TRY AGAIN?";
            }
        }