WPF扫雷(注释+代码)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace _2扫雷
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        //在外面定义一个变量,用来循环10次,原因是行循环10次,列循环10次
        int rows = 10;
        //随机数
        Random r = new Random();
        //这个二维数组分别放行和列
        int[,] mines;
        //放图片的数组
        Image[,] images;
        //在外面定义一个判断值 //当前位置默认为false
        bool[,] overList;
        //定义10个炸弹
        int mineCount = 10;
        //计时器
        DispatcherTimer timer = new DispatcherTimer();
        //时间倒数
        int num = 60;
        //按钮记时
        Button kaishi = new Button();
        //记录步数
        Label Puji = new Label();
        //记录步数
        int x = 0;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
           /* for (int i = 0; i < rows; i++)
            {
                //把网格的行和列分成10*10的格子
                //创建行数
                RowDefinition row = new RowDefinition();
                GameBG.RowDefinitions.Add(row);
                //创建列数
                ColumnDefinition column = new ColumnDefinition();
                GameBG.ColumnDefinitions.Add(column);
            }
            //表示网格的线是否显示显示
            GameBG.ShowGridLines = true;*/

        Ge();
        //创建一个方法,用这个方法显示每个格子的东西显示
        InitialGame();

        //计时器
        // DispatcherTimer timer = new DispatcherTimer();
        //timer.Start();
        timer.Interval = TimeSpan.FromMilliseconds(1000);
        timer.Tick += Timer_Tick;
        /*//按钮记时
        Button kaishi = new Button();*/
        kaishi.Width = 200;
        kaishi.Height = 100;
        kaishi.Content = "开始游戏";
        kaishi.FontSize = 30;
        //表示把某个东西放在网格的那个具体格子
        Grid.SetColumn(kaishi, 1);
        Grid.SetRow(kaishi, 2);
        DA.Children.Add(kaishi);
        kaishi.Click += Kaishi_Click;

        /* //记录步数
         Label Puji = new Label();*/
        Puji.FontSize = 15;
        Puji.Content = "记录第" + x + "步";
        Puji.Margin = new Thickness(100,35,0,0);
        SK.Children.Add(Puji);

    }
    Label jifen = new Label();//这样指改变指不会创建多个
    private void Timer_Tick(object sender, EventArgs e)
    {
        /*Label jifen = new Label();*/
        num--;
        jifen.Content = "还剩" + num + "秒后结束";
        jifen.FontSize = 15;
        //设置外边距,上下左右距离
        jifen.Margin = new Thickness(230,-30,0,0);
        //不能放在这里,原因是每次回创建多个GameBG,所以里面含又多个
        //GameBG.Children.Add(jifen);
       
        if (num <= 1)
        {
            num =1;
            //MessageBox.Show("游戏时间到了");
            MessageBoxResult YX=MessageBox.Show("游戏时间到了,是否从新开始","警示", MessageBoxButton.YesNo,MessageBoxImage.Question);
            x = -1;
            if (YX==MessageBoxResult.Yes)
            {
                x++;
                Puji.Content = "记录第" + x + "步";
                num = 60;
                timer.Start();

                GameBG.Children.Clear();//先清除
                //SK.Children.Add(jifen);//每添加一次,就直接放进去
                //Ge();//先把每个格子从新放入
                InitialGame();//从新调用
            }
            else
            {
                //关闭页面
                this.Close();
            }
        }
    }

    private void Kaishi_Click(object sender, RoutedEventArgs e)
    {
        timer.Start();
        SK.Children.Add(jifen);//每添加一次,就直接放进去
        DA.Children.Remove(kaishi);
    }

    //总的网格数
    private void Ge()
    {
        for (int i = 0; i < rows; i++)
        {
            //把网格的行和列分成10*10的格子
            //创建行数
            RowDefinition row = new RowDefinition();
            GameBG.RowDefinitions.Add(row);
            //创建列数
            ColumnDefinition column = new ColumnDefinition();
            GameBG.ColumnDefinitions.Add(column);
        }
        //表示网格的线是否显示显示
        GameBG.ShowGridLines = true;
    }

    private void InitialGame()
    {
        //把每个网格的行和列放在mines数组里
        mines = new int[rows, rows];
        //给每个图片添加网格
        images = new Image[rows, rows];
        //当前位置默认为全是false
        overList = new bool[rows, rows];
        //用1数字来记录10个炸弹
        for (int i = 0; i < mineCount; i++)//循环10次炸弹
        {
            //GetLength表示指定元素的索引
            //随机出网格0代表行,1来表列
            int row = r.Next(0,mines.GetLength(0));
            int colmun = r.Next(0,mines.GetLength(1));
            //表示当行和列,标记==1,这个的值==1
            //当记录数字等于等于1时候表示以及记录过了,所以i循环的时候i--回去,从新随机,else不等于记录的数组时就为1
            if (mines[row,colmun]==1)
            {
                i--;
            }
            else
            {
                mines[row, colmun] = 1;
            }
        }

        //初始情况下所有的Image全部装zhuan
        for (int i = 0; i < mines.GetLength(0); i++)//控制行
        {
            for (int j = 0; j < mines.GetLength(1); j++)//控制列
            {
                //实例化一下图片
                images[i, j] = new Image();
                //然后给每个位置添加图片
                images[i, j].Source = new BitmapImage(new Uri("img/zhuan.gif", UriKind.Relative));
                //每个小格子的间距
                images[i, j].Margin = new Thickness(2,2,2,2);
                //附加属性设置为指定的对象,把这个图片添加到指定的x,y的具体位置上
                Grid.SetRow(images[i,j],i);//把每个图片放在每个对应图片
                Grid.SetColumn(images[i,j],j);//把图片平铺
                //给每个图片定义一个tag值,用一个数组定义,索引0,1
                //如果给成具体数字表示这张图片的tag值是什么数字代表
                images[i, j].Tag = new int[2] { i, j };
                //把每个图片添加到GameBG里面
                GameBG.Children.Add(images[i, j]);
                //鼠标的左键
                images[i, j].MouseLeftButtonDown += MainWindow_MouseLeftButtonDown;
                //鼠标的右键
                images[i, j].MouseRightButtonDown += MainWindow_MouseRightButtonDown;
            }
        }
    }
    //鼠标右键,表示有雷放个旗子
    private void MainWindow_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        //因为是局部变量,所以想要获取image具体的图片要用一个具体的事件触发者,谁创建的这个事件谁就是事件触发者
        Image img = sender as Image;
        //添加红旗图片
        img.Source = new BitmapImage(new Uri("img/qizi.gif", UriKind.Relative));
    }
    //鼠标左键
    private void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //因为是局部变量,所以想要获取image具体的图片要用一个具体的事件触发者,谁创建的这个事件谁就是事件触发者
        Image img = sender as Image;
        //获取图片的tag值,类型是数组
         int[] index=img.Tag as int[];

        x++;
        Puji.Content = "记录第" + x + "步";

        //点击的这个是一个安全地区
        //首先在执行这里时,在外面定义一个bool,用形参来判断满足的条件IsMine
        //IsMine(index[0],index[1]);
        if (!IsMine(index[0], index[1]))//true//返回不正确时进入//判断雷数
        {
            //要判断周围的地雷数,基本上所有的雷周围至少有3个,最多有8个相邻
            //假设当前这个是i,j,则需要考虑周围的(i-1,j),(i-1,j-1),(i,j-1),(i+1,j-1),(i+1,j),(i+1,j+1),(i,j+1),(i-1,j+1)
            //int count = CountMine(index[0], index[1]);\
            //调用x,y具体图片的位置tagzhi
            CountMine(index[0], index[1], img);//放雷数
            //判断剩下格子数量
            int left = 0;
            for (int i = 0; i < overList.GetLength(0); i++)
            {
                for (int j = 0; j < overList.GetLength(1); j++)
                {
                    if (overList[i, j] == false)
                    {
                        left++;
                    }
                }
            }
            if (left == mineCount)
            {
                MessageBoxResult SL=MessageBox.Show("获胜,是否进行下一关","闯关成功", MessageBoxButton.YesNo, MessageBoxImage.Question);
                x = -1;
                if (SL==MessageBoxResult.Yes)
                {
                    x++;
                    Puji.Content = "记录第" + x + "步";
                    //从新下一关倒数从新开始记录
                    num = 60;
                    GameBG.Children.Clear();
                    //先清除行和列
                    GameBG.RowDefinitions.Clear();
                    GameBG.ColumnDefinitions.Clear();
                    GameBG.Children.Clear();
                    //然后给增加行和列
                    rows += 5;
                    mineCount += 5;
                    //然后在清除整个页面的内容
                    //调用网格数
                    Ge();
                    //调用图片
                    InitialGame();
                }
                else
                {
                    GameBG.Children.Clear();
                    //调用网格数
                    Ge();
                    //调用图片
                    InitialGame();
                }
            }
        }
        else
        {
            for (int i = 0; i < mines.GetLength(0); i++)
            {
                for (int j = 0; j < mines.GetLength(1); j++)
                {
                    if (mines[i, j] == 1)
                    {
                        images[i, j].Source = new BitmapImage(new Uri("img/lei.gif", UriKind.Relative));
                    }
                }
            }
            /* MessageBox.Show("失败!");
             //失败后先清除失败之前的
             GameBG.Children.Clear();
             Ge();
             InitialGame();*/
            timer.Stop();
            MessageBoxResult shibai=MessageBox.Show("失败!是否从新开始游戏", "失败!", MessageBoxButton.YesNo, MessageBoxImage.Question);
            x = -1;
            if (shibai==MessageBoxResult.Yes)
            {
                x++;
                num = 60;
                Puji.Content = "记录第" + x + "步";
                GameBG.Children.Clear();
                timer.Start();//把记录倒数的数字,从新开始
                /*Ge();*/
                InitialGame();
            }
            else
            {
                this.Close();//关闭整个游戏窗口
            }
        }
       
    }

    void CountMine(int i, int j, Image img)
    {
        //判断死循环,判断当前位置被判断过了,在外面定义一个overList
        //因为外面默认值是false,所以if判断进来为true,然后return,下面的都不会执行
        /*1.先点击MainWindow_MouseLeftButtonDown
         * 2.判断雷数
         * 3. CountMine(index[0], index[1], img);进来overList[i,j]==false,不进入if(overList[i,j]==true)
         * 4.直接改变默认值false为overList[i, j] = true;
         * 5.第二次点击重复1、2、进入CountMine在判断,这个时候就可以进入overList[i,j]==true,return后面的就不会再执行了
         */
        if (overList[i,j]==true)
        {
            return;
        }
        //点击后改为true
        overList[i, j] = true;

        //用一个数字记录周围的雷数,如果还是0的话翻其他周围的牌子
        int count = 0;
        if (IsMine(i - 1, j))//为
        {
            //如果满足条件count++;加成1
            count++;
        }
        if (IsMine(i - 1, j - 1))
        {
            count++;
        }
        if (IsMine(i, j - 1))
        {
            count++;
        }
        if (IsMine(i + 1, j - 1))
        {
            count++;
        }
        if (IsMine(i + 1, j))
        {
            count++;
        }
        if (IsMine(i + 1, j + 1))
        {
            count++;
        }
        if (IsMine(i, j + 1))
        {
            count++;
        }
        if (IsMine(i - 1, j + 1))
        {
            count++;
        }
        if (count == 0)//不是炸弹
        {
            //消除地板砖
            GameBG.Children.Remove(img);
            //八个方向,判断界限不能超过界限
            if (i > 0)
            {
                //又递归一下,判断周围的地板,并改图片
                CountMine(i - 1, j, images[i - 1, j]);
            }
            if (j > 0)
            {
                CountMine(i, j - 1, images[i, j - 1]);
            }
            if (i > 0 && j > 0)
            {
                CountMine(i - 1, j - 1, images[i - 1, j - 1]);
            }
            if (i < mines.GetLength(0) - 1)
            {
                CountMine(i + 1, j, images[i + 1, j]);
            }
            if (j < mines.GetLength(1) - 1)
            {
                CountMine(i, j + 1, images[i, j + 1]);
            }
            if (i > 0 && j < mines.GetLength(1) - 1)
            {
                CountMine(i - 1, j + 1, images[i - 1, j + 1]);
            }
            if (i < mines.GetLength(0) - 1 && j < mines.GetLength(1) - 1)
            {
                CountMine(i + 1, j + 1, images[i + 1, j + 1]);
            }
            if (i < mines.GetLength(0) - 1 && j > 0)
            {
                CountMine(i + 1, j - 1, images[i + 1, j - 1]);
            }
        }
        else
        {
            GameBG.Children.Remove(img);
            Label lb = new Label();
            //文本的
            lb.Content = count.ToString();
            Grid.SetColumn(lb, j);
            Grid.SetRow(lb, i);
            lb.FontSize = 15;
            lb.HorizontalContentAlignment = HorizontalAlignment.Center;
            lb.VerticalContentAlignment = VerticalAlignment.Center;
            GameBG.Children.Add(lb);
        }
    }

    bool IsMine(int i,int j)//默认是false
    {
        //表示i、j不能为负数或0,i\j不能大于数组的限度,防止死循环和报错(限度会超出)
        if (i<0||j<0||i>=mines.GetLength(0)||j>=mines.GetLength(1))
        {
            return false;
        }
        else
        {
            //表示炸弹时返回正确的
            if (mines[i,j]==1)//mines[i,j]==1是正确的
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    private void MenuItem_Click(object sender, RoutedEventArgs e)
    {
        rows +=5 ;
        mineCount += 5;
        //先清除行和列
        GameBG.RowDefinitions.Clear();
        GameBG.ColumnDefinitions.Clear();
        //然后在清除整个页面的内容
        GameBG.Children.Clear();
        //调用网格数
        Ge();
        //调用图片
        InitialGame();
    }
}}

	//   using System;
	//using System.Collections.Generic;
	//using System.Linq;
	//using System.Text;
	//using System.Threading.Tasks;
	//using System.Windows;
	//using System.Windows.Controls;
	//using System.Windows.Data;
	//using System.Windows.Documents;
	//using System.Windows.Input;
	//using System.Windows.Media;
	//using System.Windows.Media.Imaging;
	//using System.Windows.Navigation;
	//using System.Windows.Shapes;
	
