Exemple #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);
            }
        }
        public async Task LoadGameAsync(String filePath)
        {
            if (dataAccess == null)
            {
                throw new InvalidOperationException("No data access is provided.");
            }

            GameStateWrapper state = await dataAccess.LoadGameAsync(filePath);

            this.GameEnded           = false;
            this.FieldSize           = state.FieldSize;
            this.PlayerOne           = state.PlayerOne;
            this.PlayerTwo           = state.PlayerTwo;
            this.ActivePlayer        = state.ActivePlayer;
            this.lines               = state.Lines;
            this.linesToEnd          = CalcLinesToEnd();
            this.rectangles          = state.Rectangles;
            this.registeredRectCount = state.RegisteredRectCount;
        }