Ejemplo n.º 1
0
            void SweepButton_Click(object sender, RoutedEventArgs e)
            {
                SweepButton sb = sender as SweepButton;

                if (!sb.IsEnabled)
                {
                    return;
                }
                if ((string)sb.Content != "*")
                {
                    sb.IsEnabled = false;
                    if (sb.Bombs == 9)
                    {
                        sb.Content = "#";

                        for (int i = 0; i < 10; i++)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                Mines[10 * i + j].IsEnabled = false;
                            }
                        }
                        MessageBox.Show("You are dead!!");
                    }

                    sb.Content = sb.Bombs;
                    if (sb.Bombs == 0)
                    {
                        sb.Content = "";
                        for (int temp1 = -1; temp1 < 2; temp1++)
                        {
                            for (int temp2 = -1; temp2 < 2; temp2++)
                            {
                                if (_coloum + temp1 >= 0 && _coloum + temp1 <= 9)
                                {
                                    if (_row + temp2 >= 0 && _row + temp2 <= 9)
                                    {
                                        Mines[10 * (_coloum + temp1) + _row + temp2].SweepButton_Click(Mines[10 * (_coloum + temp1) + _row + temp2], e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
Ejemplo n.º 2
0
        public Sweeper()
        {
            for (int i = 0; i < 100; i++)
            {
                Mines[i] = new SweepButton();
            }


            InitializeComponent();

            // Create the filed

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Mines[10 * i + j].Margin = new Thickness(21 * i, 21 * j, 0, 0);
                    gridBombZone.Children.Add(Mines[10 * i + j]);
                }
            }
        }