예제 #1
0
        private void SendTurnToInputController(object o, EventArgs args = null)
        {
            CellViewModel toCell = (CellViewModel)o;

            var         uiThread = Thread.CurrentThread;
            ThreadStart start    = delegate()
            {
                try
                {
                    _inputController.SendInput(_selectedCell.Cell, toCell.Cell, _isPawnTransformation ? toCell.Figure : null);
                }
                catch (Exception exception)
                {
                    Dispatcher uiDispatcher = Dispatcher.FromThread(uiThread) ?? Dispatcher.CurrentDispatcher;

                    Action act = delegate()
                    {
                        throw exception;
                    };

                    uiDispatcher.Invoke(DispatcherPriority.Normal, act);
                }

                //Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,
                //                                    new Action<Cell, Cell, Figure>(
                //                                        _inputController.SendInput),
                //                                    _selectedCell.Cell, toCell.Cell,
                //                                    _isPawnTransformation ? toCell.Figure : null);
            };

            (new Thread(start)).Start();

            _isPawnTransformation = false;
        }
예제 #2
0
        public bool MakeTurnExecute(CellViewModel fromCell, CellViewModel toCell)
        {
            if (fromCell != null && fromCell.Figure.IsWhite == IsWhiteGo && _field.MakeTurn(fromCell.Cell, toCell.Cell))
            {
                fromCell.CallFigurePropertyChanged();
                toCell.CallFigurePropertyChanged();

                RaisePropertyChanged("IsWhiteGo");
                RaisePropertyChanged("IsUnderCheck");

                ClearAllCellsFromSelection();
                return(true);
            }

            return(false);
        }
예제 #3
0
        public void MarkCellsForTurn(CellViewModel fromCell)
        {
            bool isWasSelected = fromCell.IsSelected;

            ClearAllCellsFromSelection();

            fromCell.IsSelected = !isWasSelected;
            if (fromCell.IsSelected)
            {
                _selectedCell = fromCell;

                if (fromCell.Figure != null)
                {
                    MarkCells(PrepareFieldViewModelCells(_field.PossibleTurns(fromCell.Cell)));
                }
            }
        }
예제 #4
0
        private void InputInformationExecute(object source, InputDataEventArgs args)
        {
            CellViewModel fromCell = Cells.Single(rec => rec.Cell == args.FromCell);
            CellViewModel toCell   = Cells.Single(rec => rec.Cell == args.ToCell);

            _makeTurnFromInputController = true;
            if (!MakeTurnExecute(fromCell, toCell))
            {
                throw new ChessGameException("Input with synchronisation error.");
            }

            if (args.FigureName != null)
            {
                toCell.TransformFigureOnCel(args.FigureName, toCell.Figure.IsWhite);
            }

            RaisePropertyChanged("IsWaiting");
        }
        public PawnTransformationViewModel(bool isWhite, CellViewModel cell)
        {
            IsWhite = isWhite;
            _cell   = cell;
            //IsPawnTransformationPopup = true;

            RookFigureCell        = new Cell(0, 0);
            RookFigureCell.Figure = new RookFigure(IsWhite, RookFigureCell);

            KnightFigureCell        = new Cell(0, 0);
            KnightFigureCell.Figure = new KnightFigure(IsWhite, KnightFigureCell);

            BishopFigureCell        = new Cell(0, 0);
            BishopFigureCell.Figure = new BishopFigure(IsWhite, BishopFigureCell);

            QueenFigureCell        = new Cell(0, 0);
            QueenFigureCell.Figure = new QueenFigure(IsWhite, QueenFigureCell);
        }
예제 #6
0
        public bool MakeTurn(CellViewModel toCell)
        {
            if (_inputController.IsWaiting)
            {
                return(false);
            }

            _makeTurnFromInputController = false;
            if (toCell.IsMarked && MakeTurnExecute(_selectedCell, toCell) && !_field.IsMateOnField)
            {
                if (!_isPawnTransformation)
                {
                    SendTurnToInputController(toCell);

                    RaisePropertyChanged("IsWaiting");
                }

                return(true);
            }

            return(false);
        }