/// <summary> /// The highscore windows ctor /// </summary> /// <param name="mainMenu"></param> public HighScoreWindow(MainMenuWindow mainMenu) { InitializeComponent(); DataContext = this; try { Top10Scores = ScoreManager.GetTop10Scores(); Value = ScoreManager.GetLastScore().Value; this.mainMenu = mainMenu; soundPlayer.SoundLocation = "Resources/Audio/StarWarsThemeEnd.wav"; } catch (Exception ex) { ex.Log(); } }
/// <summary> /// Will attempt to log the user in on button press /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, RoutedEventArgs e) { string username = txtUsername.Text; int age = 0; try { if (!int.TryParse(txtAge.Text, out age)) { throw new ArgumentException(); } if (age > 0) { if (Controllers.UserManager.LoginUser(username, age).Status == Utilities.OperationStatus.Success) { Console.WriteLine("The user was logged into the application!"); MainMenuWindow mainMenu = new MainMenuWindow(this); mainMenu.Show(); this.Hide(); } else { // Alert the user that they could not be loged in Console.WriteLine("The user could not be logged into the application!"); } } else { Console.WriteLine("The user entered an invalid age <= 0."); ErrorOutput.Visibility = Visibility.Visible; tbkErrorOutput.Text = "ERROR: Invalid user data, please enter a value above 0."; } } catch (ArgumentException argEx) { // Tell the user they entered invalid data ErrorOutput.Visibility = Visibility.Visible; tbkErrorOutput.Text = "ERROR: Invalid user data, please use only numeric values for your age."; } catch (Exception ex) { ErrorOutput.Visibility = Visibility.Visible; tbkErrorOutput.Text = "ERROR: Unknown System Error. Please see error log."; ex.Log(); } }
/// <summary> /// Game window ctor /// </summary> /// <param name="mainMenu"></param> /// <param name="gameType"></param> public GameWindow(MainMenuWindow mainMenu, GameType gameType) { InitializeComponent(); DataContext = this; try { this.mainMenu = mainMenu; txtUserAnswer.Focus(); SetImage(gameType); uiUpdateTimer.Interval = TIMER_REFRESH_RATE_MILLI; uiUpdateTimer.Elapsed += UpdateUiElapsed; currentGame = gameManager.CreateGame(gameType); } catch (Exception ex) { ex.Log(); } }