private void MainWindow_Closed(object sender, EventArgs e) { if (!Lost) { StringBuilder mapBuilder = new StringBuilder(); for (int x = 0; x < GameMap.Size; ++x) { for (int y = 0; y < GameMap.Size; ++y) { var tile = GameMap.GetTile(x, y); string tileStr = tile is null ? "-" : IntStringBaseConverter.LongToBase((int)tile.Parent.Shape); mapBuilder.Append(tileStr); } } Properties.Settings.Default.SavedScore = Engine.Engine.Score; var figure0 = Showcase.Maps[0].Figure; var figure1 = Showcase.Maps[1].Figure; var figure2 = Showcase.Maps[2].Figure; Properties.Settings.Default.SavedShowcase0 = figure0 is not null ? (int)figure0.Shape : -1; Properties.Settings.Default.SavedShowcase1 = figure1 is not null ? (int)figure1.Shape : -1; Properties.Settings.Default.SavedShowcase2 = figure2 is not null ? (int)figure2.Shape : -1; Properties.Settings.Default.SavedMap = mapBuilder.ToString(); Properties.Settings.Default.IsSaved = true; Properties.Settings.Default.Save(); } }
private void TryLoadFromSave() { if (Properties.Settings.Default.IsSaved) { Engine.Engine.Score = Properties.Settings.Default.SavedScore; Title = "ะกััั: " + Engine.Engine.Score + " / " + Properties.Settings.Default.BestScore; if (Properties.Settings.Default.SavedShowcase0 != -1) { var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase0); Showcase.Pick(Showcase.Maps[0].Figure); figure.TryPutOnMap(Showcase.Maps[0], new Location(0, 0)); } else { Showcase.Maps[0].Figure = null; } if (Properties.Settings.Default.SavedShowcase1 != -1) { var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase1); Showcase.Pick(Showcase.Maps[1].Figure); figure.TryPutOnMap(Showcase.Maps[1], new Location(0, 0)); } else { Showcase.Maps[1].Figure = null; } if (Properties.Settings.Default.SavedShowcase2 != -1) { var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase2); Showcase.Pick(Showcase.Maps[2].Figure); figure.TryPutOnMap(Showcase.Maps[2], new Location(0, 0)); } else { Showcase.Maps[2].Figure = null; } var savedMap = Properties.Settings.Default.SavedMap; for (int x = 0; x < GameMap.Size; ++x) { for (int y = 0; y < GameMap.Size; ++y) { string tileStr = savedMap[x * 10 + y].ToString(); if (tileStr != "-") { FigureShape shape = (FigureShape)IntStringBaseConverter.BaseToLong(tileStr); Tile tile = new Tile(new Location(x, y), new Figure(shape)); GameMap.SetTile(x, y, tile); } } } } }