// When the button is clicked, send the button's character to the initials // for it to be added void clickedButton() { // Get the Character from the Button Text char t = btnText.text.ToCharArray()[0]; HighscoreName hsScript = GameObject.Find("HighscoreCanvas") .GetComponent <HighscoreName>(); hsScript.addCharacterToName(t); }
private void RetryBtn_Click(object sender, EventArgs e) { // Logic for the objects depending on the lives if (lives > 0) { Score.Visible = true; GameOver.Visible = false; EndScore.Visible = false; RetryBtn.Visible = false; RetryBtn.Enabled = false; HighScore.Visible = false; HighScore.Enabled = false; PipeT.Visible = true; PipeB.Visible = true; Start(); } else { // On a new highscore, check the input if (NewHighscore.Visible == true) { using SqliteContext lite = new SqliteContext(); if (string.IsNullOrWhiteSpace(HighscoreName.Text)) { MessageBox.Show("Please enter a name!"); } else if (!Regex.IsMatch(HighscoreName.Text, "^[a-zA-Z0-9]*$")) { MessageBox.Show("Name must be alphanumeric and cannot contain spaces!"); } else if (HighscoreName.Text.Length > 16) { MessageBox.Show("Name cannot exceed 16 characters!"); } else if (lite.Highscores.Any(x => x.Name.ToLower() == HighscoreName.Text.ToLower())) { MessageBox.Show("That name already exists!"); } else { MessageBox.Show("Your highscore has been submitted!"); // Check highscores and delete the latest and lowest score var lowestScore = lite.Highscores.OrderByDescending(x => x.Score).Select(z => z.Id).LastOrDefault(); if (lite.Highscores.Count() >= 10) { lite.Highscores.Remove(lite.Highscores.OrderByDescending(x => x.Id == lowestScore).FirstOrDefault()); } // Create instance for the new highscore var highscore = new Highscores { Name = HighscoreName.Text, Score = endCount, Time = DateTime.UtcNow }; // Add the new highscore and save it to the database lite.Highscores.Add(highscore); lite.SaveChanges(); // Clear the text field HighscoreName.Clear(); // Go to game menu Menu(); Start(); } } else { // Go to game menu Menu(); Start(); } } }