public void SubmitScore() { if (nameField.text != "") { HighscoreEntry entry = new HighscoreEntry(score, nameField.text); Highscores.AddScore(pos, entry, Highscores.LoadScores()); gameObject.SetActive(false); } }
// void Start() // { // HighscoreList highscores = Highscores.LoadScores(); // highscoreList = highscores.scoreList; // if (highscoreList.Count == 0) // { // AddHighScoreEntry(25000, "President Josephy"); // AddHighScoreEntry(15000, "Rosko"); // AddHighScoreEntry(10000, "Josh"); // AddHighScoreEntry(9000, "Billy"); // AddHighScoreEntry(8000, "Mole man"); // AddHighScoreEntry(7000, "A cheater"); // AddHighScoreEntry(6000, "Josh again"); // AddHighScoreEntry(5000, "Gun is OP"); // AddHighScoreEntry(3000, "A bush"); // AddHighScoreEntry(1000, "One of the babies"); // // highscores = Highscores.LoadScores(); // // highscoreList = highscores.scoreList; // } // } void Awake() { entryContainer = transform.Find("highscoreEntryContainer"); entryTemplate = entryContainer.Find("highscoreEntryTemplate"); entryTemplate.gameObject.SetActive(false); // AddHighScoreEntry(999999, "Josephy"); // AddHighScoreEntry(888888, "Rosko"); // AddHighScoreEntry(777777, "Mole man"); // AddHighScoreEntry(555555, "Billy"); // AddHighScoreEntry(666666, "Thomas"); // AddHighScoreEntry(6, "Josh the 2nd"); // AddHighScoreEntry(5, "Josh again"); // AddHighScoreEntry(4, "Still Josh"); // AddHighScoreEntry(3, "Not Josh"); // AddHighScoreEntry(2, "Ok, it's josh"); // AddHighScoreEntry(3, "This really isn't josh"); // AddHighScoreEntry(3, "Josh returns"); // AddHighScoreEntry(1000000, "Better than \\/"); HighscoreList highscores = Highscores.LoadScores(); highscoreList = highscores.scoreList; if (highscoreList.Count == 0) { AddHighScoreEntry(25000, "President Josephy"); AddHighScoreEntry(15000, "Rosko"); AddHighScoreEntry(10000, "Josh"); AddHighScoreEntry(9000, "Billy"); AddHighScoreEntry(8000, "Mole man"); AddHighScoreEntry(7000, "A cheater"); AddHighScoreEntry(6000, "Josh again"); AddHighScoreEntry(5000, "Gun is OP"); AddHighScoreEntry(3000, "A bush"); AddHighScoreEntry(1000, "One of the babies"); highscores = Highscores.LoadScores(); highscoreList = highscores.scoreList; } highscoreEntryTransformList = new List <Transform>(); foreach (HighscoreEntry entry in highscoreList) { CreateHighscoreEntry(entry, entryContainer, highscoreEntryTransformList); } }
private void AddHighScoreEntry(int score, string name) { // Create entry HighscoreEntry entry = new HighscoreEntry(score, name); // Load highscore table HighscoreList highscores = Highscores.LoadScores(); int pos = Highscores.CheckScore(score, highscores.scoreList); if (pos != -1 && pos != 10) { Highscores.AddScore(pos, entry, highscores); } else { print("Score " + score + " too low. Discarding."); } Highscores.SaveScores(highscores); }
void Update() { if (Input.GetButtonDown("Pickup")) { if (field == fields.Return) // If the score tally has been finished { // Return to the menu, but only if the highscore prompt is not open if (!highscorePrompt.gameObject.activeInHierarchy) { GameManager.instance.ReturnToMenu(); } } else // Skip the tally { skipped = true; timer = duration + 1; } } // Increment timer for score tallying timer += Time.deltaTime; if (timer > duration) { // Set text fields active // There are two switch statements for the same condition because // these cases execute at the end of the timer, while the other ones // need to execute throughout the timer. switch (field) { case fields.Condition: // Completion Condition and Reason if (GameManager.isVictory) { // Debug.Log("YOU WON!"); completionCondtionText.text = "Victory"; completionReasonText.text = "You got to the 'choppa"; } else { // Debug.Log("YOU LOST!"); completionCondtionText.text = "Defeat"; completionReasonText.text = "You were devoured by moles"; } ActivateField(completionCondtionText); break; case fields.Reason: ActivateField(completionReasonText); break; case fields.Score: ActivateField(scoreText); break; case fields.Wait: // Adds a delay between score showing up and the tally starting duration = 1.5f; break; case fields.Return: // ActivateField(returnText); duration = 0f; if (!returnText.gameObject.activeInHierarchy) { returnText.gameObject.SetActive(true); audio.clip = returnSound; audio.Play(); Cursor.lockState = CursorLockMode.None; // If score is a highscore, prompt for name and save score if (isHighScore) { // Cursor.visible = false; highscorePrompt.gameObject.SetActive(true); highscorePrompt.score = score; highscorePrompt.pos = rank; } } break; } // Reset timer unless skipped if (!skipped) { timer = 0; } if (field != fields.Return) { field++; // Move on to the next field when this one is finished } } // Tally the current field switch (field) { case fields.Waves: // Waves TallyField(WaveSpawner.nextWave, wavesText, "Waves Survived: ", GameStats.WAVE_SCORE); break; case fields.ChildrenSaved: // Children Saved TallyField(GameStats.childrenSaved, childrenSavedText, "Children Saved: ", GameStats.CHILD_SCORE); break; case fields.Kills: // Kills TallyField(GameManager.kills, killsText, "Kills: ", GameStats.KILL_SCORE); break; case fields.Damage: // Damage TallyField(GameManager.damage, damageText, "Damage Dealt: ", 1f); // score += scoreTally; duration = .25f; break; case fields.HighScore: // HighScore HighscoreList list = Highscores.LoadScores(); if (!HighScoreText.gameObject.activeInHierarchy) { // print(score); score += scoreTally; // print (score); int pos = Highscores.CheckScore(score, list.scoreList); // int pos = Highscores.CheckScore(50001, list.scoreList); if (pos != -1 && pos != 10) { // You made it to the highscore list! // Highscores.AddScore(pos, entry, highscores); isHighScore = true; rank = pos; // Play sound audio.clip = textSound; audio.Play(); // Display message if (pos == 0) { // You got 1st place! HighScoreText.text = "You got 1st place!\n" + "You were ahead by " + list.scoreList[pos + 1].score + "points!"; } else { HighScoreText.text = "You got " + Highscores.AddOrdinal(pos + 1) + " place!\n" + "The next highest score is " + list.scoreList[pos].score + "."; } // Set highscore text fields to active NewText.gameObject.SetActive(true); HighScoreText.gameObject.SetActive(true); } else { // Better luck next time. print("Score " + score + " too low. You didn't make the cut."); } } // if ((score + scoreTally) > PlayerPrefs.GetInt("HighScore")) // { // PlayerPrefs.SetInt("HighScore", (score + scoreTally)); // NewText.gameObject.SetActive(true); // } // TallyField(PlayerPrefs.GetInt("HighScore"), HighScoreText, "HighScore: ", 0); break; } }