private void Awake() { BestScoreEntry bestScoreEntry = new BestScoreEntry { score = points, name = namedisplay }; string JSONstring = File.ReadAllText(path); HighScoreTable highScoreTable = JsonUtility.FromJson <HighScoreTable>(JSONstring); if (highScoreTable == null) { highScoreTable = new HighScoreTable() { ScoreList = new List <BestScoreEntry>() }; } highScoreTable.ScoreList.Add(bestScoreEntry); for (int i = 0; i < highScoreTable.ScoreList.Count; i++) { for (int j = i + 1; j < highScoreTable.ScoreList.Count; j++) { if (highScoreTable.ScoreList[j].score > highScoreTable.ScoreList[i].score) { BestScoreEntry temp = highScoreTable.ScoreList[i]; highScoreTable.ScoreList[i] = highScoreTable.ScoreList[j]; highScoreTable.ScoreList[j] = temp; } } } string JSON = JsonUtility.ToJson(highScoreTable); File.WriteAllText(path, JSON); ScoreDisplay(highScoreTable); }
/// <summary> /// Gets or creates a high score table for the current game /// settings. /// </summary> public HighScoreTable GetTable(Config config) { // Go through the list foreach (HighScoreTable table in Tables) { // See if it matches if (config.SelectionType == table.SelectionType && config.BoardSize == table.BoardSize && config.LanguageName == table.LanguageName) { // This is it return table; } } // Create a new one HighScoreTable hst = new HighScoreTable(); hst.SelectionType = config.SelectionType; hst.BoardSize = config.BoardSize; hst.LanguageName = config.LanguageName; // Add and return it Tables.Add(hst); return hst; }
private void ParseScoreData(string data, ScoreEntry.ScoreType scoreType) { if (string.IsNullOrEmpty(data)) { return; } HighScoreTable scoreTable = GameObject.FindObjectOfType <HighScoreTable> (); if (scoreTable == null) { return; } string[] scoreData = data.Split('&'); string[] entryData; if (scoreData != null && scoreData.Length > 0) { for (int i = 0; i < scoreData.Length; i++) { entryData = scoreData [i].Split(':'); if (entryData.Length == 2) { Debug.Log(string.Format("{0}: {1} - {2}", i, entryData [0], entryData [1])); ScoreEntry score = new ScoreEntry((long)System.Convert.ToDouble(entryData [1]), entryData [0], scoreType); scoreTable.AddScoreEntry(score); } } } }
public void sendData() { if (playernamestr == "") { button.interactable = false; } HighScoreTable.AddHighscoreEntry(Score.score, playernamestr); SceneManager.LoadScene(2); }
void Awake() { instance = this; entryContainer = transform.Find("HighScoreEntryContainer"); entryTemplate = entryContainer.Find("HighScoreEntryTemplate"); entryTemplate.gameObject.SetActive(false); Instantiate(); SortAndAddDummy(); }
// Use this for initialization void Start() { // Find camera with script on it GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); // Get reference to the script HighScoreTable hst = camera.GetComponent <HighScoreTable>(); // Read scores off disk hst.loadHighScores(); // Display score in GUI displayTopScores(); }// End Start()
// Use this for initialization void Start () { // Find camera with script on it GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); // Get reference to the script HighScoreTable hst = camera.GetComponent<HighScoreTable>(); // Read scores off disk hst.loadHighScores(); // Display score in GUI displayTopScores(); }// End Start()
private void Awake() { highScoreTable = GetComponent <HighScoreTable>(); PlayerInfo playerInfo = GameObject.FindObjectOfType <PlayerInfo>(); if (playerInfo != null) { Debug.Log("adding highscore"); highScoreTable.AddHighScoreEntry(playerInfo.score, playerInfo.playerName); } else { Debug.LogError("noPlayerInfoFound", this); } }
public void PopulateHighScores() { if (highScoresContainer == null) return; if (highScoresContainer.transform.childCount == 0) return; HighScoreTable scoreTable = GameObject.FindObjectOfType<HighScoreTable> (); UnityEngine.UI.Text scoreText = null; Transform child = null; if (scoreTable.HighScores.Count > 0) { for (int i = 0; i < scoreTable.HighScores.Count; i++) { child = highScoresContainer.transform.GetChild (i); if (child != null) { scoreText = child.GetComponent<UnityEngine.UI.Text> (); if (scoreText != null) { scoreText.text = string.Format ("#{0}. {1} - {2}", i + 1, scoreTable.HighScores [i].Initials, scoreTable.HighScores [i].Score); } } } } else { for (int i = 0; i < highScoresContainer.transform.childCount; i++) { child = highScoresContainer.transform.GetChild (i); if (child != null) { scoreText = child.GetComponent<UnityEngine.UI.Text> (); if (scoreText != null) { scoreText.text = string.Format ("#{0}. ", i + 1); } } } } }
public void CallTopScoreMenu() { //Debug.Log("here"); HighScoreTable.Add(); GetPlayerName.BossKilled(); //HighScoreTable.SaveScore(); // Menu.KillBoss(); Button = GameObject.Find("Button"); Button.SetActive(false); Slider = GameObject.Find("Slider"); Slider.SetActive(false); //Score = GameObject.Find("TopScore Menu"); //Score.SetActive(true); //topScore.SetActive(true); }
private TetrisApp() { // Create the object that configures the GPIO pins to buttons. GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null); // Assign GPIO / Key functions to GPIOButtonInputProvider #if ESP32 // This is an example mapping, work them out for your needs! inputProvider.AddButton(12, Button.VK_LEFT, true); inputProvider.AddButton(13, Button.VK_RIGHT, true); inputProvider.AddButton(34, Button.VK_UP, true); inputProvider.AddButton(35, Button.VK_SELECT, true); inputProvider.AddButton(36, Button.VK_DOWN, true); DisplayControl.Initialize(new SpiConfiguration(1, 22, 21, 18, 5), new ScreenConfiguration(0, 0, 320, 240)); #elif STM32F769I_DISCO // This is an example (working) button map, work the actual pins out for your need! //WARNING: Invalid pin mappings will never be returned, and may need you to reflash the device! inputProvider.AddButton(PinNumber('J', 0), Button.VK_LEFT, true); inputProvider.AddButton(PinNumber('J', 1), Button.VK_RIGHT, true); inputProvider.AddButton(PinNumber('J', 3), Button.VK_UP, true); inputProvider.AddButton(PinNumber('J', 4), Button.VK_DOWN, true); inputProvider.AddButton(PinNumber('A', 6), Button.VK_SELECT, true); DisplayControl.Initialize(new SpiConfiguration(), new ScreenConfiguration()); //TODO: surely this should "actually" be I2C?! #else throw new System.Exception("Unknown button and/or display mapping!"); #endif // Create ExtendedWeakReference for high score table highScoreEWD = ExtendedWeakReference.RecoverOrCreate( typeof(TetrisApp), 0, ExtendedWeakReference.c_SurvivePowerdown); // Set persistence priority highScoreEWD.Priority = (int)ExtendedWeakReference.PriorityLevel.Important; // Try to recover previously saved HighScore HighScore = (HighScoreTable)highScoreEWD.Target; // If nothing was recovered - create new if (HighScore == null) { HighScore = new HighScoreTable(); } }
public void ScoreDisplay(HighScoreTable highScoreTable) { string scores = ""; for (int i = 0; i < highScoreTable.ScoreList.Count; i++) { if (i == 10) { break; } int rank = i + 1; string rankString = rank.ToString(); string name = highScoreTable.ScoreList[i].name; string score = highScoreTable.ScoreList[i].score.ToString(); scores += rankString + " " + score + " " + name + "\n"; } Debug.Log(scores); ScoreBoard.text = scores; }
private void TimerCountdown() { // Minutes and Seconds int min = Mathf.FloorToInt(timer / 60); int sec = Mathf.FloorToInt(timer % 60); // Change time text color if (timer > 5) { // If a full minute(s) is left then highlight time in red if (sec == 0) { timeDisplay.color = new Color(1, 0, 0, 1); } else { timeDisplay.color = new Color(1, 1, 1, 1); } } else { // If 5 seconds are left then highlight time in red timeDisplay.color = new Color(1, 0, 0, 1); } // Display time in "mm:ss" format timeDisplay.text = min.ToString("00") + ":" + sec.ToString("00"); timer -= Time.deltaTime; if (timer <= 3) { FindObjectOfType <AudioManager>().Play("TimeTicking"); } // If there is no time left, then go to end screen if (timer <= 0) { HighScoreTable.AddHighScoreEntry(Manager.Instance.Score, Manager.Instance.Name); SceneManager.LoadScene(2); } }
// Use this for initialization void Start() { // Get reference to RectTransform of text gameOverTitle = GetComponent <RectTransform>(); // Push text off screen alignText(); // Find camera with script on it GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); // Referenece to HighScoreTable script hst = camera.GetComponent <HighScoreTable>(); // Store high score for comparison highScore = PlayerPrefs.GetInt("Score9"); // Initialise stop to 0 stop = 0; }// End Start()
public void loadScores(string filename) { //Debug.Log(Application.persistentDataPath); if (File.Exists(Application.persistentDataPath + "/" + GameManager.gameTimer.levelName + ".scores")) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = File.Open(Application.persistentDataPath + "/" + GameManager.gameTimer.levelName + ".scores", FileMode.Open); HighScoreTable hst = (HighScoreTable)bf.Deserialize(fs); scores = hst.scores; names = hst.names; fs.Close(); } else //set defaults { scores = new int[] { 5000000, 4500000, 3500000, 2000000, 1000000, 500000, 100000, 50000, 25000, 10000 }; //if you get under 10,000 points you need to consider your life choices names = new string[] { "TREVOR", "ADAM", "LUKASZ", "PETER", "VINCE", "JONATHAN", "TIAN", "SAD TREVOR", "CJ", "SUP" }; //sup saveScores(filename); } }
// Use this for initialization void Start () { // Get reference to RectTransform of text gameOverTitle = GetComponent<RectTransform>(); // Push text off screen alignText(); // Find camera with script on it GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); // Referenece to HighScoreTable script hst = camera.GetComponent<HighScoreTable>(); // Store high score for comparison highScore = PlayerPrefs.GetInt("Score9"); // Initialise stop to 0 stop = 0; }// End Start()
public IEnumerator LoadHighScoreJSONFile() { string path = Application.streamingAssetsPath; string fullPath = System.IO.Path.Combine("file:///", path, fileName); UnityWebRequest request = UnityWebRequest.Get(fullPath); yield return(request.SendWebRequest()); if (request.isHttpError || request.isNetworkError) { Debug.Log("Request Error : " + request.error); yield break; } string downloadedText = request.downloadHandler.text; Debug.Log(downloadedText); highScoreTable = JsonUtility.FromJson <HighScoreTable>(downloadedText); }
private TetrisApp() { // Create the object that configures the GPIO pins to buttons. GpioButtonInputProvider inputProvider = new GpioButtonInputProvider(null); // Create ExtendedWeakReference for high score table highScoreEWD = ExtendedWeakReference.RecoverOrCreate( typeof(TetrisApp), 0, ExtendedWeakReference.c_SurvivePowerdown); // Set persistance priority highScoreEWD.Priority = (int)ExtendedWeakReference.PriorityLevel.Important; // Try to recover previously saved HighScore HighScore = (HighScoreTable)highScoreEWD.Target; // If nothing was recovered - create new if (HighScore == null) { HighScore = new HighScoreTable(); } }
private TetrisApp() { // Create the object that configures the GPIO pins to buttons. GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null); // Assign GPIO / Key functions to GPIOButtonInputProvider // Esp32 inputProvider.AddButton(12, Button.VK_LEFT, true); inputProvider.AddButton(13, Button.VK_RIGHT, true); inputProvider.AddButton(34, Button.VK_UP, true); inputProvider.AddButton(35, Button.VK_SELECT, true); inputProvider.AddButton(36, Button.VK_DOWN, true); // STM32 //inputProvider.AddButton(PinNumber('A', 0), Button.VK_LEFT, true); //inputProvider.AddButton(PinNumber('A', 1), Button.VK_RIGHT, true); //inputProvider.AddButton(PinNumber('A', 2), Button.VK_UP, true); //inputProvider.AddButton(PinNumber('A', 3), Button.VK_SELECT, true); //inputProvider.AddButton(PinNumber('A', 4), Button.VK_DOWN, true); // Create ExtendedWeakReference for high score table highScoreEWD = ExtendedWeakReference.RecoverOrCreate( typeof(TetrisApp), 0, ExtendedWeakReference.c_SurvivePowerdown); // Set persistence priority highScoreEWD.Priority = (int)ExtendedWeakReference.PriorityLevel.Important; // Try to recover previously saved HighScore HighScore = (HighScoreTable)highScoreEWD.Target; // If nothing was recovered - create new if (HighScore == null) { HighScore = new HighScoreTable(); } }
/* UNITY FUNCTIONS */ // Called when the object is created for the first time void Awake() { if (gInstance != null && gInstance != this) { Destroy(gameObject); } else { gInstance = this; } // prepare object LoadHighScores(); DontDestroyOnLoad(gameObject); }
public void sendData() { HighScoreTable.AddHighscoreEntry(Score.score, PlayerName.playernamestr); SceneManager.LoadScene(2); }