Beispiel #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);
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #3
0
        public void Initialize()
        {
            Player PlayerOne = new Player("TestPlayer1", Colors.Red);
            Player PlayerTwo = new Player("TestPlayer2", Colors.Blue);

            state = new GameStateWrapper
            {
                PlayerOne           = PlayerOne,
                PlayerTwo           = PlayerTwo,
                ActivePlayer        = PlayerOne,
                FieldSize           = 3,
                Lines               = new List <System.Tuple <Point, Point, Player> >(),
                Rectangles          = new List <System.Tuple <Point, Point, Player> >(),
                RegisteredRectCount = 0
            };

            mockDAccess = new Mock <ISquaresGameDataAccess>();
            mockDAccess.Setup(mock => mock.LoadGameAsync(It.IsAny <String>()))
            .Returns(() => Task.FromResult(state));

            model          = SquaresGameModel.FromSave(state, mockDAccess.Object);
            model.EndGame += EndGameAssert;
            model.EndGame += (sender, e) => ++ endGameRaised;
        }