Пример #1
0
        public void PerformMove(BoardPosition piece, MainWindow.Surround move)
        {
            BoardPosition swappingPiece;

            switch (move)
            {
            case MainWindow.Surround.Top:
                swappingPiece = this.TopOf(piece);
                break;

            case MainWindow.Surround.Right:
                swappingPiece = this.RightOf(piece);
                break;

            case MainWindow.Surround.Bottom:
                swappingPiece = this.BottomOf(piece);
                break;

            case MainWindow.Surround.Left:
                swappingPiece = this.LeftOf(piece);
                break;

            default:
                throw new ArgumentOutOfRangeException("move");
            }

            if (swappingPiece == null)
            {
                return;
            }

            var movePiecePosition = piece.ArrayPosition;
            var swappingPosition  = swappingPiece.ArrayPosition;

            swappingPiece.ArrayPosition = movePiecePosition;
            piece.ArrayPosition         = swappingPosition;

            this[swappingPiece.ArrayPosition.Y, swappingPiece.ArrayPosition.X] = swappingPiece;
            this[piece.ArrayPosition.Y, piece.ArrayPosition.X] = piece;
        }
Пример #2
0
        private IEnumerable <BoardPosition> GetBoardPieces(IVirtualBoard board, BoardPosition piece, MainWindow.Surround direction)
        {
            Func <BoardPosition, BoardPosition> dir = p =>
            {
                switch (direction)
                {
                case MainWindow.Surround.Top:
                    return(board.TopOf(p));

                case MainWindow.Surround.Right:
                    return(board.RightOf(p));

                case MainWindow.Surround.Bottom:
                    return(board.BottomOf(p));

                case MainWindow.Surround.Left:
                    return(board.LeftOf(p));

                default:
                    throw new ArgumentOutOfRangeException("direction");
                }
            };

            var borderingPiece = dir(piece);

            if (borderingPiece != null && borderingPiece.Piece.RootBoardPiece == piece.Piece.RootBoardPiece)
            {
                yield return(borderingPiece);

                var borderingPiece2 = dir(borderingPiece);
                if (borderingPiece2 != null && borderingPiece2.Piece.RootBoardPiece == piece.Piece.RootBoardPiece)
                {
                    yield return(borderingPiece2);
                }
            }
        }