public void PostHighScore() { Debug.Log("Tuut"); HiScore hs = new HiScore(); hs.name = "Esimerkki"; hs.score = 20; StartCoroutine(POST(hs)); }
public static HiScore FindLowest(this List <HiScore> hiScores) { HiScore currentLowest = null; foreach (HiScore hiScore in hiScores) { if (currentLowest == null || currentLowest.Score < hiScore.Score) { currentLowest = hiScore; } } return(currentLowest); }
// Saves the full list of hiscores, // including the one passed by parameter public void SaveHiScore(string user, int score) { // First get the full list and add our HiScore HiScore myHiScore = new HiScore(user, score); List <HiScore> hiScores = this.GetSortedListFromSnapshot(true); hiScores.Add(myHiScore); // Sort the list List <HiScore> sortedHiScores = hiScores.OrderByDescending(o => o.score).ToList(); // Actually save the correctly sorted list this.InsertHiScores(sortedHiScores); }
public void uploadScore(int score, String name) { HiScore hs = new HiScore(); hs.name = name; hs.value = score; string hsJson = JsonUtility.ToJson(hs); Debug.Log(hsJson); byte[] postData = System.Text.Encoding.UTF8.GetBytes(hsJson); StartCoroutine(UploadData(postData)); }
void LoadGame() { // Data retrieving mechanism if (!File.Exists(Application.persistentDataPath + filename)) { Debug.Log("Savefile does not exist"); return; } BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + filename, FileMode.Open); SaveFile sf = (SaveFile)bf.Deserialize(file); file.Close(); hiScores = sf.hiScores; }
IEnumerator POST(HiScore hs) { Dictionary <string, string> headers = new Dictionary <string, string> (); headers.Add("Content-Type", "application/json"); string jsonData = JsonUtility.ToJson(hs); byte[] postData = System.Text.Encoding.UTF8.GetBytes(jsonData); WWW www = new WWW("localhost:5000/scores", postData, headers); yield return(www); Debug.Log(www); }
public void addScore(int _Score) { UpdateScore(_Score); // display user scores if (scoreUI) { scoreUI.text = Score.ToString(); } if (hiScoreUI) { hiScoreUI.text = HiScore.ToString(); } if (numArrowsUI) { numArrowsUI.text = numArrows.ToString(); } }
public void AddNewHiScore(int points, string name) { HiScore score = new HiScore(points, name); hiScores.Add(score); try { StreamWriter scores = new StreamWriter("HiScore.dat"); for (int i = 0; i < hiScores.Count; i++) { scores.WriteLine(hiScores[i].GetPoints() + ":" + hiScores[i].GetName()); } scores.Close(); } catch (Exception) { // TO DO: Warn the user? } }
void Start() { instance = this; hiScoreStore = ReadScore(); UpdateScoreBoard(hiScoreStore.hiScoreList); hiScoreInput.gameObject.SetActive(true); hiScoreInput.gameObject.SetActive(false); if (hiScoreInput.GetComponent <HiScoreInput>().raceFinishTime != 0f) { hiScoreInput.gameObject.SetActive(true); } else { hiScoreBoard.SetActive(true); hiScoreElement.gameObject.SetActive(true); } }
public void Init(float totTime) { if (GameData.current.HiScores == null) { GameData.current.HiScores = new List <HiScore>(); } L = GameData.current.HiScores; DrivingPlayManager.Current.ShowDrivingGUI(false); DrivingPlayManager.Current.ShowInputGUI(false); HiScorePrefab = Resources.Load("Prefabs/pnlHiScore"); trPanel = transform.Find("pnlHiScoreList").GetComponent <RectTransform>(); _trTrophy = transform.parent.Find("Trophy"); _trTrophy.gameObject.SetActive(false); float _segTime = totTime / Race.Current.Laps / Road.Instance.Segments.Count; _rank = GetRank(_segTime); _hs = new HiScore(); _hs.SegTime = _segTime; InsertHiScore(_hs); ShowBestLap(); StartCoroutine(Darken()); StartCoroutine(ShowHiScores()); }
private static void Main(string[] args) { string startCoord = string.Empty; char[,] field = CreateField(); char[,] bombs = PlaceBombs(); int count = 0; bool isBombTrigered = false; List<HiScore> bestScores = new List<HiScore>(6); int row = 0; int col = 0; const int Max = 35; bool start = true; bool finish = false; do { if (start) { Console.WriteLine( "Wellcome! Let's play “Minesweeper”. Test your luck and continue to the end." + "Enter 'top' for \"HiScores\", \n'restart': Restart the game , \n'exit': Exit from game."); Dump(field); start = false; } Console.Write("Enter row & column or choise: "); startCoord = Console.ReadLine().Trim(); if (startCoord.Length >= 3) { if (int.TryParse(startCoord[0].ToString(), out row) && int.TryParse(startCoord[2].ToString(), out col) && row <= field.GetLength(0) && col <= field.GetLength(1)) { startCoord = "turn"; } } switch (startCoord) { case "top": Scores(bestScores); break; case "restart": field = CreateGameField(); bombs = PlaceTheBombs(); Dump(field); isBombTrigered = false; start = false; break; case "exit": Console.WriteLine("GoodBye"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { YourTurn(field, bombs, row, col); count++; } if (Max == count) { finish = true; } else { Dump(field); } } else { isBombTrigered = true; } break; default: Console.WriteLine("\n You entered invalid command. Please enter again.\n"); break; } if (isBombTrigered) { Dump(bombs); Console.Write("\n Bomb Trigered and die with {0} points. " + "Nickname: ", count); string nickname = Console.ReadLine(); HiScore t = new HiScore(nickname, count); if (bestScores.Count < 5) { bestScores.Add(t); } else { for (int i = 0; i < bestScores.Count; i++) { if (bestScores[i].Points < t.Points) { bestScores.Insert(i, t); bestScores.RemoveAt(bestScores.Count - 1); break; } } } bestScores.Sort((HiScore score1, HiScore score2) => score2.Player.CompareTo(score1.Player)); bestScores.Sort((HiScore score1, HiScore score2) => score2.Points.CompareTo(score1.Points)); Scores(bestScores); field = CreateGameField(); bombs = PlaceTheBombs(); count = 0; isBombTrigered = false; start = true; } if (finish) { Console.WriteLine("\n Well done!"); Dump(bombs); Console.WriteLine("Nickname: "); string nickName = Console.ReadLine(); HiScore points = new HiScore(nickName, count); bestScores.Add(points); Scores(bestScores); field = CreateGameField(); bombs = PlaceTheBombs(); count = 0; finish = false; start = true; } } while (startCoord != "exit"); Console.WriteLine("Made in Bulgaria"); Console.WriteLine("Goodbye!"); Console.Read(); }
public int CompareScore(HiScore s1, HiScore s2) { return(s2.GetPoints() - s1.GetPoints()); }
/// <summary> /// Adds the submitted score to the hiScores list, wasteful if score is not above the lowest on the leaderboard. /// </summary> /// <param name="hiScore"></param> public void SaveScore(HiScore hiScore) { hiScores.Add(hiScore); SortScores(); hiScores.Remove(hiScores.Last()); }