基本信息
源码名称:wpf窗口游戏开发---5个项目(贪吃蛇、扫雷、打字游戏)
源码大小:18.64M
文件格式:.zip
开发语言:C#
更新时间:2020-01-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 8 元 
   源码介绍

使用wpf窗口开发的贪吃蛇、扫雷、打字游戏以及gdi简易动画项目








void CountMine(int i,int j,Image img)
        {
            
            //判断当前位置是否判断过,如果判断过则跳出---作用防止反复判断自己造成死循环
            if (bomOrgo[i,j]==true)
            {
                return;
            }
            //将当前位置设置为true
            bomOrgo[i,j] = true;
            //创建一个变量来接收地雷数
            int count = 0;
            //判断当前位置四周的八个方向是否为雷,如果是则count  
            if (IsBoom(i - 1, j - 1))
            {
                count  ;
            }
            if (IsBoom(i-1,j))
            {
                count  ;
            }
            if (IsBoom(i - 1, j 1))
            {
                count  ;
            }
            if (IsBoom(i, j-1))
            {
                count  ;
            }
            if (IsBoom(i , j 1))
            {
                count  ;
            }
            if (IsBoom(i  1, j-1))
            {
                count  ;
            }
            if (IsBoom(i   1, j))
            {
                count  ;
            }
            if (IsBoom(i   1, j 1))
            {
                count  ;
            }
            //递归思想:判断如果当前位置的8个方向都没有雷,则再以八个方向为中心重复调用自己这个方法往外判断
            if (count==0)
            {
                GameBG.Children.Remove(img);
                //外部if保证数组不超出索引
                if (i>0)
                {
                    CountMine(i - 1, j,images[i-1,j]);
                    if (j>0)
                    {
                        CountMine(i-1,j-1, images[i - 1, j-1]);
                    }
                }
                if (i<maps.GetLength(0)-1)
                {
                    CountMine(i   1, j,images[i   1, j]);
                }
                if (i>0&&j<maps.GetLength(1)-1)
                {
                    CountMine(i - 1, j   1, images[i - 1, j 1]);
                }
                if (j<maps.GetLength(1)-1)
                {
                    CountMine(i , j 1, images[i, j 1]);
                }
                if (j>0)
                {
                    CountMine(i, j - 1, images[i , j-1]);
                }
                if (i < maps.GetLength(1)-1&&j>0)
                {
                    CountMine(i   1, j - 1, images[i   1, j-1]);
                }
                if (i < maps.GetLength(0)-1&& j < maps.GetLength(1)-1)
                {
                    CountMine(i   1, j 1, images[i   1, j 1]);
                }
            }
            else
            {
                //移除该处图片
                GameBG.Children.Remove(img);
                //实例化label
                Label lb = new Label();
                lb.Content = count.ToString();
                //将label设置网格的相应位置处
                Grid.SetRow(lb, i);
                Grid.SetColumn(lb, j);
                lb.FontSize = 24;
                //设置label水平居中
                lb.HorizontalContentAlignment = HorizontalAlignment.Center;
                //设置label竖直居中
                lb.VerticalContentAlignment = VerticalAlignment.Center;
                GameBG.Children.Add(lb);
            }
        }