Ejemplo n.º 1
0
        public bool TryLoadGame(string filename)
        {
            if (!File.Exists(filename))
            {
                return(false);
            }

            using (var file = new StreamReader(filename))
                try
                {
                    game = Game.Game.FromGameSave(JsonConvert.DeserializeObject <GameSave>(file.ReadToEnd()));
                }
                catch (Exception e)
                {
                    MessageBox.Show(
                        @"Ошибка при загрузке. Файл поврежден.",
                        @"Ошибка",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
                               Path.DirectorySeparatorChar +
                               $"Error_{DateTime.UtcNow.ToShortDateString()}_" +
                               $"{DateTime.UtcNow.ToShortTimeString().Replace(":", "-")}_" +
                               $"{Guid.NewGuid()}.txt";
                    File.WriteAllText(path, e.ToString());
                    return(false);
                }

            field = game.Field;
            ClearClickedPoint();
            form.UpdateLabels();
            form.UpdateButtons();
            form.Invalidate();
            return(true);
        }
Ejemplo n.º 2
0
        public void StartNewGame()
        {
            game                = new Game.Game(9);
            field               = game.Field;
            game.BallMoving    += form.OnBallMoving;
            field.FieldUpdated += () => form.Invalidate();

            form.UpdateLabels();
            form.UpdateButtons();
            form.Invalidate();
        }