//namespace _2扫雷
//    {
//        /// <summary>
//        /// MainWindow.xaml 的交互逻辑
//        /// </summary>
//        public partial class MainWindow : Window
//        {
//            public MainWindow()
//            {
//                InitializeComponent();
//            }
//            //在外面定义一个变量,用来循环10次,原因是行循环10次,列循环10次
//            int rows = 10;
//            //随机数
//            Random r = new Random();
//            //这个二维数组分别放行和列
//            int[,] mines;
//            //放图片的数组
//            Image[,] images;
//            //在外面定义一个判断值 //当前位置默认为false
//            bool[,] overList;
//            //定义10个炸弹
//            int mineCount = 10;
//            private void Window_Loaded(object sender, RoutedEventArgs e)
//            {
//                for (int i = 0; i < rows; i++)
//                 {
//                     //把网格的行和列分成10*10的格子
//                     //创建行数
//                     RowDefinition row = new RowDefinition();
//                     GameBG.RowDefinitions.Add(row);
//                     //创建列数
//                     ColumnDefinition column = new ColumnDefinition();
//                     GameBG.ColumnDefinitions.Add(column);
//                 }
//                 //表示网格的线是否显示显示
//                 GameBG.ShowGridLines = true;

//                //创建一个方法,用这个方法显示每个格子的东西显示
//                InitialGame();
//            }
//            
//            private void InitialGame()
//            {
//                //把每个网格的行和列放在mines数组里
//                mines = new int[rows, rows];
//                //给每个图片添加网格
//                images = new Image[rows, rows];
//                //当前位置默认为全是false
//                overList = new bool[rows, rows];
//                //用1数字来记录10个炸弹
//                for (int i = 0; i < mineCount; i++)//循环10次炸弹
//                {
//                    //GetLength表示指定元素的索引
//                    //随机出网格0代表行,1来表列
//                    int row = r.Next(0, mines.GetLength(0));
//                    int colmun = r.Next(0, mines.GetLength(1));
//                    //表示当行和列,标记==1,这个的值==1
//                    //当记录数字等于等于1时候表示以及记录过了,所以i循环的时候i--回去,从新随机,else不等于记录的数组时就为1
//                    if (mines[row, colmun] == 1)
//                    {
//                        i--;
//                    }
//                    else
//                    {
//                        mines[row, colmun] = 1;
//                    }
//                }

