private void Save() { List <Boat> boatsToSave = new List <Boat>(); boatsToSave.AddRange(leftPort.Boats); boatsToSave.AddRange(leftPort.RemovedBoats); boatsToSave.AddRange(rightPort.Boats); boatsToSave.AddRange(rightPort.RemovedBoats); boatsToSave.AddRange(waitingBoats); SaveFileManager.Save(boatsToSave, "boats.txt"); SaveFileManager.SaveStatistics("stats.txt"); //SaveFileManager.Save(leftPort.Boats, "left.txt"); //SaveFileManager.Save(leftPort.RemovedBoats, "left_removed.txt"); //SaveFileManager.Save(rightPort.Boats, "right.txt"); //SaveFileManager.Save(rightPort.RemovedBoats, "right_removed.txt"); //SaveFileManager.Save(waitingBoats, "waiting.txt"); //if(sender is DispatcherTimer) //{ // MessageBox.Show("Game saved"); //} }
void LoadSaveFiles() { Func <List <Boat>, string, List <Boat> > loadBoats = (boats, port) => boats.Where(boat => boat.IsInPort == port).ToList(); try { List <Boat> boatsFromFile = SaveFileManager.Load("boats.txt"); leftPort.Boats = loadBoats(boatsFromFile, leftPort.PortName); leftPort.RemovedBoats = loadBoats(boatsFromFile, leftPort.PortName + "-removed"); rightPort.Boats = loadBoats(boatsFromFile, rightPort.PortName); rightPort.RemovedBoats = loadBoats(boatsFromFile, rightPort.PortName + "-removed"); Simulate.waitingBoats = boatsFromFile.Where(boat => boat.IsInPort == "?").ToList(); //Simulate.waitingBoats = SaveFileManager.Load("waiting.txt"); //leftPort.Boats = SaveFileManager.Load("left.txt"); //leftPort.RemovedBoats = SaveFileManager.Load("left_removed.txt"); //rightPort.Boats = SaveFileManager.Load("right.txt"); //rightPort.RemovedBoats = SaveFileManager.Load("right_removed.txt"); waitingBoats = Simulate.waitingBoats; if (leftPort.Boats.Any()) { leftPort.UpdateSpots(); } if (rightPort.Boats.Any()) { rightPort.UpdateSpots(); } SaveFileManager.LoadStatistics("stats.txt"); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void ClearSave_Clicked(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Är du säker?", "WARNING!", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { SaveFileManager.DeleteSaves(); leftPort = new Port("LeftPort"); rightPort = new Port("RightPort"); harbour.ReplacePort(leftPort); harbour.ReplacePort(rightPort); waitingBoats.Clear(); Simulate.AddToWaiting(5); UpdateWaitingBoats(); BoatData.ClearTable(leftPort.PortName); BoatData.ClearTable(rightPort.PortName); BoatData.ClearTable("WaitingBoats"); BoatData.UpdateVisitors(waitingBoats); BoatData.Update(leftPort); BoatData.Update(rightPort); Simulate.DaysPassed = 0; Simulate.BoatsRejected = 0; Simulate.BoatsAccepted = 0; UpdateLabels(); } }