public static void loadLevel4(Canvas canvas, Window window, Player player) { String fileName = "GalagaSavedGame.bin"; BinaryFormatter reader = null; Stream stream = null; SerializeGameObj game = null; try { reader = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); game = (SerializeGameObj)reader.Deserialize(stream); LoadLevels loadlvl1 = new LoadLevels(game.GetCoins, game.GetLives, game.GetLevel); player = loadlvl1.getPlayer(); } catch (SerializationException e) { MessageBox.Show("An error occured and the current game was not able to be LOADED."); MessageBox.Show(e.Message); } }
public static void loadLevel1(Canvas canvas, Window window, Player player) { String fileName = "GalagaSavedGame.bin"; BinaryFormatter reader = null; Stream stream = null; SerializeGameObj game = null; try { reader = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); game = (SerializeGameObj)reader.Deserialize(stream); // if(game.GetLevel == 4) // { // LoadLevels load = new LoadLevels(game.GetCoins, game.GetLives, game.GetLevel); //} //else ///{ LoadLevels loadlvl1 = new LoadLevels(game.GetShipInt, game.GetShipPoint, game.GetShipPath, game.GetCommanderInt, game.GetCommanderPoint, game.GetCommanderPath, game.GetBugInt, game.GetBugPoint, game.GetBugPath, canvas, window, game.GetShipMin, game.GetShipMax, game.GetComMin, game.GetComMax, game.GetBugMin, game.GetBugMax , game.GetCoins, game.GetLives, game.GetLevel); player = loadlvl1.getPlayer(); //} } catch (SerializationException e) { MessageBox.Show("An error occured and the current game was not able to be LOADED."); MessageBox.Show(e.Message); } }
public static void saveLevel4(Player player, bool load) { String fileName = "GalagaSavedGame.bin"; BinaryFormatter formatter = null; Stream stream = null; SerializeGameObj game = null; int coins; int lives; int level; if (load) { coins = LoadLevels.getStaticPlayer().getCoins(); lives = LoadLevels.getStaticPlayer().GetLives(); level = LoadLevels.getStaticPlayer().getCurrentLevel(); } else { coins = player.getCoins(); lives = player.GetLives(); level = player.getCurrentLevel(); } game = new SerializeGameObj(coins, lives, level); try { formatter = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, game); stream.Close(); MessageBox.Show("Game has been saved"); } catch (SerializationException e) { MessageBox.Show("An error occured and the current game was not able to be saved."); MessageBox.Show(e.Message); } }
public static void loadLevel2(Canvas canvas, Window window, Player player) { String fileName = "GalagaSavedGame.bin"; BinaryFormatter reader = null; Stream stream = null; SerializeGameObj game = null; List <int> enemieInt = new List <int>(); List <Point> pointArr = new List <Point>(); List <String> pathArr = new List <string>(); List <double> minXShip = new List <double>(); List <double> maxXShip = new List <double>(); List <double> minXCom = new List <double>(); List <double> maxXCom = new List <double>(); List <double> minXBug = new List <double>(); List <double> maxXBug = new List <double>(); int coins = player.getCoins(); int lives = player.GetLives(); int level = player.getCurrentLevel(); try { reader = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); game = (SerializeGameObj)reader.Deserialize(stream); LoadLevels loadlvl1 = new LoadLevels(game.GetShipInt, game.GetShipPoint, game.GetShipPath, game.GetCommanderInt, game.GetCommanderPoint, game.GetCommanderPath, game.GetBugInt, game.GetBugPoint, game.GetBugPath, canvas, window, game.GetShipMin, game.GetShipMax, game.GetComMin, game.GetComMax, game.GetBugMin, game.GetBugMax , game.GetCoins, game.GetLives, game.GetLevel); player = loadlvl1.getPlayer(); } catch (SerializationException e) { MessageBox.Show("An error occured and the current game was not able to be LOADED."); MessageBox.Show(e.Message); } }
public static void saveLevel2(Player player, bool load) { String fileName = "GalagaSavedGame.bin"; BinaryFormatter formatter = null; Stream stream = null; SerializeGameObj game = null; List <int> shipInt = new List <int>(); List <int> commanderInt = new List <int>(); List <int> bugInt = new List <int>(); List <Point> shipPoint = new List <Point>(); List <Point> commanderPoint = new List <Point>(); List <Point> bugPoint = new List <Point>(); List <String> shipPath = new List <string>(); List <String> commanderPath = new List <string>(); List <String> bugPath = new List <string>(); List <double> minXShip = new List <double>(); List <double> maxXShip = new List <double>(); List <double> minXCom = new List <double>(); List <double> maxXCom = new List <double>(); List <double> minXBug = new List <double>(); List <double> maxXBug = new List <double>(); int coins; int lives; int level; if (load) { coins = LoadLevels.getStaticPlayer().getCoins(); lives = LoadLevels.getStaticPlayer().GetLives(); level = LoadLevels.getStaticPlayer().getCurrentLevel(); } else { coins = player.getCoins(); lives = player.GetLives(); level = player.getCurrentLevel(); } if (load == false) { for (int i = 0; i < player.getEnemiesList().Count; i++) { if (player.getEnemiesList()[i].GetType() == typeof(SpaceShip)) { shipInt.Add(0); shipPoint.Add(player.getEnemiesList()[i].GetPoint()); shipPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString()); maxXShip.Add(player.getEnemiesList()[i].getMaxX()); minXShip.Add(player.getEnemiesList()[i].getMinX()); } else if (player.getEnemiesList()[i].GetType() == typeof(Commander)) { commanderInt.Add(1); commanderPoint.Add(player.getEnemiesList()[i].GetPoint()); commanderPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString()); maxXCom.Add(player.getEnemiesList()[i].getMaxX()); minXCom.Add(player.getEnemiesList()[i].getMinX()); } else if (player.getEnemiesList()[i].GetType() == typeof(Bug)) { bugInt.Add(2); bugPoint.Add(player.getEnemiesList()[i].GetPoint()); bugPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString()); maxXBug.Add(player.getEnemiesList()[i].getMaxX()); minXBug.Add(player.getEnemiesList()[i].getMinX()); } } } else if (load) { for (int i = 0; i < LoadLevels.getStaticPlayer().getEnemiesList().Count; i++) { if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(SpaceShip)) { shipInt.Add(0); shipPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint()); shipPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString()); maxXShip.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX()); minXShip.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX()); } else if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(Commander)) { commanderInt.Add(1); commanderPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint()); commanderPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString()); maxXCom.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX()); minXCom.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX()); } else if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(Bug)) { bugInt.Add(2); bugPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint()); bugPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString()); maxXBug.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX()); minXBug.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX()); } } } game = new SerializeGameObj(shipInt, shipPoint, shipPath, commanderInt, commanderPoint, commanderPath, bugInt, bugPoint, bugPath, minXShip, maxXShip, minXCom, maxXCom, minXBug, maxXBug, coins, lives, level); try { formatter = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, game); stream.Close(); MessageBox.Show("Game has been saved"); } catch (SerializationException e) { MessageBox.Show("An error occured and the current game was not able to be saved."); MessageBox.Show(e.Message); } }