private void singlePlayer(object sender, RoutedEventArgs e) { if (playerID == -1) { CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); customMessageBox.ShowText("Please login to continue"); } else { GameRepository gameRepository = new GameRepository(); PlayersRepository playersRepository = new PlayersRepository(); if (gameRepository.GetGame(playerID).Count > 0) { LoadGame loadGame = new LoadGame(kinectSensorChooser, playerID); loadGame.ShowDialog(); } else { GameMode gameMode = new GameMode(kinectSensorChooser, playerID); gameMode.ShowDialog(); } PersonalBestValue.Text = playersRepository.GetPlayerScore(playerID).ToString(); } }
public void UpdatePersonalBest(int playerID, int latestScore) { PlayersRepository playersRepository = new PlayersRepository(); int storedScore = playersRepository.GetPlayerScore(playerID); if (storedScore < latestScore) { playersRepository.ModifyPlayerScore(playerID, latestScore); } }
private void login(object sender, RoutedEventArgs e) { if (playerID == -1) { // No user logged in, proceed to show login screen Login login = new Login(kinectSensorChooser); playerID = login.CustomShowDialog(); } else { // A user is logged in, prompt current user to logout before a new login Logout logout = new Logout(kinectSensorChooser, playerID); if (logout.CustomShowDialog()) { // Reset player ID playerID = -1; // User logged out, proceed to show login screen Login login = new Login(kinectSensorChooser); playerID = login.CustomShowDialog(); PersonalBestValue.Visibility = Visibility.Hidden; PersonalBestText.Visibility = Visibility.Hidden; } } // If logged in, get highest score if (playerID != -1) { PlayersRepository playersRepository = new PlayersRepository(); playerScore = playersRepository.GetPlayerScore(playerID); PersonalBestValue.Text = playerScore.ToString(); PersonalBestValue.Visibility = Visibility.Visible; PersonalBestText.Visibility = Visibility.Visible; } else { PersonalBestValue.Visibility = Visibility.Hidden; PersonalBestText.Visibility = Visibility.Hidden; } }
public HighScore(KinectSensorChooser kinectSensorChooser, int gameMode) { InitializeComponent(); // Set screen to center WindowStartupLocation = WindowStartupLocation.CenterScreen; // Set values this.kinectSensorChooser = kinectSensorChooser; this.gameMode = gameMode; // Data binding var kinectRegionandSensorBinding = new Binding("Kinect") { Source = kinectSensorChooser }; BindingOperations.SetBinding(kinectKinectRegion, KinectRegion.KinectSensorProperty, kinectRegionandSensorBinding); // Set title if (gameMode == 0) { Title = "Survival Mode Highscore"; } else if (gameMode == 1) { Title = "Time Attack Mode Highscore"; } // Set highscore text var textHeader = new Label { Content = "Name\t\t\t\t\t\t\t\t\t" + "Score", FontWeight = FontWeights.Bold, FontSize = 26 }; scrollContent.Children.Add(textHeader); ScoreRepository sro = new ScoreRepository(); PlayersRepository pro = new PlayersRepository(); var highscore = sro.GetAllScore(gameMode); for (int i = highscore.Count - 1; i >= 0; i--) { List <PlayersRepository.PlayerDto> user = pro.GetPlayerWithId(highscore[i].PlayerScore); string name = ""; if (user.Count == 1) { name = user[0].Username; } var textBody = new Label { FontSize = 26, Content = " " + name + "\t\t\t\t\t\t\t\t\t" + highscore[i].Value }; scrollContent.Children.Add(textBody); } #region KinectRegion // Setup Kinect region press target and event handlers KinectRegion.SetIsPressTarget(back, true); KinectRegion.AddHandPointerEnterHandler(back, HandPointerEnterEvent); KinectRegion.AddHandPointerLeaveHandler(back, HandPointerLeaveEvent); KinectRegion.AddHandPointerPressHandler(back, HandPointerPressEvent); KinectRegion.AddHandPointerPressReleaseHandler(back, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerGotCaptureHandler(back, HandPointerCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(back, HandPointerLostCaptureEvent); #endregion }
private void login(object sender, RoutedEventArgs e) { // Setup custom message box CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); // Check if username entered is at least 3 characters long if (textBoxUsername.Text.Length < 3) { // Show error message dialog customMessageBox.ShowText("Username is at least 3 characters long!"); } // Check password length is at least 3 characters long else if (passwordBox.Password.Length < 3) { // Show error message dialog customMessageBox.ShowText("Password is at least 3 characters long!"); } else { // Create the player repository object PlayersRepository pro = new PlayersRepository(); // Hash the password SHA256 sha256 = SHA256.Create(); byte[] bytes = Encoding.UTF8.GetBytes(passwordBox.Password); byte[] hash = sha256.ComputeHash(bytes); StringBuilder result = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { result.Append(hash[i].ToString("X2")); } // Search database for this username List <PlayersRepository.PlayerDto> player = pro.GetPlayerWithUsername(textBoxUsername.Text); // If player exist if (player.Count == 1) { // If password match then log them in if (result.ToString().Contains(player[0].Password)) { // Retrieve and save the player ID playerID = player[0].Id; // Show dialog that the login is successful customMessageBox.ShowText("Successfully logged in"); // Close after succesfully logged in Close(); } else { // Show dialog that the login is not successful customMessageBox.ShowText("Password is incorrect!"); // Clear the incorrect password passwordBox.Password = ""; } } else { // Show dialog that the login is not successful customMessageBox.ShowText("Player doesn't exist!"); } } }
// Execute press functions private void HandPointerPressReleaseEvent(object sender, HandPointerEventArgs e) { if (capturedHandPointer == e.HandPointer) { if (e.HandPointer.GetIsOver(btnCancelLogin)) { Close(); VisualStateManager.GoToState(btnCancelLogin, "MouseOver", true); } else if (e.HandPointer.GetIsOver(btnLogin)) { // Setup custom message box CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); // Check if username entered is at least 3 characters long if (textBoxUsername.Text.Length < 3) { // Show error message dialog customMessageBox.ShowText("Username is at least 3 characters long!"); } // Check password length is at least 3 characters long else if (passwordBox.Password.Length < 3) { // Show error message dialog customMessageBox.ShowText("Password is at least 3 characters long!"); } else { // Create the player repository object PlayersRepository pro = new PlayersRepository(); // Hash the password SHA256 sha256 = SHA256.Create(); byte[] bytes = Encoding.UTF8.GetBytes(passwordBox.Password); byte[] hash = sha256.ComputeHash(bytes); StringBuilder result = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { result.Append(hash[i].ToString("X2")); } // Search database for this username List <PlayersRepository.PlayerDto> player = pro.GetPlayerWithUsername(textBoxUsername.Text); // If player exist if (player.Count == 1) { // If password match then log them in if (result.ToString().Contains(player[0].Password)) { // Retrieve and save the player ID playerID = player[0].Id; // Show dialog that the login is successful customMessageBox.ShowText("Successfully logged in"); // Close after succesfully logged in Close(); } else { // Show dialog that the login is not successful customMessageBox.ShowText("Password is incorrect!"); // Clear the incorrect password passwordBox.Password = ""; } } else { // Show dialog that the login is not successful customMessageBox.ShowText("Player doesn't exist!"); } } VisualStateManager.GoToState(btnLogin, "MouseOver", true); } else if (e.HandPointer.GetIsOver(textBoxUsername)) { textBoxUsername.Focus(); VisualStateManager.GoToState(textBoxUsername, "MouseOver", true); } else if (e.HandPointer.GetIsOver(passwordBox)) { passwordBox.Focus(); VisualStateManager.GoToState(passwordBox, "MouseOver", true); } else { try { if (e.HandPointer.GetIsOver((Button)sender)) { Button button = null; try { button = (Button)sender; } catch (Exception) { } if (button.Equals(btnA)) { keyPressed = 'a'; } else if (button.Equals(btnB)) { keyPressed = 'b'; } else if (button.Equals(btnC)) { keyPressed = 'c'; } else if (button.Equals(btnD)) { keyPressed = 'd'; } else if (button.Equals(btnE)) { keyPressed = 'e'; } else if (button.Equals(btnF)) { keyPressed = 'f'; } else if (button.Equals(btnG)) { keyPressed = 'g'; } else if (button.Equals(btnH)) { keyPressed = 'h'; } else if (button.Equals(btnI)) { keyPressed = 'i'; } else if (button.Equals(btnJ)) { keyPressed = 'j'; } else if (button.Equals(btnK)) { keyPressed = 'k'; } else if (button.Equals(btnL)) { keyPressed = 'l'; } else if (button.Equals(btnM)) { keyPressed = 'm'; } else if (button.Equals(btnN)) { keyPressed = 'n'; } else if (button.Equals(btnO)) { keyPressed = 'o'; } else if (button.Equals(btnP)) { keyPressed = 'p'; } else if (button.Equals(btnQ)) { keyPressed = 'q'; } else if (button.Equals(btnR)) { keyPressed = 'r'; } else if (button.Equals(btnS)) { keyPressed = 's'; } else if (button.Equals(btnT)) { keyPressed = 't'; } else if (button.Equals(btnU)) { keyPressed = 'u'; } else if (button.Equals(btnV)) { keyPressed = 'v'; } else if (button.Equals(btnW)) { keyPressed = 'w'; } else if (button.Equals(btnX)) { keyPressed = 'x'; } else if (button.Equals(btnY)) { keyPressed = 'y'; } else if (button.Equals(btnZ)) { keyPressed = 'z'; } else if (button.Equals(btnBackspace)) { keyPressed = '\b'; } if (textBoxUsername.IsFocused) { int usernameCaretIndex = textBoxUsername.CaretIndex; if (keyPressed == '\b' && textBoxUsername.Text.Length > 0) { textBoxUsername.Text = textBoxUsername.Text.Remove(usernameCaretIndex - 1, 1); textBoxUsername.CaretIndex = usernameCaretIndex - 1; } else { textBoxUsername.Text = textBoxUsername.Text.Insert(usernameCaretIndex, keyPressed.ToString()); textBoxUsername.CaretIndex = usernameCaretIndex + 1; } } else if (passwordBox.IsFocused) { // Due to security reason, caret index of passwordbox is not retrievable if (keyPressed == '\b' && passwordBox.Password.Length > 0) { // Remove all password passwordBox.Password = ""; } else { // Use TextCompositionManager to input at current caret TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, passwordBox, keyPressed.ToString())); } } } else { VisualStateManager.GoToState(btnCancelLogin, "Normal", true); VisualStateManager.GoToState(btnLogin, "Normal", true); VisualStateManager.GoToState(textBoxUsername, "Normal", true); VisualStateManager.GoToState(passwordBox, "Normal", true); VisualStateManager.GoToState(btnA, "Normal", true); VisualStateManager.GoToState(btnB, "Normal", true); VisualStateManager.GoToState(btnC, "Normal", true); VisualStateManager.GoToState(btnD, "Normal", true); VisualStateManager.GoToState(btnE, "Normal", true); VisualStateManager.GoToState(btnF, "Normal", true); VisualStateManager.GoToState(btnH, "Normal", true); VisualStateManager.GoToState(btnI, "Normal", true); VisualStateManager.GoToState(btnJ, "Normal", true); VisualStateManager.GoToState(btnK, "Normal", true); VisualStateManager.GoToState(btnL, "Normal", true); VisualStateManager.GoToState(btnM, "Normal", true); VisualStateManager.GoToState(btnN, "Normal", true); VisualStateManager.GoToState(btnO, "Normal", true); VisualStateManager.GoToState(btnP, "Normal", true); VisualStateManager.GoToState(btnQ, "Normal", true); VisualStateManager.GoToState(btnR, "Normal", true); VisualStateManager.GoToState(btnS, "Normal", true); VisualStateManager.GoToState(btnT, "Normal", true); VisualStateManager.GoToState(btnU, "Normal", true); VisualStateManager.GoToState(btnV, "Normal", true); VisualStateManager.GoToState(btnW, "Normal", true); VisualStateManager.GoToState(btnX, "Normal", true); VisualStateManager.GoToState(btnY, "Normal", true); VisualStateManager.GoToState(btnZ, "Normal", true); VisualStateManager.GoToState(btnBackspace, "Normal", true); } } catch (Exception) { } } e.HandPointer.Capture(null); e.Handled = true; } }
// Execute press function private void OnHandPointerPressRelease(object sender, HandPointerEventArgs e) { if (capturedHandPointer == e.HandPointer) { e.HandPointer.Capture(null); if (e.HandPointer.GetIsOver(btn_login)) { VisualStateManager.GoToState(btn_login, "MouseOver", true); if (playerID == -1) { // No user logged in, proceed to show login screen Login login = new Login(kinectSensorChooser); playerID = login.CustomShowDialog(); } else { // A user is logged in, prompt current user to logout before a new login Logout logout = new Logout(kinectSensorChooser, playerID); if (logout.CustomShowDialog()) { PersonalBestValue.Visibility = Visibility.Hidden; PersonalBestText.Visibility = Visibility.Hidden; // Reset player ID playerID = -1; // User logged out, proceed to show login screen Login login = new Login(kinectSensorChooser); playerID = login.CustomShowDialog(); } } // If logged in, get highest score if (playerID != -1) { PlayersRepository playersRepository = new PlayersRepository(); playerScore = playersRepository.GetPlayerScore(playerID); PersonalBestValue.Text = playerScore.ToString(); PersonalBestValue.Visibility = Visibility.Visible; PersonalBestText.Visibility = Visibility.Visible; } else { PersonalBestValue.Visibility = Visibility.Hidden; PersonalBestText.Visibility = Visibility.Hidden; } } else if (e.HandPointer.GetIsOver(btn_register)) { VisualStateManager.GoToState(btn_register, "MouseOver", true); if (playerID == -1) { // No user logged in, proceed to show register screen Register register = new Register(kinectSensorChooser); register.ShowDialog(); } else { // A user is logged in, prompt current user to logout before a new registration Logout logout = new Logout(kinectSensorChooser, playerID); if (logout.CustomShowDialog()) { // Reset player ID playerID = -1; PersonalBestValue.Visibility = Visibility.Hidden; PersonalBestText.Visibility = Visibility.Hidden; // User logged out, proceed to show register screen Register register = new Register(kinectSensorChooser); register.ShowDialog(); } } } else if (e.HandPointer.GetIsOver(btn_singlePlayer)) { VisualStateManager.GoToState(btn_singlePlayer, "MouseOver", true); if (playerID == -1) { CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); customMessageBox.ShowText("Please login to continue"); } else { GameRepository gameRepository = new GameRepository(); if (gameRepository.GetGame(playerID).Count > 0) { LoadGame loadGame = new LoadGame(kinectSensorChooser, playerID); loadGame.ShowDialog(); } else { GameMode gameMode = new GameMode(kinectSensorChooser, playerID); gameMode.ShowDialog(); } } } else if (e.HandPointer.GetIsOver(btn_multiPlayer)) { VisualStateManager.GoToState(btn_multiPlayer, "MouseOver", true); // Multiplayer doesnt need login, player ID = -1 GameMode gameMode = new GameMode(kinectSensorChooser, -1); gameMode.ShowDialog(); } else if (e.HandPointer.GetIsOver(btn_loadGame)) { VisualStateManager.GoToState(btn_loadGame, "MouseOver", true); if (playerID == -1) { CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); customMessageBox.ShowText("Please login to continue"); } else { GameRepository gameRepository = new GameRepository(); List <GameRepository.GameDto> getGame = gameRepository.GetGame(playerID); if (getGame.Count == 0) { // No game saved, display the dialog CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser); customMessageBox.ShowText("You have no saved game!"); } else { // Load the game kinectSensorChooser.Stop(); DragDropImages dragDropImages = new DragDropImages(playerID, getGame[0].GameMode); dragDropImages.GetLoadGameData(getGame[0].Lives, getGame[0].Time, getGame[0].Score, getGame[0].ItemGame); dragDropImages.ShowDialog(); kinectSensorChooser.Start(); } } } else if (e.HandPointer.GetIsOver(btn_highScores)) { VisualStateManager.GoToState(btn_highScores, "MouseOver", true); GameMode gameMode = new GameMode(kinectSensorChooser, playerID, 0); gameMode.ShowDialog(); } else if (e.HandPointer.GetIsOver(btn_help)) { VisualStateManager.GoToState(btn_help, "MouseOver", true); Help help = new Help(kinectSensorChooser); help.ShowDialog(); } else if (e.HandPointer.GetIsOver(btn_exit)) { VisualStateManager.GoToState(btn_exit, "MouseOver", true); Close(); } else { VisualStateManager.GoToState(btn_login, "Normal", true); VisualStateManager.GoToState(btn_register, "Normal", true); VisualStateManager.GoToState(btn_singlePlayer, "Normal", true); VisualStateManager.GoToState(btn_multiPlayer, "Normal", true); VisualStateManager.GoToState(btn_loadGame, "Normal", true); VisualStateManager.GoToState(btn_highScores, "Normal", true); VisualStateManager.GoToState(btn_help, "Normal", true); VisualStateManager.GoToState(btn_exit, "Normal", true); } e.Handled = true; } }