Example #1
0
        private void AnimateMoveTask(MoveTask moveTask, bool isUndo)
        {
            MoveAnimationsFactory moveAnimationsFactory = new MoveAnimationsFactory();

            foreach (var pieceMove in moveTask.MovedPiecesCoordinates)
            {
                Coordinate fromCoordinate = isUndo ? pieceMove.Item2 : pieceMove.Item1;
                Coordinate toCoordinate   = isUndo ? pieceMove.Item1 : pieceMove.Item2;

                Point animationStartPoint = GetCoordinatePositionOnBoard(fromCoordinate);
                Point animationEndPoint   = GetCoordinatePositionOnBoard(toCoordinate);

                ContentPresenter pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(ViewModel.GetPiece(toCoordinate));
                moveAnimationsFactory.AddMoveAnimation(pieceItemView, animationStartPoint, animationEndPoint);
            }

            if (moveTask.CapturedPieceCoordinate != null)
            {
                // if is not undo the removed piece is marked to be removed and only removed after the animation
                ChessPieceViewModel removedPiece  = isUndo ? ViewModel.GetPiece(moveTask.CapturedPieceCoordinate) : ViewModel.GetRemovedPiece(moveTask.CapturedPieceCoordinate);
                ContentPresenter    pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(removedPiece);
                moveAnimationsFactory.AddRemoveAnimation(pieceItemView);
            }

            moveAnimationsFactory.StoryBoard.Completed += (o, e) =>
            {
                moveTask.CompleteTask();
                IsHitTestVisible = true;
            };

            moveAnimationsFactory.StoryBoard.Begin();
            // dont allow user interactions with the board for the duration of the animation
            IsHitTestVisible = false;
        }
 public MoveSimulator(ChessPieceViewModel piece, Field targetField)
 {
     _piece = piece;
     CopyGameState();
     _kingUnderCheckTest = GetKingUnderCheckTest(_piece.IsBlack);
     _tempPiece          = GetTempPiece();
     DoImaginaryMove(targetField);
 }
Example #3
0
 public PickPiecePopUp(bool black, ChessPieceViewModel piece)
 {
     WindowStartupLocation = WindowStartupLocation.CenterScreen;
     ResizeMode            = ResizeMode.NoResize;
     InitializeComponent();
     _black        = black;
     SelectedPiece = piece;
     CheckColor();
 }
Example #4
0
        public PushToStack(Field target, int column, int row, ChessPieceViewModel piece)
        {
            this.piece = piece;
            string MtargetR = getValueRow(target.Row);
            string MtargetM = getValueCol(target.Column);
            string Mcolumn  = getValueCol(column);
            string Mrow     = getValueRow(row);

            Chessboard.stackMsg.Add(finalizeString(MtargetM, MtargetR, Mcolumn, Mrow));
        }
Example #5
0
 private void PickKnight_OnClick(object sender, RoutedEventArgs e)
 {
     SelectedPiece = new Knight
     {
         Row        = SelectedPiece.Row,
         Column     = SelectedPiece.Column,
         IsBlack    = SelectedPiece.IsBlack,
         IsSelected = SelectedPiece.IsSelected
     };
     PieceTransform();
 }
        private void SwitchPiece(ChessPieceViewModel piece)
        {
            Formation.Pieces.Remove(piece);
            Formation.Pieces.Add(PickPiecePopUp.SelectedPiece);

            if (MainWindow.Remote)
            {
                UpdateGameState();
            }

            CheckOrCheckmateOrPatt();
        }
Example #7
0
        public PushToStack(Field targetField, int column, int row, int RCol, int RTCol, ChessPieceViewModel piece)
        {
            this.piece = piece;
            string KRow     = getValueRow(row);
            string KCol     = getValueCol(column);
            string KTRow    = getValueRow(targetField.Row);
            string KTCol    = getValueCol(targetField.Column);
            string RTColumn = getValueCol(RTCol);
            string RColumn  = getValueCol(RCol);

            Chessboard.stackMsg.Add(finalizeString(KRow, KCol, KTRow, KTCol, RTColumn, RColumn));
        }
Example #8
0
        private void EndDragMove()
        {
            if (!isDragStarted)
            {
                return;
            }

            dragCanvas.Children.Clear();

            isDragStarted = false;

            dragSourcePieceViewModel.IsDragSource = false;
            dragSourcePieceViewModel = null;
            pointerPressSquare       = null;
            dropHintEllipse          = null;
        }
        private void PrepForNextRound(ChessPieceViewModel piece, Field targetField)
        {
            Move.ValidateMove(piece, targetField);
            CheckPawnLastRow(piece);
            CheckForKingLastStanding();

            piece.IsSelected = false;

            // TODO Wait till PickPiecePopup closes!
            if (ChessPieceMove.SwapPlayer)
            {
                CheckLabel.Content        = "";
                ChessPieceMove.SwapPlayer = false;
                SwapPlayer();
            }
        }
Example #10
0
        private void OnSquarePointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (!isDragStarted && pointerPressSquare != null && e.Pointer.IsInContact)
            {
                SquareViewModel squareVM = (SquareViewModel)pointerPressSquare.DataContext;
                dragSourcePieceViewModel = ViewModel.GetPiece(squareVM.Coordinate);

                if (dragSourcePieceViewModel != null)
                {
                    PointerPoint pointerPoint = e.GetCurrentPoint(board);
                    if (!HasPointerMovedEnaugh(pointerPoint.Position))
                    {
                        return;
                    }

                    StartDragMove(e.Pointer, pointerPoint);
                }
            }
        }
        public void CheckPawnLastRow(ChessPieceViewModel piece)
        {
            var type = piece.GetType();

            if (type == typeof(Pawn))
            {
                if (piece.IsBlack && piece.Row == 7)
                {
                    PickPiecePopUp pfpu = new PickPiecePopUp(true, piece);
                    pfpu.Show();
                    pfpu.TrapOccurred += (sender, e) => SwitchPiece(piece);
                }
                else if (!piece.IsBlack && piece.Row == 0)
                {
                    PickPiecePopUp pfpu = new PickPiecePopUp(false, piece);
                    pfpu.Show();
                    pfpu.TrapOccurred += (sender, e) => SwitchPiece(piece);
                }
            }
        }
 public void ValidateMove(ChessPieceViewModel piece, Field targetField)
 {
     piece.TryMove(targetField, Formation.Pieces);
 }
 public MoveSimulator(King king)
 {
     CopyGameState();
     _kingUnderCheckTest = GetKingUnderCheckTest(king.IsBlack);
 }
 public MoveSimulator(Player activePlayer)
 {
     CopyGameState();
     _kingUnderCheckTest = GetKingUnderCheckTest(activePlayer.IsBlack);
 }