Ejemplo n.º 1
0
        private static void DropOneSpotIfEmptyBelow(PuzzlePiece pieceToDrop, List<PuzzlePiece> puzzlePieces)
        {
            var orbBelow = puzzlePieces.SingleOrDefault(pp => pp.Location.Column == pieceToDrop.Location.Column
                                                           && pp.Location.Row == pieceToDrop.Location.Row + 1);

            if (orbBelow == null && pieceToDrop.Location.Row != AppGlobals.PuzzleGridRowCount -1)
            {
                _orbMoved = true;
                pieceToDrop.Location.Row += 1;
            }
        }
Ejemplo n.º 2
0
        private static List<PuzzlePiece> WalkSouthMatchingOrbs(PuzzlePiece northMostConnectedMatchingPiece, List<PuzzlePiece> matchingPieces, List<PuzzlePiece> allPuzzlePieces)
        {
            matchingPieces.Add(northMostConnectedMatchingPiece);

            PuzzlePiece nextPiece = northMostConnectedMatchingPiece;
            do
            {
                nextPiece = allPuzzlePieces.SingleOrDefault(pp => pp.Location.Column == nextPiece.Location.Column
                                                               && pp.Location.Row == nextPiece.Location.Row + 1
                                                               && pp.Type == nextPiece.Type);

                nextPiece = AddPieceIfTypeMatches(northMostConnectedMatchingPiece, nextPiece, matchingPieces);
            } while (nextPiece != null);

            return matchingPieces;
        }
Ejemplo n.º 3
0
        private static void MovePiece(PuzzlePiece piece)
        {
            var image = piece.Element;
            image.RenderTransform = piece._dragTranslation;

            DoubleAnimation moveAnim = new DoubleAnimation();
            moveAnim.Duration = TimeSpan.FromMilliseconds(400);

            moveAnim.From = piece._dragTranslation.Y;

            piece.SetPosition(piece.Location.Row, piece.Location.Column);
            moveAnim.To = piece._dragTranslation.Y;

            Storyboard.SetTarget(moveAnim, image);
            Storyboard.SetTargetProperty(moveAnim, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
            AppGlobals.PuzzleStoryBoard.Children.Add(moveAnim);
        }
Ejemplo n.º 4
0
        private void AddMatchText(PuzzlePiece puzzlePiece)
        {
            var orbImage  = puzzlePiece.Element;
            var grid = orbImage.Parent as Grid;
            var extraHeighPadding = Application.Current.Host.Content.ActualHeight - grid.ActualHeight;

            var modalPosition = new TranslateTransform();
            modalPosition.X = puzzlePiece._dragTranslation.X;
            modalPosition.Y = puzzlePiece._dragTranslation.Y + extraHeighPadding;

            _textModal = new Popup();

            var textModalContent = new OrbMatchText();
            textModalContent.Height = orbImage.ActualHeight;
            textModalContent.Width = orbImage.ActualWidth;
            textModalContent.TextContent.Text = "" + _matchCount;

            _textModal.Child = textModalContent;
            _textModal.RenderTransform = modalPosition;
            _textModal.IsOpen = true;
        }
Ejemplo n.º 5
0
 private void AddOrb(int row, int column, List<PuzzlePiece> puzzlePieces)
 {
     var orb = new PuzzlePiece(row, column);
     puzzlePieces.Add(orb);
     _grid.Children.Add(orb.Element);
 }
Ejemplo n.º 6
0
        private static PuzzlePiece GetNorthMostConnectedMatchingPiece(PuzzlePiece puzzlePiece, List<PuzzlePiece> allPuzzlePieces)
        {
            bool foundNorthMostConnectedMatchingPiece;
            PuzzlePiece currentPiece = puzzlePiece;
            do
            {
                foundNorthMostConnectedMatchingPiece = true;
                var nextPiece = allPuzzlePieces.SingleOrDefault(pp => pp.Location.Column == currentPiece.Location.Column
                                                             && pp.Location.Row == currentPiece.Location.Row - 1
                                                             && pp.Type == currentPiece.Type);

                if (nextPiece != null)
                {
                    currentPiece = nextPiece;
                    foundNorthMostConnectedMatchingPiece = false;
                }
            } while (!foundNorthMostConnectedMatchingPiece);

            return currentPiece;
        }
Ejemplo n.º 7
0
        private static PuzzlePiece AddPieceIfTypeMatches(PuzzlePiece origionalPiece, PuzzlePiece possibleMatch, List<PuzzlePiece> puzzlePieces)
        {
            if (possibleMatch == null)
            {
                return null; 
            }

            if (origionalPiece.Type == possibleMatch.Type && !possibleMatch.Matched)
            {
                puzzlePieces.Add(possibleMatch);
                return possibleMatch;
            }

            return null;
        }
Ejemplo n.º 8
0
        private static List<PuzzlePiece> GetMatchingColumnNeighbors(PuzzlePiece piece, List<PuzzlePiece> puzzlePieces)
        {
            var matchingPieces = new List<PuzzlePiece>();
            matchingPieces.Add(piece);

            PuzzlePiece nextPiece = piece;
            do
            {
                nextPiece = puzzlePieces.SingleOrDefault(pp => pp.Location.Column == nextPiece.Location.Column
                                                            && pp.Location.Row == nextPiece.Location.Row + 1);

                nextPiece = AddPieceIfTypeMatches(piece, nextPiece, matchingPieces);
            } while (nextPiece != null);

            return matchingPieces;
        }
Ejemplo n.º 9
0
        private DoubleAnimation GetAnimation(PuzzlePiece puzzlePiece)
        {
            var opacityAnimation = new DoubleAnimation
            {
                To = 0,
                From = 1,
                Duration = TimeSpan.FromMilliseconds(400)
            };

            Storyboard.SetTarget(opacityAnimation, puzzlePiece.Element);
            Storyboard.SetTargetProperty(opacityAnimation,
                                            new PropertyPath(Image.OpacityProperty));

            return opacityAnimation;
        }