Ejemplo n.º 1
0
        void OnContainerSizeChanged(object sender, EventArgs args)
        {
            View   container = (View)sender;
            double width     = container.Width;
            double height    = container.Height;

            if (width <= 0 || height <= 0)
            {
                return;
            }

            // Orient StackLayout based on portrait/landscape mode.
            stackLayout.Orientation = (width < height) ? StackOrientation.Vertical :
                                      StackOrientation.Horizontal;

            // Calculate tile size and position based on ContentView size.
            tileSize = Math.Min(width, height) / this.sp.width;
            absoluteLayout.WidthRequest  = this.sp.width * tileSize;
            absoluteLayout.HeightRequest = this.sp.width * tileSize;

            foreach (View fileView in absoluteLayout.Children)
            {
                SlidingPuzzleTile tile = SlidingPuzzleTile.Dictionary[fileView];

                // Set tile bounds.
                AbsoluteLayout.SetLayoutBounds(fileView, new Rectangle(tile.currentCol * tileSize, tile.currentRow * tileSize, tileSize, tileSize));
            }
        }
Ejemplo n.º 2
0
        async Task AnimateTile(int row, int col, int newRow, int newCol, uint length)
        {
            // The tile to be animated.
            SlidingPuzzleTile tile = tiles[row, col];
            View tileView          = tile.TileView;

            // The destination rectangle.
            Rectangle rect = new Rectangle(emptyCol * tileSize,
                                           emptyRow * tileSize,
                                           tileSize,
                                           tileSize);

            // Animate it!
            await tileView.LayoutTo(rect, length);

            // Set layout bounds to same Rectangle.
            AbsoluteLayout.SetLayoutBounds(tileView, rect);

            // Set several variables and properties for new layout.
            tiles[newRow, newCol] = tile;
            tile.currentRow       = newRow;
            tile.currentCol       = newCol;
            tiles[row, col]       = null;
            emptyRow = row;
            emptyCol = col;
        }
Ejemplo n.º 3
0
        async void OnTileTapped(object sender, EventArgs args)
        {
            if (isBusy)
            {
                return;
            }

            isBusy = true;

            View tileView = (View)sender;
            SlidingPuzzleTile tappedTile = SlidingPuzzleTile.Dictionary[tileView];

            taps.Add(new Tuple <int, int>(emptyRow, emptyCol));
            await ShiftIntoEmpty(tappedTile.currentRow, tappedTile.currentCol);

            isBusy = false;
            await isPuzzleSolved();
        }
Ejemplo n.º 4
0
        public SlidingPuzzlePage(SlidingPuzzle sp, Attraction attraction)
        {
            InitializeComponent();
            this.gc          = GameController.getInstance();
            subtitles.Source = ServerConection.URL_MEDIA + "subtitles.jpg";
            info.Source      = ServerConection.URL_MEDIA + "info.jpg";
            playVideo.Source = ServerConection.URL_MEDIA + "playVideo.jpg";
            how.Source       = ServerConection.URL_MEDIA + "how.png";
            this.sp          = sp;
            taps             = new List <Tuple <int, int> >();
            tiles            = new SlidingPuzzleTile[sp.width, sp.height];
            emptyRow         = sp.width - 1;
            emptyCol         = sp.height - 1;
            this.attraction  = attraction;

            for (int row = 0; row < sp.width; row++)
            {
                for (int col = 0; col < sp.height; col++)
                {
                    if (row == emptyRow && col == emptyCol)
                    {
                        break;
                    }
                    SlidingPuzzleTile tile = new SlidingPuzzleTile(row, col, sp.piecesURLS[row * sp.width + col]);

                    TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
                    tapGestureRecognizer.Tapped += OnTileTapped;
                    tile.TileView.GestureRecognizers.Add(tapGestureRecognizer);

                    tiles[row, col] = tile;
                    absoluteLayout.Children.Add(tile.TileView);
                }
            }

            shuffle();
        }