Example #1
0
        private async Task LoadGame(String path)
        {
            try
            {
                if (model == null)
                {
                    GameStateWrapper state = await dataAccess.LoadGameAsync(path);

                    model = SquaresGameModel.FromSave(state, dataAccess);
                    NewGame(model);
                }
                else
                {
                    await model.LoadGameAsync(path);

                    p1NameLabel.Text = model.PlayerOne.PlayerName;
                    p2NameLabel.Text = model.PlayerTwo.PlayerName;
                }
                InitDots(model.FieldSize);
                UpdateUI(this, EventArgs.Empty);
            }
            catch (Exception excp)
            {
                MessageBox.Show(excp.Message);
            }
        }
Example #2
0
        public async void LoadGame()
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            if (openDialog.ShowDialog() == true)
            {
                try
                {
                    if (model == null)
                    {
                        GameStateWrapper state = await persistence.LoadGameAsync(openDialog.FileName);

                        model = SquaresGameModel.FromSave(state, persistence);
                        NewGame(model);
                    }
                    else
                    {
                        await model.LoadGameAsync(openDialog.FileName);

                        PlayerOne.Player = model.PlayerOne;
                        PlayerTwo.Player = model.PlayerTwo;
                    }
                    FieldSize = model.FieldSize;
                    InitDots(FieldSize);
                    UpdateUI(this, EventArgs.Empty);
                }
                catch (Exception excp)
                {
                    System.Windows.MessageBox.Show(excp.Message);
                }
            }
        }