//Allows the user to view the HighscoreForm private void btnScores_Click(object sender, EventArgs e) { this.Hide(); //Hides the MenuForm as it is the MainForm for the application HighscoreForm highscoreForm = new HighscoreForm(); highscoreForm.Show(); }
//Manages the end of the game by updating players' scores and saving them to file private void endOfGame() { if (player1.Score == player2.Score) { MessageBox.Show("It's a draw!", "All Pairs Found"); } else if (player1.Score > player2.Score) { MessageBox.Show(player1.Username + " wins!", "All Pairs Found"); } else { MessageBox.Show(player2.Username + " wins!", "All Pairs Found"); } //Update the players' scores if (btnCards.Count() == 18) //i.e. if playing in easy mode { player1.ScoresEasy.Add(player1.Score); player1.Score = 0; if (player2.Username != "CPU") //skips player 2 if in 1 player mode { player2.ScoresEasy.Add(player2.Score); player2.Score = 0; } } else //i.e. if playing in hard mode { player1.ScoresHard.Add(player1.Score); player1.Score = 0; if (player2.Username != "CPU") //skips player 2 if in 1 player mode { player2.ScoresHard.Add(player2.Score); player2.Score = 0; } } //saves the players' scores to file if (!Player.UpdatePlayer(player1)) //if player not found then append to file { Player.AppendNewPlayer(player1); } if (player2.Username != "CPU") //skips player 2 if in 1 player mode { if (!Player.UpdatePlayer(player2)) //if player not found then append to file { Player.AppendNewPlayer(player2); } } //Closes the GameForm and opens the HighscoreForm to show the top scores this.Close(); HighscoreForm highscoreForm = new HighscoreForm(); highscoreForm.Show(); }