public async void Register( )
        {
            _view = ViewPresenterManager.ResolveView(typeof(IStatisticView)) as IStatisticView;
            _main = MainPresenter.Get();

            var games = await DbLocal.FetchChessResults();

            var data = new StatisticViewData();

            data.TotalPlayed = games.Count();
            data.CountDraws  = games.Count(x => x.Winner == 0);
            data.CountLoses  = games.Count(x => x.Winner == 2);
            data.CountWins   = data.TotalPlayed - data.CountLoses - data.CountDraws;
            int maxLen     = 0;
            int currentMax = 0;

            foreach (var game in games)
            {
                if (game.Winner == 1)
                {
                    currentMax++;
                }
                else
                {
                    if (maxLen < currentMax)
                    {
                        maxLen = currentMax;
                    }
                }
            }
            data.LongestWins = maxLen;

            _view.Start(data);
            _main.QueryForSetupView(_view as UserControl);
        }
        public async void Register( )
        {
            _main = MainPresenter.Get();
            _view = ViewPresenterManager.ResolveView(typeof(IRemoteSetupView)) as IRemoteSetupView;

            var users = await DbLocal.FetchUsers();

            _view.Contacts  = users?.ToList();
            _view.StartGame = (addr) => {
                var gamePres = new ChessBoardPresenter();
                var canPlay  = RemoteManager.ConnectTo(new Connection {
                    Address = addr.Split(':')[0],
                    Port    = addr.Split(':')[1]
                });
                if (canPlay)
                {
                    _main.ShowInfo("Невозможно подключиться");
                    _main.ReleaseControl();
                    return;
                }
                gamePres.Register(new Model.Game.Chess.ChessSettings {
                    Type          = Model.Game.Chess.GameType.Remote,
                    IsWhite       = true,// TODO:
                    SecondLimited = -1
                });
            };
            _view.Cancel = () => {
                _main.ReleaseControl();
            };

            _view.Start();
            _main.QueryForSetupView(_view as UserControl);
        }
        public void Register(ChessSettings settings)
        {
            _settings = settings;
            _board    = ViewPresenterManager.ResolveView(typeof(IChessBoardView))
                        as IChessBoardView;
            _main = MainPresenter.Get();

            _board.Start(settings);
            string gameType;

            if (_settings.Type == GameType.Single)
            {
                gameType = "single chess";
            }
            else if (_settings.Type == GameType.AgainstPC)
            {
                gameType = "bot chess";
            }
            else
            {
                gameType = "remote chess";
            }

            _game = GameFactory.GetGame(gameType);

            _game.MoveReceived = (move) => {
                _needMoveWhite = !_needMoveWhite;
                _countMoves++;
                _board.SetChange(move as Tuple <BPosition, BPosition>);
            };

            _game.MessagesReceived = (message) => {
                _main.AddChatMessage(message);
            };

            _game.Settings = settings;
            _game.Open();


            _main.QueryForSetupView((UserControl)_board);

            _board.SetupState(GameState.Initial, true);
            _board.GameReady      = GameStarted;
            _board.StateChanged   = GameStateChanged;
            _board.CancelLastMove = () => {
                return(_game.QueryCancelMove());
            };
            _board.SetText("Начало игры");
            _board.GetMovesFrom = (item) => _game.GetValidMoves(item).Select(x => (BPosition)x).ToList();

            if (_game.HaveChat)
            {
                _main.ShowChat();
            }
            else
            {
                _main.HideChat();
            }
        }
Exemplo n.º 4
0
        public void Register( )
        {
            _main = MainPresenter.Get();
            var view = ViewPresenterManager.ResolveView(typeof(ISettingsView));

            _main.QueryForSetupView(view as UserControl);
            _view        = view as ISettingsView;
            _view.Data   = Config.Get();
            _view.Cancel = () => {
                _main.ReleaseControl();
            };
            _view.Save = data =>
            {
                Config.Set(data);
                SettingsManager.Save();
                _main.ReleaseControl();
            };

            _view.Start();
        }