Exemplo n.º 1
0
        private void SolveButton_Click(object sender, RoutedEventArgs e)
        {
            this.game.Reset();
            this.game.CheckWinner();

            foreach (Canvas c in this.puzzlePieces)
            {
                PuzzleTile tile = c.Children[0] as PuzzleTile;
                tile.HideNumberLabel();
            }
        }
Exemplo n.º 2
0
        private void PuzzlePiece_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!this.game.IsPlaying)
            {
                foreach (Canvas c in this.puzzlePieces)
                {
                    PuzzleTile tile = c.Children[0] as PuzzleTile;
                    tile.ShowNumberLabel();
                }

                this.game.NewGame();
            }
        }
Exemplo n.º 3
0
        private void InitBoard()
        {
            int totalPieces = this.game.ColsAndRows * this.game.ColsAndRows;
            int pieceSize   = ImageSize / this.game.ColsAndRows;

            this.puzzlePieces = new Canvas[totalPieces];
            int nx = 0;

            for (int ix = 0; ix < this.game.ColsAndRows; ix++)
            {
                for (int iy = 0; iy < this.game.ColsAndRows; iy++)
                {
                    nx = (ix * this.game.ColsAndRows) + iy;

                    PuzzleTile tile = new PuzzleTile();
                    tile.SetValue(FrameworkElement.NameProperty, "PuzzleImage_" + nx);
                    tile.Height = pieceSize;
                    tile.Width  = pieceSize;
                    tile.Tag    = nx;

                    tile.ImageSize = ImageSize;
                    tile.PieceSize = pieceSize;
                    tile.XLocation = ix;
                    tile.YLocation = iy;

                    tile.LabelNumber = ((iy * this.game.ColsAndRows) + ix) + 1;

                    tile.SetValue(Canvas.TopProperty, 0.0);
                    tile.SetValue(Canvas.LeftProperty, 0.0);

                    this.puzzlePieces[nx] = new Canvas();
                    this.puzzlePieces[nx].SetValue(FrameworkElement.NameProperty, "PuzzlePiece_" + nx);
                    this.puzzlePieces[nx].Width  = pieceSize;
                    this.puzzlePieces[nx].Height = pieceSize;
                    this.puzzlePieces[nx].Children.Add(tile);
                    this.puzzlePieces[nx].MouseLeftButtonDown += this.PuzzlePiece_MouseLeftButtonDown;
                    if (nx < totalPieces - 1)
                    {
                        this.GameContainer.Children.Add(this.puzzlePieces[nx]);
                    }
                }
            }

            // Retrieve image
            StreamResourceInfo imageResource = Application.GetResourceStream(new Uri("WindowsPhonePuzzle;component/Assets/Tulips.jpg", UriKind.Relative));

            this.ImageStream = imageResource.Stream;

            this.game.Reset();
        }
Exemplo n.º 4
0
        public PuzzlePage()
        {
            InitializeComponent();

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;

            // Puzzle Game
            this.game = new PuzzleGame(3);

            this.game.GameStarted += delegate
            {
                this.ResetWinTransition.Begin();
                this.StatusPanel.Visibility              = Visibility.Visible;
                this.TapToContinueTextBlock.Opacity      = 0;
                this.TapToContinueTextBlockFront.Opacity = 0;
                this.TotalMovesTextBlock.Text            = this.game.TotalMoves.ToString();
            };

            this.game.GameOver += delegate
            {
                this.WinTransition.Begin();
                this.StatusPanel.Visibility   = Visibility.Visible;
                this.TotalMovesTextBlock.Text = this.game.TotalMoves.ToString();

                foreach (Canvas c in this.puzzlePieces)
                {
                    PuzzleTile tile = c.Children[0] as PuzzleTile;
                    tile.HideNumberLabel();
                }
            };

            this.game.PieceUpdated += delegate(object sender, PieceUpdatedEventArgs args)
            {
                int pieceSize = ImageSize / this.game.ColsAndRows;
                this.AnimatePiece(this.puzzlePieces[args.PieceId], Canvas.LeftProperty, (int)args.NewPosition.X * pieceSize);
                this.AnimatePiece(this.puzzlePieces[args.PieceId], Canvas.TopProperty, (int)args.NewPosition.Y * pieceSize);
                this.TotalMovesTextBlock.Text = this.game.TotalMoves.ToString();
            };

            this.InitBoard();
        }
Exemplo n.º 5
0
        private void InitBoard()
        {
            int totalPieces = this.game.ColsAndRows * this.game.ColsAndRows;
            int pieceSize = ImageSize / this.game.ColsAndRows;

            this.puzzlePieces = new Canvas[totalPieces];
            int nx = 0;
            for (int ix = 0; ix < this.game.ColsAndRows; ix++)
            {
                for (int iy = 0; iy < this.game.ColsAndRows; iy++)
                {
                    nx = (ix * this.game.ColsAndRows) + iy;

                    PuzzleTile tile = new PuzzleTile();
                    tile.SetValue(FrameworkElement.NameProperty, "PuzzleImage_" + nx);
                    tile.Height = pieceSize;
                    tile.Width = pieceSize;
                    tile.Tag = nx;

                    tile.ImageSize = ImageSize;
                    tile.PieceSize = pieceSize;
                    tile.XLocation = ix;
                    tile.YLocation = iy;

                    tile.LabelNumber = ((iy * this.game.ColsAndRows) + ix) + 1;

                    tile.SetValue(Canvas.TopProperty, 0.0);
                    tile.SetValue(Canvas.LeftProperty, 0.0);

                    this.puzzlePieces[nx] = new Canvas();
                    this.puzzlePieces[nx].SetValue(FrameworkElement.NameProperty, "PuzzlePiece_" + nx);
                    this.puzzlePieces[nx].Width = pieceSize;
                    this.puzzlePieces[nx].Height = pieceSize;
                    this.puzzlePieces[nx].Children.Add(tile);
                    this.puzzlePieces[nx].MouseLeftButtonDown += this.PuzzlePiece_MouseLeftButtonDown;
                    if (nx < totalPieces - 1)
                    {
                        this.GameContainer.Children.Add(this.puzzlePieces[nx]);
                    }
                }
            }

            // Retrieve image
            StreamResourceInfo imageResource = Application.GetResourceStream(new Uri("WindowsPhonePuzzle;component/Assets/Tulips.jpg", UriKind.Relative));
            this.ImageStream = imageResource.Stream;

            this.game.Reset();
        }