//----------- Load - Save ------------// public void Save(string fileName) { File.WriteAllText(fileName, String.Empty); using (StreamWriter writer = new StreamWriter(fileName)) { if (current_Enemies != null && current_Enemies.Count > 0) { writer.WriteLine("[enemies]"); for (int i = 0; i < current_Enemies.Count; ++i) { writer.WriteLine(current_Enemies[i].Serialize()); } writer.WriteLine("[end]"); } if (enemie_Que != null && enemie_Que.Count > 0) { writer.WriteLine("[queuedEnemies]"); for (int i = 0; i < enemie_Que.Count; i++) { writer.WriteLine(enemie_Que[i].Serialize()); } writer.WriteLine("[end]"); } if (player != null) { writer.WriteLine("[player]"); writer.WriteLine(player.Serialize()); writer.WriteLine("[end]"); } if (player_fire != null && player_fire.Count > 0) { writer.WriteLine("[playerBullets]"); for (int i = 0; i < player_fire.Count; ++i) { writer.WriteLine(player_fire[i].Serialize()); } writer.WriteLine("[end]"); } writer.WriteLine("[defaults]"); writer.WriteLine(level + "," + score + "," + base_Speed); writer.WriteLine("[end]"); } }
//----------- Load - Save ------------// //Save method that takes in a file name and saves the current state of the game (Defaults, //Player, Enemies, etc...) into specified file. public void Save(string fileName) { File.WriteAllText(fileName, String.Empty); using (StreamWriter writer = new StreamWriter(fileName)) { writer.WriteLine("[defaults]"); writer.WriteLine(level + "," + score + "," + base_Speed + "," + gameLevelTimer + "," + BossIsSpawned); //add timers writer.WriteLine("[end]"); if (player != null) { writer.WriteLine("[player]"); writer.WriteLine(player.Serialize()); writer.WriteLine("[end]"); } if (player_fire != null && player_fire.Count > 0) { writer.WriteLine("[playerBullets]"); for (int i = 0; i < player_fire.Count; ++i) { writer.WriteLine(player_fire[i].Serialize()); } writer.WriteLine("[end]"); } if (current_Enemies != null && current_Enemies.Count > 0) { writer.WriteLine("[enemies]"); for (int i = 0; i < current_Enemies.Count; ++i) { writer.WriteLine(current_Enemies[i].Serialize()); } writer.WriteLine("[end]"); } } }