// Getting BlindtestClass Object from MainPage, then loading list of users protected override void OnNavigatedTo(NavigationEventArgs e) { // If a parameter is given, and if it's a BlindtestClass element if (e.Parameter is BlindtestClass) { // Get main element var bt = e.Parameter; blindtest = (BlindtestClass)bt; // Getting user and game information connected_user = blindtest.getConnectedUser(); selected_game = blindtest.getSelectedGame(); // loading game info in UI, and filling listView with tracks according to datatemplate gameInformation_label.Text = "List of tracks - " + selected_game.game_title; ObservableCollection <DeezerTrack> listItems = new ObservableCollection <DeezerTrack>(); foreach (DeezerTrack track in selected_game.tracklist) { listItems.Add(track); } tracklist_listView.ItemsSource = listItems; // Loading scoreboard for this game foreach (BTGameHistory history in selected_game.scores.history) { BTScoreboard score = new BTScoreboard(); score.username = "******"; score.profile_picture = "ms-appx:///Assets/Users/unselected-user.png"; foreach (BTUser user in blindtest.getAllUsers()) { if (user.user_id == history.user_id) { score.username = user.nickname; score.profile_picture = user.profile_picture; } } score.date = history.date; score.score = history.score.ToString(); scoreboard.Add(score); } // Filling scoreboard listView with scores loaded before according to dataTemplate ObservableCollection <BTScoreboard> listItems2 = new ObservableCollection <BTScoreboard>(); foreach (BTScoreboard score in scoreboard) { listItems2.Add(score); } scoreboard_listView.ItemsSource = listItems2; } }
// Getting BlindtestClass Object from MainPage, then loading list of users protected override void OnNavigatedTo(NavigationEventArgs e) { // If a parameter is given, and if it's a BlindtestClass element if (e.Parameter is BlindtestClass) { // Get main element var bt = e.Parameter; blindtest = (BlindtestClass)bt; selected_game = blindtest.getSelectedGame(); gameInformation_label.Text = "List of tracks - " + selected_game.game_title; // Loading every score history entry in dedicated listView, and loading UI elements ObservableCollection <DeezerTrack> listItems = new ObservableCollection <DeezerTrack>(); description_label.Text = "Here is the scoreboard for '" + selected_game.game_title + "' game! Just click on an entry to see all of it's details!"; gameInformation_label.Text = "Scoreboard - " + selected_game.game_title; maximum_score = (selected_game.scores.title * selected_game.tracklist.Count) + (selected_game.scores.artist * selected_game.tracklist.Count) + (selected_game.scores.album * selected_game.tracklist.Count) + (selected_game.scores.duration * selected_game.tracklist.Count); maxScore_label.Text = maximum_score.ToString() + " points"; foreach (BTGameHistory history in selected_game.scores.history) { BTScoreboard score = new BTScoreboard(); score.username = "******"; score.profile_picture = "ms-appx:///Assets/Users/unselected-user.png"; score.user_id = history.user_id; foreach (BTUser user in blindtest.getAllUsers()) { if (user.user_id == history.user_id) { score.username = user.nickname; score.profile_picture = user.profile_picture; } } score.date = history.date; score.score = history.score.ToString(); scoreboard.Add(score); } ObservableCollection <BTScoreboard> listItems2 = new ObservableCollection <BTScoreboard>(); foreach (BTScoreboard score in scoreboard) { listItems2.Add(score); } scoreboard_listView.ItemsSource = listItems2; } }
// Getting BlindtestClass Object from MainPage, then loading list of users protected override void OnNavigatedTo(NavigationEventArgs e) { // If a parameter is given, and if it's a BlindtestClass element if (e.Parameter is BlindtestClass) { // Get main element var bt = e.Parameter; blindtest = (BlindtestClass)bt; // Loading UI elements and filling scoreboard listView connected_user = blindtest.getConnectedUser(); selected_game = blindtest.getSelectedGame(); correctAnswers_label.Text = "Correct Answers - " + selected_game.game_title; gameStatus_label.Text = "Game in progress..."; foreach (BTGameHistory history in selected_game.scores.history) { BTScoreboard score = new BTScoreboard(); score.username = "******"; score.profile_picture = "ms-appx:///Assets/Users/unselected-user.png"; foreach (BTUser user in blindtest.getAllUsers()) { if (user.user_id == history.user_id) { score.username = user.nickname; score.profile_picture = user.profile_picture; } } score.date = history.date; score.score = history.score.ToString(); scoreboard.Add(score); } ObservableCollection <BTScoreboard> listItems2 = new ObservableCollection <BTScoreboard>(); foreach (BTScoreboard score in scoreboard) { listItems2.Add(score); } scoreboard_listView.ItemsSource = listItems2; // Launching the game is_album_correct = false; is_artist_correct = false; is_duration_correct = false; is_title_correct = false; score = 0; // Loading tracklist foreach (DeezerTrack track in selected_game.tracklist) { tracklist_src.Add(track); } nbr_track = tracklist_src.Count; total_tracks = tracklist_src.Count; current_track_int = 1; songStatus_label.Text = "Track " + current_track_int.ToString() + " of " + total_tracks.ToString(); Random random = new Random(); int random_int = random.Next(0, nbr_track - 1); current_track = tracklist_src[random_int]; tracklist_src.Remove(current_track); gameStatus_label.Text = "Game in progress... - score : " + score.ToString() + " points"; blindtest.readPreview(current_track); total_correct_answer = 0; } }
// Next song button private void NextSong_button_Click(object sender, RoutedEventArgs e) { // stop previous track preview blindtest.pausePreview(); // Resetting ui elements and local info total_correct_answer = 0; title_label.Text = "not found yet!"; artist_label.Text = "not found yet!"; album_label.Text = "not found yet!"; duration_label.Text = "not found yet!"; BitmapImage bmpImg = new BitmapImage(); bmpImg.UriSource = new Uri("ms-appx:///Assets/default-track.png"); selectedTrack_Image.Source = bmpImg; current_track_int++; is_album_correct = false; is_artist_correct = false; is_duration_correct = false; is_title_correct = false; // If there is still tracks to play if (current_track_int <= total_tracks) { // Editing status label songStatus_label.Text = "Track " + current_track_int.ToString() + " of " + total_tracks.ToString(); nbr_track--; // Selecting random track in the list Random random = new Random(); int random_int = random.Next(0, nbr_track - 1); current_track = tracklist_src[random_int]; tracklist_src.Remove(current_track); // Reading preview gameStatus_label.Text = "Game in progress... - score : " + score.ToString() + " points"; blindtest.readPreview(current_track); total_correct_answer = 0; } // When all tracks have been played else { // Showing final score to user gameStatus_label.Text = "Game finished! - Final score : " + score.ToString() + " points"; // Creating history entry BTGameHistory history_entry = new BTGameHistory(); history_entry.user_id = connected_user.user_id; history_entry.score = score; DateTime time = DateTime.Now; history_entry.date = time.ToString(); // Adding score entry to database blindtest.addScore(selected_game, history_entry); // Locking UI elements answer_button.IsEnabled = false; answer_textBox.IsEnabled = false; nextSong_button.IsEnabled = false; downloadStatusTimer.Stop(); playPreview_button.IsEnabled = false; stopPreview_button.IsEnabled = false; // Clear scoreboard listview ObservableCollection <BTScoreboard> listItems2 = new ObservableCollection <BTScoreboard>(); scoreboard_listView.ItemsSource = listItems2; // Reloading scoreboard in listView BTScoreboard scoreboard_entry = new BTScoreboard(); scoreboard_entry.date = history_entry.date; scoreboard_entry.profile_picture = connected_user.profile_picture; scoreboard_entry.score = history_entry.score.ToString(); scoreboard_entry.username = connected_user.nickname; scoreboard.Add(scoreboard_entry); foreach (BTScoreboard score in scoreboard) { listItems2.Add(score); } scoreboard_listView.ItemsSource = listItems2; } }