//                //初始情况下所有的Image全部装zhuan
//                for (int i = 0; i < mines.GetLength(0); i++)//控制行
//                {
//                    for (int j = 0; j < mines.GetLength(1); j++)//控制列
//                    {
//                        //实例化一下图片
//                        images[i, j] = new Image();
//                        //然后给每个位置添加图片
//                        images[i, j].Source = new BitmapImage(new Uri("img/zhuan.gif", UriKind.Relative));
//                        //每个小格子的间距
//                        images[i, j].Margin = new Thickness(2, 2, 2, 2);
//                        //附加属性设置为指定的对象,把这个图片添加到指定的x,y的具体位置上
//                        Grid.SetRow(images[i, j], i);
//                        Grid.SetColumn(images[i, j], j);
//                        //给每个图片定义一个tag值,用一个数组定义,索引0,1
//                        //如果给成具体数字表示这张图片的tag值是什么数字代表
//                        images[i, j].Tag = new int[2] { i, j };
//                        //把每个图片添加到GameBG里面
//                        GameBG.Children.Add(images[i, j]);
//                        //鼠标的左键
//                        images[i, j].MouseLeftButtonDown += MainWindow_MouseLeftButtonDown;
//                        //鼠标的右键
//                        images[i, j].MouseRightButtonDown += MainWindow_MouseRightButtonDown;
//                    }
//                }
//            }
//            //鼠标右键,表示有雷放个旗子
//            private void MainWindow_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
//            {
//                //因为是局部变量,所以想要获取image具体的图片要用一个具体的事件触发者,谁创建的这个事件谁就是事件触发者
//                Image img = sender as Image;
//                //添加红旗图片
//                img.Source = new BitmapImage(new Uri("img/qizi.gif", UriKind.Relative));
//            }
//            //鼠标左键
//            private void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
//            {
//                //因为是局部变量,所以想要获取image具体的图片要用一个具体的事件触发者,谁创建的这个事件谁就是事件触发者
//                Image img = sender as Image;
//                //获取图片的tag值,类型是数组
//                int[] index = img.Tag as int[];
//                //点击的这个是一个安全地区
//                //首先在执行这里时,在外面定义一个bool,用形参来判断满足的条件IsMine
//                //IsMine(index[0],index[1]);
//                if (!IsMine(index[0], index[1]))//true//返回不正确时进入//判断雷数
//                {
//                    //要判断周围的地雷数,基本上所有的雷周围至少有3个,最多有8个相邻
//                    //假设当前这个是i,j,则需要考虑周围的(i-1,j),(i-1,j-1),(i,j-1),(i+1,j-1),(i+1,j),(i+1,j+1),(i,j+1),(i-1,j+1)
//                    //int count = CountMine(index[0], index[1]);\
//                    //调用x,y具体图片的位置tagzhi
//                    CountMine(index[0], index[1], img);//放雷数
//                                                       //判断剩下格子数量
//                    int left = 0;
//                    for (int i = 0; i < overList.GetLength(0); i++)
//                    {
//                        for (int j = 0; j < overList.GetLength(1); j++)
//                        {
//                            if (overList[i, j] == false)
//                            {
//                                left++;
//                            }
//                        }
//                    }
//                    if (left == mineCount)
//                    {
//                        MessageBox.Show("获胜");
//                    }
//                }
//                else
//                {
//                    for (int i = 0; i < mines.GetLength(0); i++)
//                    {
//                        for (int j = 0; j < mines.GetLength(1); j++)
//                        {
//                            if (mines[i, j] == 1)
//                            {
//                                images[i, j].Source = new BitmapImage(new Uri("img/lei.gif", UriKind.Relative));
//                            }
//                        }
//                    }
//                    MessageBox.Show("失败!");
//                  
//                }
//            }

