Esempio n. 1
0
        private void grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!isInDrag)
            {
                return;
            }
            var element = sender as System.Windows.UIElement;

            mouseLeftButtonDown = false;
            bool arranged = false;

            if (isDragging)
            {
                //Reset transform back to original position
                //if (!arranged)
                //{
                //    if (element != null) element.ReleaseMouseCapture();
                //    element.RenderTransform = new TranslateTransform();
                //    transform = new TranslateTransform();
                //    Grid.SetZIndex(element, 1);
                //    Console.WriteLine("No Intersection");
                //}

                try
                {
                    Grid.SetZIndex(draggingViewport, 1);
                    Grid.SetZIndex(dragCanvas, 1);
                }
                catch
                {
                }
                transform = new TranslateTransform();

                element.ReleaseMouseCapture();
                draggingViewport = null;
                isDragging       = false;
                isInDrag         = false;
                e.Handled        = true;
            }
        }
Esempio n. 2
0
        // creates the BOTTOM grid and adds buttons
        private void CreateGrid()
        {
            NewGame();
            bombsLeft.Text = MyVariables.mine.ToString();

            //clear everything to start anew
            tablero.RowDefinitions.Clear();
            tablero.ColumnDefinitions.Clear();


            //this creates the grid's rows and columns
            for (int i = 0; i < gridy.theGrid.GetLength(0); i++)
            {
                RowDefinition row = new RowDefinition();
                row.MinHeight = 25;
                tablero.RowDefinitions.Add(row);
            }

            for (int j = 0; j < gridy.theGrid.GetLength(1); j++)
            {
                ColumnDefinition col = new ColumnDefinition();
                col.MinWidth = 25;
                tablero.ColumnDefinitions.Add(col);
            }

            //colors
            SolidColorBrush color  = new SolidColorBrush(Colors.LightSeaGreen);
            SolidColorBrush color2 = new SolidColorBrush(Colors.MediumAquamarine);


            // create all the children
            for (int i = 0; i < gridy.theGrid.GetLength(0); i++)
            {
                for (int j = 0; j < gridy.theGrid.GetLength(1); j++)
                {
                    //textblock - background
                    TextBlock block = new TextBlock();
                    block.Text       = gridy.theGrid[i, j].Mine.ToString();
                    block.FontWeight = FontWeights.UltraBold;

                    //make the grid display a bomb when the array value is 9, else just the numbers of different colors
                    if (gridy.theGrid[i, j].Mine == 9)
                    {
                        string bomb = "💣";
                        block.Text = bomb;
                    }
                    else if (gridy.theGrid[i, j].Mine == 0)
                    {
                        block.Text = " ";
                    }
                    else if (gridy.theGrid[i, j].Mine == 1)
                    {
                        block.Foreground = Brushes.Green;
                    }
                    else if (gridy.theGrid[i, j].Mine == 2)
                    {
                        block.Foreground = Brushes.Orange;
                    }
                    else if (gridy.theGrid[i, j].Mine == 3)
                    {
                        block.Foreground = Brushes.DarkOrange;
                    }
                    else if (gridy.theGrid[i, j].Mine == 4)
                    {
                        block.Foreground = Brushes.Red;
                    }
                    else if (gridy.theGrid[i, j].Mine == 5)
                    {
                        block.Foreground = Brushes.Tomato;
                    }
                    else if (gridy.theGrid[i, j].Mine == 6)
                    {
                        block.Foreground = Brushes.DeepPink;
                    }
                    else if (gridy.theGrid[i, j].Mine == 7)
                    {
                        block.Foreground = Brushes.Navy;
                    }
                    else if (gridy.theGrid[i, j].Mine == 8)
                    {
                        block.Foreground = Brushes.DarkGray;
                    }

                    block.Background          = color2;
                    block.TextAlignment       = TextAlignment.Center;
                    block.VerticalAlignment   = VerticalAlignment.Bottom;
                    block.Width               = 23;
                    block.Height              = 23;
                    block.Padding             = new Thickness(0, 5, 0, 0);
                    block.VerticalAlignment   = VerticalAlignment.Center;
                    block.HorizontalAlignment = HorizontalAlignment.Center;
                    block.Name = "b" + i + "_" + j;



                    //boton - top--------------------------------------------

                    Button boton = new Button();

                    boton.Content               = " "; //remove later
                    boton.Background            = color;
                    boton.Width                 = 25;
                    boton.Height                = 25;
                    boton.VerticalAlignment     = VerticalAlignment.Center;
                    boton.HorizontalAlignment   = HorizontalAlignment.Center;
                    boton.Click                += new RoutedEventHandler(Button_Click);
                    boton.MouseRightButtonDown += new MouseButtonEventHandler(Button_rightclick); //right click event

                    //to find the button later on
                    //   boton.Name = "boton" + i + "_" + j;
                    boton.Tag = i + "_" + j; //since I can't RegisterName...

                    //locate and add the block
                    Grid.SetRow(block, i);
                    Grid.SetColumn(block, j);


                    //locate and add the button
                    Grid.SetRow(boton, i);
                    Grid.SetColumn(boton, j);


                    tablero.Children.Add(block);
                    tablero.Children.Add(boton);



                    //put the tablero at the bottom
                    Grid.SetZIndex(tablero, 0);
                }
            }
        }