public void setLevel(LevelTile level) { player.setLocked(false); backUpInventory = inventory.getItemsCopy(); lastEnteredLevelTile = level; Console.WriteLine(level.getLevel()); currentLevelString = level.getLevel(); //Eventually turn level strings into global constants if (currentLevel != null) { currentLevel.unloadLevel(); } if (currentLevelString.Equals("hubLevel")) { currentLevel = hubLevel; } else if (currentLevelString.Equals("houseLevel")) { currentLevel = houseLevel; } else if (currentLevelString.Equals("schoolLevel")) { currentLevel = schoolLevel; } else if (currentLevelString.Equals("gate1Level")) { currentLevel = gate1Level; } else if (currentLevelString.Equals("gate2Level")) { currentLevel = gate2Level; } else if (currentLevelString.Equals("complex1Level")) { currentLevel = complex1Level; } else if (currentLevelString.Equals("ghostTestLevel")) { currentLevel = ghostTestLevel; } else if (currentLevelString.Equals("laserTestLevel")) { currentLevel = laserTestLevel; } else if (currentLevelString.Equals("laserIntroLevel")) { currentLevel = laserIntroLevel; } else if (currentLevelString.Equals("marshEnterLevel")) { currentLevel = marshEnterLevel; } else if (currentLevelString.Equals("marsh1Level")) { currentLevel = marsh1Level; } else if (currentLevelString.Equals("marsh2Level")) { currentLevel = marsh2Level; } else if (currentLevelString.Equals("marshFinalLevel")) { currentLevel = marshFinalLevel; } creatures.Add(player); currentLevel.loadLevel(); backUpItems = (ArrayList)(currentLevel.getLevelItems()).Clone(); currentLevel.setPlayerStart(level.getPlayerStart()); //add level transfer tiles from current level to the array list of tiles levelTiles.Clear(); tiles.AddRange(currentLevel.getLevelTiles()); levelTiles.AddRange(currentLevel.getLevelTiles()); player.setX(currentLevel.getPlayerStartingX()); player.setY(currentLevel.getPlayerStartingY()); //set flag for dirt particles if (!currentLevel.getIndoors()) { player.setTracks(true); } else { player.setTracks(false); } cam.setBounds(currentLevel.getMapSizeX(), currentLevel.getMapSizeY()); cam.changeRoom(); cam.update(); if (level.getLevel().Equals("hubLevel")) loadBackupPlatforms(); saveGame(level); syncStates(); }
public void saveGame(LevelTile level) { StreamWriter saveFile = new StreamWriter("bananas.txt"); //Remove specified items from particular levels foreach (Level l in levels) { saveFile.WriteLine("L:" + levelToString[l]); string[] itemStrings = l.getRemovedLevelItems(); for (int x = 0; x < itemStrings.Length; x++) { saveFile.WriteLine("I:" + itemStrings[x]); } foreach (Platform p in platforms) { string str = "F:" + p.GetType().Name; if (((Platform)p).isItemOnPlatform()) { str += "|T"; } else { str += "|F"; } } } //Load which objects have been seen and which haven't ArrayList seenObjects = aboutScreen.getSeenObjects(); for (int x = 0; x < seenObjects.Count; x++) { saveFile.WriteLine("S:" + seenObjects[x]); } //Load the inventory for (int x = 0; x < backUpInventory.GetLength(0); x++) { for (int y = 0; y < backUpInventory.GetLength(1); y++) { if (backUpInventory[x, y] == null) continue; string str = backUpInventory[x, y].GetType().Name; str += "|" + x + "|" + y; if (backUpInventory[x, y] is ScrollI) { str += "|" + ((ScrollI)backUpInventory[x, y]).getGoodItemTip() + "|" + ((ScrollI)backUpInventory[x, y]).getBadItemTip(); } else if (backUpInventory[x, y] is LampI) { if (((LampI)backUpInventory[x, y]).hasBatteries()) { str += "|T"; } else { str += "|F"; } } saveFile.WriteLine("N:" + str); } } saveFile.WriteLine(levelToString[currentLevel]); saveFile.WriteLine("P:" + level.getPlayerStart().X + "|" + level.getPlayerStart().Y); saveFile.WriteLine("C:" + levelToString[currentLevel]); // if (level.Equals("hubLevel")) // { foreach (Platform p in platforms) { string str = "F:"+p.GetType().Name; if (((Platform)p).isItemOnPlatform()) { str += "|T"; } else { str += "|F"; } saveFile.WriteLine(str); } // } saveFile.Close(); }