//            void CountMine(int i, int j, Image img)
//            {
//                //判断死循环,判断当前位置被判断过了,在外面定义一个overList
//                //因为外面默认值是false,所以if判断进来为true,然后return,下面的都不会执行
//                /*1.先点击MainWindow_MouseLeftButtonDown
//                 * 2.判断雷数
//                 * 3. CountMine(index[0], index[1], img);进来overList[i,j]==false,不进入if(overList[i,j]==true)
//                 * 4.直接改变默认值false为overList[i, j] = true;
//                 * 5.第二次点击重复1、2、进入CountMine在判断,这个时候就可以进入overList[i,j]==true,return后面的就不会再执行了
//                 */
//                if (overList[i, j] == true)
//                {
//                    return;
//                }
//                //点击后改为true
//                overList[i, j] = true;

//                //用一个数字记录周围的雷数,如果还是0的话翻其他周围的牌子
//                int count = 0;
//                if (IsMine(i - 1, j))//为
//                {
//                    //如果满足条件count++;加成1
//                    count++;
//                }
//                if (IsMine(i - 1, j - 1))
//                {
//                    count++;
//                }
//                if (IsMine(i, j - 1))
//                {
//                    count++;
//                }
//                if (IsMine(i + 1, j - 1))
//                {
//                    count++;
//                }
//                if (IsMine(i + 1, j))
//                {
//                    count++;
//                }
//                if (IsMine(i + 1, j + 1))
//                {
//                    count++;
//                }
//                if (IsMine(i, j + 1))
//                {
//                    count++;
//                }
//                if (IsMine(i - 1, j + 1))
//                {
//                    count++;
//                }
//                if (count == 0)//不是炸弹
//                {
//                    //消除地板砖
//                    GameBG.Children.Remove(img);
//                    //八个方向,判断界限不能超过界限
//                    if (i > 0)
//                    {
//                        //又递归一下,判断周围的地板,并改图片
//                        CountMine(i - 1, j, images[i - 1, j]);
//                    }
//                    if (j > 0)
//                    {
//                        CountMine(i, j - 1, images[i, j - 1]);
//                    }
//                    if (i > 0 && j > 0)
//                    {
//                        CountMine(i - 1, j - 1, images[i - 1, j - 1]);
//                    }
//                    if (i < mines.GetLength(0) - 1)
//                    {
//                        CountMine(i + 1, j, images[i + 1, j]);
//                    }
//                    if (j < mines.GetLength(1) - 1)
//                    {
//                        CountMine(i, j + 1, images[i, j + 1]);
//                    }
//                    if (i > 0 && j < mines.GetLength(1) - 1)
//                    {
//                        CountMine(i - 1, j + 1, images[i - 1, j + 1]);
//                    }
//                    if (i < mines.GetLength(0) - 1 && j < mines.GetLength(1) - 1)
//                    {
//                        CountMine(i + 1, j + 1, images[i + 1, j + 1]);
//                    }
//                    if (i < mines.GetLength(0) - 1 && j > 0)
//                    {
//                        CountMine(i + 1, j - 1, images[i + 1, j - 1]);
//                    }
//                }
//                else
//                {
//                    GameBG.Children.Remove(img);
//                    Label lb = new Label();
//                    //文本的
//                    lb.Content = count.ToString();
//                    Grid.SetColumn(lb, j);
//                    Grid.SetRow(lb, i);
//                    lb.FontSize = 15;
//                    lb.HorizontalContentAlignment = HorizontalAlignment.Center;
//                    lb.VerticalContentAlignment = VerticalAlignment.Center;
//                    GameBG.Children.Add(lb);
//                }
//            }

