Ejemplo n.º 1
0
        /// <summary>Изменение состояния игры.</summary>
        /// <param name="value">Новое состояние игры.</param>
        /// <param name="args">Дополнительные аргументы, если надо.</param>
        void SetGameStatus(GameStatuses value, object args = null)
        {
            // Сравнение с текущим состоянием.
            if (GameStatus == value)
            {
                return;
            }

            // Присваивание нового значения состояния.
            GameStatus = value;

            // Создание события с разными параметрами в зависимости от переданного значения args.
            // Если args пустое, то в событие передаётся только новое состояние игры.
            // Иначе - передаётся массив из двух элементов: новое состояние игры и параметр args.
            if (args == null)
            {
                ChangedStateEvent?.Invoke(this, new ChangedStateHandlerArgs(NamesState.GameStatus, value));
            }
            else
            {
                // Если новое состояние это победа или ничья, то обновляется статистика.
                if (GameStatus == GameStatuses.Win || GameStatus == GameStatuses.Draw)
                {
                    if (GameStatus == GameStatuses.Win)
                    {
                        RepoStatistic.SaveStatistic(Gamers, CurrentGamerId == Gamers[0].Id, CurrentGamerId == Gamers[1].Id);                        // SaveStatistic();
                    }
                    else
                    {
                        RepoStatistic.SaveStatistic(Gamers, false, false);
                    }
                }
                ChangedStateEvent?.Invoke(this, new ChangedStateHandlerArgs(NamesState.GameStatus, new object[] { value, args }));
            }
        }
Ejemplo n.º 2
0
        private void OnStartUp(object sender, StartupEventArgs e)
        {
            ///<remarks>Подсоединение обработчика закрытия окна</remarks>
            window.Closed += Window_Closed;

            ///<remarks>Заполнение словаря соответствий</remarks>
            controls.Add(typeof(IFirstScreenVM), firstScreenUC);
            controls.Add(typeof(IStatisticVM), statisticUC);
            controls.Add(typeof(ISettingsVM), settingsUC);
            controls.Add(typeof(IStatusesVM), gameUC);

            //controls.Add(typeof(IGameEndVM), gameEndUC);
            //controls.Add(typeof(IGameEndDrawVM), drawUC);


            ChangeWindowContent(typeof(IFirstScreenVM));

            IReposSaveGame  reposGame      = new ReposSaveGameXML("SavedGame.xml");
            IReposStatistic reposStatistic = new RepoStatistic("Statistic.xml");

            //Model.ModelTicTacToe.FileNameXml = ;
            model = new ModelTicTacToe(reposGame, reposStatistic);
            //MainViewModel viewModel = new MainViewModel(ChangeWindowContent);
            StatisticVM statisticVM = new StatisticVM(ChangeWindowContent, reposStatistic);
            MainVM      viewModel   = new MainVM(ChangeWindowContent, model, 3, 3, 3, statisticVM);

            viewModel.CellTypes.Add(CellTypeDto.Empty);
            viewModel.CellTypes.Add(CellTypeDto.Cross);
            viewModel.CellTypes.Add(CellTypeDto.Zero);
            viewModel.FirstGamer.CellType  = viewModel.CellTypes[1];
            viewModel.SecondGamer.CellType = viewModel.CellTypes[2];
            ImageSource[] images =
            {
                (ImageSource)imageSourceConverter.ConvertFrom(new Uri("pack://application:,,,/View;component/Resources/Images/cross.png")),
                (ImageSource)imageSourceConverter.ConvertFrom(new Uri("pack://application:,,,/View;component/Resources/Images/zero.png")),
                (ImageSource)imageSourceConverter.ConvertFrom(new Uri("pack://application:,,,/View;component/Resources/Images/yes.png")),
                (ImageSource)imageSourceConverter.ConvertFrom(new Uri("pack://application:,,,/View;component/Resources/Images/no.png"))
            };

            viewModel.FirstGamer.Image       = images[0];
            viewModel.SecondGamer.Image      = images[1];
            viewModel.FirstGamer.ImageIndex  = 0;
            viewModel.SecondGamer.ImageIndex = 1;
            viewModel.PiecesCollection       = images;
            //viewModel.IsRevenge = File.Exists(Model.FileNameXml);

            window.DataContext = viewModel;
            window.Show();
        }