public bool CheckIfSaveExists() { FileReadWriter frw = new FileReadWriter(); String itemCatalogue = frw.ReadCatalogueFile(FileReadWriter.ITEM_CATALOGUE); String eventCatalogue = frw.ReadCatalogueFile(FileReadWriter.EVENT_CATALOGUE); String discoveryCatalogue = frw.ReadCatalogueFile(FileReadWriter.DISCOVERY_CATALOGUE); String discovered = frw.ReadSaveDataFile(FileReadWriter.DISCOVERED); String pc = frw.ReadSaveDataFile(FileReadWriter.PLAYER_CHARACTER); String inventory = frw.ReadSaveDataFile(FileReadWriter.INVENTORY); String usedEvents = frw.ReadSaveDataFile(FileReadWriter.USED_EVENTS); String currentEvent = frw.ReadSaveDataFile(FileReadWriter.CURRENT_EVENT); String visitedLocs = frw.ReadSaveDataFile(FileReadWriter.VISITED); String unvisitedLocs = frw.ReadSaveDataFile(FileReadWriter.UNVISISTED); String currLoc = frw.ReadSaveDataFile(FileReadWriter.CURRENT_LOCATION); String currSLoc = frw.ReadSaveDataFile(FileReadWriter.CURRENT_SUBLOCATION); String buttonAreas = frw.ReadSaveDataFile(FileReadWriter.BUTTONS_AREA); String difficultyController = frw.ReadSaveDataFile(FileReadWriter.DIFFICULTY_CONTROLLER); System.Drawing.Bitmap worldMap = frw.ReadBitmap(FileReadWriter.WORLD_MAP); if (GameState.IsValidGameState(pc, inventory, itemCatalogue, usedEvents, currentEvent, eventCatalogue, discovered, discoveryCatalogue, visitedLocs, unvisitedLocs, currLoc, currSLoc) && DifficultyController.IsValidDifficultyController(difficultyController)) { return(true); } return(false); }
/// <summary> /// Initialises the game state from a save /// </summary> /// <returns>If the game state was sucessfully initialised</returns> public bool InitialiseGameFromSave() { FileReadWriter frw = new FileReadWriter(); String itemCatalogue = frw.ReadCatalogueFile(FileReadWriter.ITEM_CATALOGUE); String eventCatalogue = frw.ReadCatalogueFile(FileReadWriter.EVENT_CATALOGUE); String discoveryCatalogue = frw.ReadCatalogueFile(FileReadWriter.DISCOVERY_CATALOGUE); if (!GameState.AreValidCatalogues(itemCatalogue, eventCatalogue, discoveryCatalogue)) { itemCatalogue = uk.ac.dundee.arpond.longRoadHome.Properties.Resources.itemCatalogue; eventCatalogue = uk.ac.dundee.arpond.longRoadHome.Properties.Resources.eventCatalogue; discoveryCatalogue = uk.ac.dundee.arpond.longRoadHome.Properties.Resources.discoveryCatalogue; frw.WriteCatalogueFile(FileReadWriter.ITEM_CATALOGUE, itemCatalogue); frw.WriteCatalogueFile(FileReadWriter.EVENT_CATALOGUE, eventCatalogue); frw.WriteCatalogueFile(FileReadWriter.DISCOVERY_CATALOGUE, discoveryCatalogue); } String discovered = frw.ReadSaveDataFile(FileReadWriter.DISCOVERED); String pc = frw.ReadSaveDataFile(FileReadWriter.PLAYER_CHARACTER); String inventory = frw.ReadSaveDataFile(FileReadWriter.INVENTORY); String usedEvents = frw.ReadSaveDataFile(FileReadWriter.USED_EVENTS); String currentEvent = frw.ReadSaveDataFile(FileReadWriter.CURRENT_EVENT); String visitedLocs = frw.ReadSaveDataFile(FileReadWriter.VISITED); String unvisitedLocs = frw.ReadSaveDataFile(FileReadWriter.UNVISISTED); String currLoc = frw.ReadSaveDataFile(FileReadWriter.CURRENT_LOCATION); String currSLoc = frw.ReadSaveDataFile(FileReadWriter.CURRENT_SUBLOCATION); String buttonAreas = frw.ReadSaveDataFile(FileReadWriter.BUTTONS_AREA); String difficultyController = frw.ReadSaveDataFile(FileReadWriter.DIFFICULTY_CONTROLLER); System.Drawing.Bitmap worldMap = frw.ReadBitmap(FileReadWriter.WORLD_MAP); if (GameState.IsValidGameState(pc, inventory, itemCatalogue, usedEvents, currentEvent, eventCatalogue, discovered, discoveryCatalogue, visitedLocs, unvisitedLocs, currLoc, currSLoc) && DifficultyController.IsValidDifficultyController(difficultyController)) { gs = new GameState(pc, inventory, itemCatalogue, usedEvents, currentEvent, eventCatalogue, discovered, discoveryCatalogue, visitedLocs, unvisitedLocs, currLoc, currSLoc, buttonAreas, worldMap); dc = new DifficultyController(difficultyController); gameView.InitialiseWorldMap(mf.GetWorldMap(gs), mf.GetButtonAreas(gs)); List <Location> visited = mf.GetVisitedLocations(gs); List <int> ids = new List <int>(); foreach (var loc in visited) { ids.Add(loc.GetLocationID()); } gameView.UpdateFromSave(mf.GetCurrentLocation(gs), ids); gameView.InitialiseSublocationMap(mf.GetCurrentSublocations(gs), mf.GetCurrentSublocation(gs)); gameView.InitialiseInventory(mf.GetInventory(gs)); return(true); } return(false); }