/// <summary> /// Returns the list of top player scores /// </summary> /// <returns></returns> public static List <int> GetTopPlayerScores() { // Get the top player scores json string string jsonString = PlayerPrefs.GetString(TOP_SCORES_PLAYER_PREFS_KEY, DefaultJsonStringValue()); Debug.Log(jsonString); // Parse it from an int array using the JsonUtility.FromJson TopScores topScoresInstance = JsonUtility.FromJson <TopScores>(jsonString); List <int> fromJsonArrayList = topScoresInstance == null ? new List <int>() : topScoresInstance.scores; if (fromJsonArrayList == null) { fromJsonArrayList = new List <int>(); } if (fromJsonArrayList.Count > 1) { fromJsonArrayList = fromJsonArrayList.OrderByDescending(x => { return(x); }).ToList(); } // Finally, return the list return(fromJsonArrayList); }
private static string DefaultJsonStringValue() { TopScores myTopScores = new TopScores(); myTopScores.scores = new List <int>(); return(JsonUtility.ToJson(myTopScores)); }
private void button3_Click(object sender, EventArgs e) { var topScores = new TopScores(); topScores.Tag = this; topScores.Show(this); Hide(); }
public void TestGetTopScoresFromFile() { TopScores.GetTopScoresFromFile(); string filePath = @"Top.txt"; bool fileExist = File.Exists(filePath); Assert.IsTrue(fileExist); }
private static void UpdateTopScores(List <int> newTopScoresList) { TopScores newTopScores = new TopScores(); newTopScores.scores = newTopScoresList; string jsonString = JsonUtility.ToJson(newTopScores); PlayerPrefs.SetString(TOP_SCORES_PLAYER_PREFS_KEY, jsonString); }
public void AddHighScore(Score score) { if (_topScores.Count > 10) { _topScores.Remove(_topScores.FirstOrDefault(ms => ms.Points == TopScores.Min(ts => ts.Points))); } _topScores.Add(score); RaisePropertyChanged(nameof(TopScores)); SaveHighScore(); }
public bool NewHighScore() { bool newHighScore = false; if (TopScores.Count < 10 || TopScores.FirstOrDefault(ts => ts.Points < _score) != null) { newHighScore = true; } return(newHighScore); }
void LoadHighScores() { topScores = new TopScores(); if (PlayerPrefs.HasKey("FirstScore")) { topScores.first = PlayerPrefs.GetInt("FirstScore"); topScores.second = PlayerPrefs.GetInt("SecondScore"); topScores.third = PlayerPrefs.GetInt("ThirdScore"); topScores.forth = PlayerPrefs.GetInt("ForthScore"); topScores.fifth = PlayerPrefs.GetInt("FifthScore"); topScores.firstName = PlayerPrefs.GetString("FirstName"); topScores.secondName = PlayerPrefs.GetString("SecondName"); topScores.thirdName = PlayerPrefs.GetString("ThirdName"); topScores.forthName = PlayerPrefs.GetString("ForthName"); topScores.fifthName = PlayerPrefs.GetString("FifthName"); } }
private static void TestTopScores() { var result = TopScores.Show().ToList(); result.ForEach(x => { Console.WriteLine(x); }); PrintLine(); TopScores.CheckScore("Pesho", 1000); TopScores.CheckScore("Ivan", 50); TopScores.CheckScore("Gosho", 3000); result = TopScores.Show().ToList(); result.ForEach(x => Console.WriteLine(x)); PrintLine(); TopScores.Clear(); result = TopScores.Show().ToList(); result.ForEach(x => Console.WriteLine(x)); }
public IEnumerator FetchScores(UnityAction <TopScores> success, UnityAction <string> failed) { WWW www = new WWW(serverUrl + "/gettopscores?count=" + size); yield return(www); if (String.IsNullOrEmpty(www.error)) { topScores = JsonUtility.FromJson <TopScores> (www.text); if (success != null) { success(topScores); } } else { if (failed != null) { failed(www.error); } } }
private static ArrayList FindRecentResults(IndexReader primary_reader, IndexReader secondary_reader, BetterBitArray primary_matches, Dictionary <int, Hit> hits_by_id, int max_results, ref int total_number_of_matches, HitFilter hit_filter, string index_name) { Stopwatch b = new Stopwatch(); b.Start(); int count = 0; Document doc; ArrayList all_docs = null; TopScores top_docs = null; TermDocs term_docs = null; if (primary_matches.TrueCount > max_results) { top_docs = new TopScores(max_results); } else { all_docs = new ArrayList(primary_matches.TrueCount); } if (secondary_reader != null) { term_docs = secondary_reader.TermDocs(); } for (int match_index = primary_matches.Count; ; match_index--) { // Walk across the matches backwards, since newer // documents are more likely to be at the end of // the index. match_index = primary_matches.GetPreviousTrueIndex(match_index); if (match_index < 0) { break; } count++; doc = primary_reader.Document(match_index, fields_timestamp_uri); // Check the timestamp --- if we have already reached our // limit, we might be able to reject it immediately. string timestamp_str; long timestamp_num = 0; timestamp_str = doc.Get("Timestamp"); if (timestamp_str == null) { Logger.Log.Warn("No timestamp on {0}!", GetUriFromDocument(doc)); } else { timestamp_num = Int64.Parse(doc.Get("Timestamp")); if (top_docs != null && !top_docs.WillAccept(timestamp_num)) { continue; } } // Get the actual hit now // doc was created with only 2 fields, so first get the complete lucene document for primary document. // Also run our hit_filter now, if we have one. Since we insist of returning max_results // most recent hits, any hits that would be filtered out should happen now and not later. Hit hit = CreateHit(primary_reader.Document(match_index), secondary_reader, term_docs); if (hit_filter != null && !hit_filter(hit)) { if (Debug) { Log.Debug("Filtered out {0}", hit.Uri); } total_number_of_matches--; continue; } hits_by_id [match_index] = hit; // Add the document to the appropriate data structure. // We use the timestamp_num as the score, so high // scores correspond to more-recent timestamps. if (all_docs != null) { all_docs.Add(hit); } else { top_docs.Add(timestamp_num, hit); } } if (term_docs != null) { term_docs.Close(); } b.Stop(); if (Debug) { Log.Debug(">>> {0}: Instantiated and scanned {1} documents in {2}", index_name, count, b); } if (all_docs != null) { // Sort results before sending all_docs.Sort(); return(all_docs); } else { return(top_docs.TopScoringObjects); } }