コード例 #1
0
 public static void Winner()
 {
     if (win)            //testausgabe gewonnen
     {
         ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Content    = "Gewonnen!";
         ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Background = Brushes.Green;
         Gametimer.Stop();
     }
     else
     {
         return;       //textausgabe verloren
     }
 }
コード例 #2
0
        void StartNewGame(int width, int height, int bombCount)
        {
            Game = new Gameboard(width, height, bombCount);
            Game.Show(ContentCanvas);
            ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Background = Brushes.Transparent;
            ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Content    = "laufendes Spiel!";

            if (Gametimer.IsRunning())
            {
                Gametimer.Stop();
            }
            Gametimer.Init(lbl_Timer);
            Gametimer.Start();
        }
コード例 #3
0
        public void Click(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Right)
            {
                int bombFlaggedCount = 0;
                int flaggedCounter   = 0;
                int cwidth           = fieldArray.GetLength(0) - 1;
                int cheight          = fieldArray.GetLength(1) - 1;

                if (clicked)
                {
                    return;
                }

                if (flagged)
                {
                    btn.Content = "";
                }
                else
                {
                    btn.Content = "🚩";
                }

                flagged = !flagged;

                for (int a = 0; a <= cwidth; a++)
                {
                    for (int b = 0; b <= cheight; b++)
                    {
                        if (fieldArray[a, b].bomb == true && fieldArray[a, b].flagged == true)
                        {
                            bombFlaggedCount++;
                        }
                        if (fieldArray[a, b].flagged == true)
                        {
                            flaggedCounter++;
                        }
                    }
                }
                if ((bombFlaggedCount == Gameboard.bombCount) && (Gameboard.bombCount == flaggedCounter))
                {
                    Gameboard.win = true;
                }
                Gameboard.Winner();
            }
            if (e.ChangedButton == MouseButton.Left)
            {
                if (bomb == true)
                {
                    clicked     = true;
                    btn.Content = "boom";
                    if (clicked == true)
                    {
                        btn.Background = Brushes.Red;
                    }
                    ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Content    = "Verloren!";
                    ((MainWindow)System.Windows.Application.Current.MainWindow).lbl_Status.Background = Brushes.Red;
                    Gametimer.Stop();
                }
                else
                {
                    CheckNeighbor();
                    Gameboard.Winner();
                }
            }
        }