public LevelManager() { levels = new List<FileInfo>(); DirectoryInfo dir = new DirectoryInfo( Directory.GetCurrentDirectory() + "/Levels" ); Console.WriteLine( Directory.GetCurrentDirectory() + "/Levels" ); try { levels.AddRange( dir.GetFiles( "Level*.*" ) ); } catch { Console.WriteLine( "ERROR LOADING LEVELS" ); } current_level = 0; foreach ( FileInfo name in levels ) { Console.WriteLine( name.Name ); current_level++; } string fullpath = Path.Combine( Directory.GetCurrentDirectory(), HighScoresFilename ); if ( !File.Exists( fullpath ) ) { //If the file doesn't exist, make a fake one... // Create the data to save HighScoreData data = new HighScoreData( current_level ); for ( int i = 0; i < current_level; i++ ) data.Score[i] = 0; SaveHighScores( data, HighScoresFilename ); } else { high_scores = LoadHighScores( HighScoresFilename ); } current_level = 0; }
public void saveHighScores() { string line; int i = 0; StreamReader sr = new StreamReader("highscore.txt"); while ((line = sr.ReadLine()) != null) { HighScoreData dataskornya = new HighScoreData(); string[] parts = line.Split('-'); dataskornya.PlayerName = parts[0].Trim(); dataskornya.Score = Int32.Parse(parts[1].Trim()); highScores.Add(dataskornya); i++; } sr.Close(); HighScoreData dataskornya2 = new HighScoreData(); dataskornya2.PlayerName = ime; dataskornya2.Score = poeni; highScores.Add(dataskornya2); highScores.Sort(CompareByPlayerScore); StreamWriter sw = new StreamWriter("highscore.txt"); for (i = 0; i < 5; i++) { line = highScores[i].PlayerName + " - " + highScores[i].Score; String stringToSave = ime.Replace("_", " "); sw.WriteLine(line); } sw.Close(); }
private static int CompareByPlayerScore(HighScoreData x, HighScoreData y) { if (x.Equals(null)) { if (y.Equals(null)) { return 0; } else { return -1; } } else { if (y.Equals(null)) { return 1; } else { int retval = y.Score.CompareTo(x.Score); if (retval != 0) { return retval; } else { return y.Score.CompareTo(x.Score); } } } }
public void Ini() { // Get the path of the save game string fullpath = "highscores.dat"; // Check to see if the save exists if (!File.Exists(fullpath)) { //If the file doesn't exist, make a fake one... // Create the data to save data = new HighScoreData(5); data.PlayerName[0] = "botneil"; data.Score[0] = 20; data.PlayerName[1] = "botshawn"; data.Score[1] = 10; data.PlayerName[2] = "botmark"; data.Score[2] = 9; data.PlayerName[3] = "botcindy"; data.Score[3] = 8; data.PlayerName[4] = "botsam"; data.Score[4] = 2; SaveHighScores2(data, HighScoresFilename, device); } }
public void SaveHighScores() { BinaryFormatter oFormatter = new BinaryFormatter(); FileStream oFile = File.Create(Application.persistentDataPath + "/HighScores.dat"); HighScoreData oData = new HighScoreData(); oData.registeredHighScores = highScores; oFormatter.Serialize(oFile, oData); oFile.Close(); }
/* * Constructor */ public HighScores(int score) { SetUp(); this.data = LoadHighScores(HighScoresFilename); this.PlayerScore = score; SaveHighScore(); }
//Consulta de puntajes altos public void generaHighScores(SFSObject dataObject) { //obtiene arreglo resultado this.ultimaConsultaHighScores= new ArrayList(); ISFSArray resultado = dataObject.GetSFSArray("result"); for (int i=0; i < resultado.Size(); i++){ SFSObject item= (SFSObject) resultado.GetSFSObject(i); string user= item.GetUtfString("userid"); string score= ((double) item.GetDouble("score")).ToString(); HighScoreData nuevo= new HighScoreData(user, score); this.ultimaConsultaHighScores.Insert(i, nuevo); } }
void CreateHighScores(string[] initiatedNames, int[] initiatedScores) { for (int i = 0; i < 10; i++) { highScores[i] = new Script_PlayerClass(); highScores[i].PlayerName = initiatedNames[i]; highScores[i].Score = initiatedScores[i]; } BinaryFormatter oFormatter = new BinaryFormatter(); FileStream oFile = File.Create(Application.persistentDataPath + "/HighScores.dat"); HighScoreData oData = new HighScoreData(); oData.registeredHighScores = highScores; oFormatter.Serialize(oFile, oData); oFile.Close(); }
public void saveHighScore() { if (CountScore.score > Menu_controller.bestSocre) { //Animation Save Score Menu_controller.bestSocre = CountScore.score; bestScoreText.text = getScore.text; // Save New Score BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath+"/playerInfo.dat"); HighScoreData data = new HighScoreData(); data.highScoreData = CountScore.score; bf.Serialize(file,data); file.Close(); } }
public static void SaveHighScores( HighScoreData data, string filename ) { // Get the path of the save game string fullpath = Path.Combine( Directory.GetCurrentDirectory(), filename ); // Open the file, creating it if necessary FileStream stream = File.Open( fullpath, FileMode.OpenOrCreate ); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer( typeof( HighScoreData ) ); serializer.Serialize( stream, data ); } finally { // Close the file stream.Close(); } }
public static void SaveHighScores(HighScoreData highScoreData, string filename) { // Get the path of the save game string fullPath = "highscores.dat"; // Open the file, creating it if necessary FileStream stream = File.Open(fullPath, FileMode.OpenOrCreate, FileAccess.Write); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, highScoreData); } finally { // Close the file stream.Close(); } }
/// <summary> /// Method to save highscore to a file /// </summary> /// <param name="data"></param> /// <param name="filename"></param> public static void SaveHighScore(HighScoreData data, string filename) { //Get path of the scores file string fullPath = Path.Combine(GameConstants.GAME_ROOT_DIRECTORY, filename); //Open file. Create if necessary FileStream stream = File.Open(fullPath, FileMode.Create); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } finally { //Close the file stream.Close(); } }
protected override void Initialize() { base.Initialize(); // Testing HighScoreData highScoreData = new HighScoreData(3); highScoreData.Name[0] = "Bobby"; highScoreData.Score[0] = 1000; highScoreData.Name[1] = "Nikit"; highScoreData.Score[1] = 988; highScoreData.Name[2] = "Anna"; highScoreData.Score[2] = 900; WriteScore(highScoreData); base.Initialize(); }
private void updateText(int pos, HighScoreData hs) { TextMesh player = null, score = null; if(pos == 0){ player = this.name1; score = this.score1; } else{ if(pos == 1){ player = this.name2; score = this.score2; } else{ if(pos==2){ player = this.name3; score = this.score3; } else{ if(pos==3){ player = this.name4; score = this.score4; } else{ if(pos==4){ player = this.name5; score = this.score5; } } } } } if(player != null && score != null){ player.text = hs.getName(); score.text = hs.getScore(); } }
/* Load highscores */ public static HighScoreData LoadHighScores(string filename) { HighScoreData data; // Get the path of the save game string fullpath = "highscores.dat"; #if WINDOWS // Open the file FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate, FileAccess.Read); try { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); data = (HighScoreData)serializer.Deserialize(stream); } finally { // Close the file stream.Close(); } return (data); #elif XBOX using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fullpath, FileMode.Open,iso)) { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); data = (HighScoreData)serializer.Deserialize(stream); } } return (data); #endif }
/* Save highscores */ public static void SaveHighScores2(HighScoreData data, string filename, StorageDevice device) { FileStream stream; if (!File.Exists(filename)) { stream = File.Open(filename, FileMode.OpenOrCreate); } else { stream = File.Open(filename, FileMode.Truncate); } try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } }
/// <summary> /// write to an XML file the high score data for this game type /// </summary> private void saveHighScoreData() { HighScoreData highScore = new HighScoreData(); highScore.GameType = this.ToString(); highScore.HighScore = score; highScore.date = DateTime.Now; //if the new score is larger than the current high score, reset the high score; else do nothing. if (score > readHighScoreData().HighScore) { XmlSerializer writer = new XmlSerializer(typeof(HighScoreData)); StreamWriter file = new StreamWriter("HighScore.xml"); writer.Serialize(file, highScore); file.Close(); } }
/* Load highscores */ public HighScoreData LoadHighScores(string filename) { HighScoreData data; // Open the file FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read); try { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); data = (HighScoreData)serializer.Deserialize(stream); } finally { // Close the file stream.Close(); } return (data); }
private void WriteScore(HighScoreData highScores) { try { FileStream fileStream = new FileStream(HIGH_SCORE_FILE, FileMode.OpenOrCreate, FileAccess.Write); //BinaryWriter binaryWriter = new BinaryWriter(fileStream); //binaryWriter.Write(highScore); //binaryWriter.Close(); XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(fileStream, highScores); fileStream.Close(); } catch (IOException) { } isNewHighScore = false; }
public void reload_scores() { high_scores = LoadHighScores( HighScoresFilename ); }
public static void SaveHighScores(HighScoreData data) { // Get the path of the saved game string fullpath; #if WINDOWS fullpath = Path.Combine(Path.Combine(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games"), "SHMUP"), localHighScoreFileName); #elif XBOX fullpath = Path.Combine(container.Path, localHighScoreFileName); #endif // Open the file, creating it if necessary FileStream stream = File.Open(fullpath, FileMode.Create); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } }
public void addPlayer(HighScoreData hs) { this.players.Add(hs); }
public static void WriteHighscoresToFile(HighScoreData data, String fileName) { // Open the file, creating it if necessary FileStream stream = File.Open(fileName, FileMode.OpenOrCreate); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); //TODO: This will crash the game incase the format of the Highscore.lst file is incorrect. serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } }
public void SetUp() { // Get the path of the save game string fullPath = "highscores.dat"; // Check to see if the save exists if (!File.Exists(fullPath)) { //If the file doesn't exist, make a fake one... // Create the data to save data = new HighScoreData(5); data.Score[4] = 5; data.Score[3] = 4; data.Score[2] = 3; data.Score[1] = 2; data.Score[0] = 1; SaveHighScores(data, HighScoresFilename); } }
public void Ini() { // Get the path of the save game string fullpath = "highscores.dat"; // Check to see if the save exists #if WINDOWS if (!File.Exists(fullpath)) { //If the file doesn't exist, make a fake one... // Create the data to save data = new HighScoreData(5); data.PlayerName[0] = "botneil"; data.Score[0] = 20; data.PlayerName[1] = "botshawn"; data.Score[1] = 10; data.PlayerName[2] = "botmark"; data.Score[2] = 9; data.PlayerName[3] = "botcindy"; data.Score[3] = 8; data.PlayerName[4] = "botsam"; data.Score[4] = 2; SaveHighScores(data, HighScoresFilename, device); } #elif XBOX using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (!iso.FileExists(fullpath)) { //If the file doesn't exist, make a fake one... // Create the data to save data = new HighScoreData(5); data.PlayerName[0] = "botneil"; data.Score[0] = 20; data.PlayerName[1] = "botshawn"; data.Score[1] = 10; data.PlayerName[2] = "botmark"; data.Score[2] = 9; data.PlayerName[3] = "botcindy"; data.Score[3] = 8; data.PlayerName[4] = "botsam"; data.Score[4] = 2; SaveHighScores(data, HighScoresFilename, device); } } #endif }
/* Save highscores */ public static void SaveHighScores(HighScoreData data, string filename, StorageDevice device) { // Get the path of the save game string fullpath = "highscores.dat"; #if WINDOWS // Open the file, creating it if necessary FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } #elif XBOX using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fullpath, FileMode.Create, iso)) { XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } } #endif }
public static HighScoreData LoadHighScores(string filename) { HighScoreData data; string fullpath = "highscores.dat"; FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate, FileAccess.Read); try { XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); data = (HighScoreData)serializer.Deserialize(stream); } finally { stream.Close(); } return (data); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { //creates a highscore .dat file using he scores below if there isn't one. string fullpath = "highscores.dat"; if (!File.Exists(fullpath)) { data = new HighScoreData(5); data.Score[0] = 2500; data.Score[1] = 1500; data.Score[2] = 1000; data.Score[3] = 500; data.Score[4] = 300; SaveHighScores(data, HighScoresFilename, null); IsFixedTimeStep = false; } // TODO: Add your initialization logic here base.Initialize(); InitializeBindings(); interactiveMusic.musicsystem.setParameterValue(1, 1); }
public static void SaveHighScores(HighScoreData data, string filename, StorageDevice device) { string fullpath = "highscores.dat"; FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate); try { XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); serializer.Serialize(stream, data); } finally { stream.Close(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); IsFixedTimeStep = true; gameTimer = new Timer(); //try opening the high score file. If it does not open, presume that it has not been created before try { StreamReader file = new StreamReader("HighScore.xml"); file.Close(); } catch { //create a new high score where the score is 0 and the date and time is the first time this game was opened HighScoreData highScore = new HighScoreData(); highScore.HighScore = 0; highScore.date = DateTime.Now; XmlSerializer writer = new XmlSerializer(typeof(HighScoreData)); StreamWriter file = new StreamWriter("HighScore.xml"); writer.Serialize(file, highScore); file.Close(); } }