Пример #1
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();
        }
Пример #2
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();
                }
            }
        }