public static void saveToExternal(WinDataClass wd) { string dest = Application.persistentDataPath + "/winData.dat"; FileStream file; //string jsonStr = JsonUtility.ToJson(player); if (File.Exists(dest)) { file = File.OpenWrite(dest); } else { file = File.Create(dest); } BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(file, wd); file.Close(); }
public static void LoadFromExternal(ref WinDataClass wd) { string dest = Application.persistentDataPath + "/winData.dat"; FileStream file; if (File.Exists(dest)) { file = File.OpenRead(dest); } else { // create a default player json if it doesn't exist //file = File.Create(dest); //player = new PlayerClass("NewPlayer", 0, 0, 1000, 1500); /*player.name = "NewPlayer"; * player.level = 0; * player.currentExperience = 0; * player.experienceForNextLevel = 1000; * player.money = 1500;*/ Debug.Log("error loading victory file"); //print("here"); //saveToJSON(player); return; // something here } BinaryFormatter bf = new BinaryFormatter(); wd = (WinDataClass)bf.Deserialize(file); //print(player.name); //print(player.money); //player = new PlayerClass("", 0,0,0,0); file.Close(); //return JsonUtility.FromJson<PlayerClass>(json.text); }
/* public void saveToExternal(WinDataClass wd){ * * string dest = Application.persistentDataPath + "/winData.dat"; * FileStream file; * //string jsonStr = JsonUtility.ToJson(player); * * if(File.Exists(dest)){ * file = File.OpenWrite(dest); * }else{ * file = File.Create(dest); * } * * BinaryFormatter bf = new BinaryFormatter(); * bf.Serialize(file, wd); * file.Close(); * } */ // handles updating the player data after a win // calculating the grade, etc. public void handleGameWin() { print("handleGameWin()"); //decimal moneyEarnedDecimal = (decimal)(Math.Sqrt(_playerScore) * (_playerNotesHit/totalNotes) + _playerMaxCombo)/100; //decimal expEarnedDecimal = (decimal)(Math.Sqrt(_playerScore)) * (_playerNotesHit/totalNotes) + (_playerMaxCombo == 1 ? 0 : _playerMaxCombo); WinDataClass winData = new WinDataClass(0, 0, 0, 0, 0, 0, ""); string calculatedGrade = ""; float notePercentage = (float)((decimal)_playerNotesHit / (decimal)totalNotes); if (notePercentage < 0.5) { calculatedGrade = "D"; } else if (notePercentage >= 0.5 && notePercentage < 0.6) { calculatedGrade = "C"; } else if (notePercentage >= 0.6 && notePercentage < 0.7) { calculatedGrade = "B"; } else if (notePercentage >= 0.7 && notePercentage < 0.8) { calculatedGrade = "A"; } else if (notePercentage >= 0.8 && notePercentage < 0.9) { calculatedGrade = "S"; } else if (notePercentage >= 0.9 && notePercentage < 1) { calculatedGrade = "SS"; } else { calculatedGrade = "ACE"; } winData.score = _playerScore; winData.maxCombo = _playerMaxCombo; winData.notesHit = _playerNotesHit; winData.mapTotalNotes = totalNotes; // can calculate the percentage using this and above winData.moneyEarned = (int)Math.Round((Math.Sqrt(_playerScore) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + _playerMaxCombo) / 100.0); // round money earned to closest integer winData.expEarned = (float)Math.Round(((Math.Sqrt(_playerScore)) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + (_playerMaxCombo == 1 ? 0 : _playerMaxCombo)), 2); // round exp to 2 digits winData.grade = calculatedGrade; print("big equation thing: " + Math.Round(((Math.Sqrt(_playerScore) * (float)((decimal)_playerNotesHit / (decimal)totalNotes) + _playerMaxCombo) / 100.0), 2)); /* * print("square root: " + (float)(Math.Sqrt(_playerScore))); * print("percentage: " + (float)((_playerNotesHit/totalNotes)*1.0)); * print("winData.moneyEarned: " + winData.moneyEarned); * print("winData.expEarned: " + winData.expEarned); */ //scoreboard beatMap.addWin(winData); beatMap.save(Application.persistentDataPath); WinDataClassHelper.saveToExternal(winData); _gameState = GameState.win; //SceneManager.LoadScene("VictoryRoyaleScene"); }
public void addWin(WinDataClass win) { scoreboard.Add(win); }