Exemplo n.º 1
0
 public void Activate()
 {
     if (!IsRevealed && !IsFlagged)
     {
         IsRevealed    = true;
         BTN.IsEnabled = false;
         board.UnrevealedButtons.Remove(this);
         if (IsMine)
         {
             BTN.Background = Brushes.Red;
             Image i = new Image();
             i.Source    = new BitmapImage(new Uri("Assets/Mine.png", UriKind.Relative));
             BTN.Content = i;
             board.GameOver();
         }
         else
         {
             // Set Text to number of neighbors.
             int Count = board.CountMineNeighbors(X, Y);
             if (Count > 0)
             {
                 BTN.Content    = Count;
                 BTN.Foreground = Colors[Count - 1];
                 board.RevealedButtons.Add(this);
             }
             else
             {
                 // 0 neighbors that are mines, so activate each one.
                 foreach (RelativePositions pos in Enum.GetValues(typeof(RelativePositions)))
                 {
                     MineButton b = GetNeighbor(pos);
                     if (b != null && b.IsRevealed == false)
                     {
                         b.Activate();
                     }
                 }
             }
         }
     }
 }