//            bool IsMine(int i, int j)//默认是false
//            {
//                //表示i、j不能为负数或0,i\j不能大于数组的限度,防止死循环和报错(限度会超出)
//                if (i < 0 || j < 0 || i >= mines.GetLength(0) || j >= mines.GetLength(1))
//                {
//                    return false;
//                }
//                else
//                {
//                    //表示炸弹时返回正确的
//                    if (mines[i, j] == 1)//mines[i,j]==1是正确的
//                    {
//                        return true;
//                    }
//                    else
//                    {
//                        return false;
//                    }
//                }
//            }

//        }

//    }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: WPF是一种基于XAML语言的用户界面开发框架,使开发人员能够轻松创建漂亮和高效的桌面应用程序。MVVM是一种模式,它在WPF应用程序中广泛使用,它提供了一种分离UI和业务逻辑的方式,从而简化了代码结构。Prism是一个开源框架,它基于MVVM模式和WPF框架,提供了一些技术和工具,使开发人员能够更轻松地构建复杂的WPF应用程序。 使用WPF MVVM Prism框架可以帮助开发人员提高应用程序的可维护性和可扩展性。通过MVVM,开发人员可以创建一个适应各种应用程序场景的模型,并将其与UI分离。数据绑定和命令绑定使开发人员能够更轻松地将模型中的数据和逻辑与UI控件集成起来。Prism框架还提供了一些工具和功能,如模块化应用程序开发、事件聚合器、导航、对话框、异常处理等功能。这些工具使开发人员能够更轻松地构建复杂的应用程序,并提供了一种可扩展和可重用的方法。 总之,使用WPF MVVM Prism可以使开发人员更轻松地构建复杂的应用程序,并提高应用程序的可维护性和可扩展性。开发人员可以根据自己的需求选择使用这个框架来开发WPF应用程序,从而提高他们的工作效率和代码质量。 ### 回答2: WPF MVVM Prism是一种基于Windows Presentation Foundation(WPF)的软件开发模式,采用了MVVM(Model-View-ViewModel)设计模式和Prism框架来实现软件开发。MVVM是一种在WPF应用程序中使用的设计模式,它将应用程序的视图(View)与应用程序的模型(Model)分离开来,通过ViewModel来连接二者。Prism是一个帮助开发人员编写出复杂、可管控、可扩展和可维护的WPF应用程序的框架。 WPF MVVM Prism提供了很多好处:首先,它能实现软件的可重用性,通过将代码和视图分离,使得代码可以在多个不同的视图中重复使用,提高了开发效率。其次,它可以提高软件的可维护性,通过将逻辑和视图分离,确保逻辑代码与UI代码之间更少的耦合,提高了软件的可扩展性。此外,它还可以提高软件的可测试性,由于MVVM模式中将视图和逻辑分离开,所以开发人员可以更容易地编写出单元测试代码,来测试逻辑代码。最后,由于Prism框架提供了一些通用的,可定制的模块和服务,使得开发人员可以更快地实现常见功能、缩短开发时间。 总之,WPF MVVM Prism是一种高效、可扩展和易于维护的软件开发模式,它将视图和逻辑分离,提高了软件的可重用性和可测试性,同时也提高了软件的可扩展性和可复用性。 ### 回答3: WPF是一种桌面应用程序框架,它允许您为Windows创建高度交互式和可视化的应用程序界面。MVVM是一种软件编程模式,它将用户界面(UI)与业务逻辑分离,以便更好地实现可维护,可扩展和可组合的代码。Prism是一个WPF和Silverlight应用程序的组件库,它提供了一些可重用和可扩展的基础设施组件,帮助您更快速地构建、测试和维护WPF应用程序。因此,WPF MVVM Prism的组合可以帮助您更轻松高效地开发WPF应用程序。您可以使用MVVM模式来改进应用程序的结构和测试,使用Prism来更好地组织和可扩展您的代码,以及使用WPF来实现交互丰富的UI。同时还可以使用Prism提供的事件聚合器、导航器和模块化架构,实现更灵活的应用程序设计。WPF MVVM Prism的组合提供了一种更有效的方式来构建WPF应用程序,以满足现代用户体验的需求,并且更容易测试和维护,因此它已成为WPF应用程序开发的重要组合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值