unity-扫雷

效果图
扫雷资源
没事自己简单做了一个扫雷,主要的点有两个,一个是地雷的随机放置;一个是八向查找地雷数;
随机地雷逻辑:

    public int GenerateRandomNumber(int min, int max)
    {
        RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();
        byte[] randomNumber = new byte[4]; // 生成4字节的随机数,即32位整数
        random.GetBytes(randomNumber);
        int value = BitConverter.ToInt32(randomNumber, 0);

        // 将生成的随机数限制在指定的范围内
        return Math.Abs(value % (max - min + 1)) + min;
    }

八向查找逻辑:

    public void GetLandmineCount(int raw, int col)
    {
        HashSet<int> totalList = new HashSet<int>();
        FindEmptyAndFlag(raw, col, totalList);
    }

    private void FindEmptyAndFlag(int raw, int col, HashSet<int> totalList)
    {
        HashSet<int> tempList = new HashSet<int>();
        int index;
        int count = 0;
        for (int i = raw - 1; i <= raw + 1; i++)
        {
            for (int j = col - 1; j <= col + 1; j++)
            {
                if (i == raw && j == col) continue;

                if (IsAllow(i, j))
                {
                    index = i * this.col + j;
                    if (itemList[index].status != ClearanceItem.ItemStatus.landmine &&
                        itemList[index].curStatus == ClearanceItem.ItemStatus.normal &&
                        !(i == raw-1 && j == col-1 || i == raw-1 && j == col+1 ||
                        i== raw+1 && j == col-1 || i == raw+1 && j == col+1) &&
                        !totalList.Contains(index))
                    {
                        try
                        {
                            tempList.Add(index);
                            totalList.Add(index);
                        }
                        catch (Exception)
                        {
                            Debug.LogError("i = " + i + " j = " + j);
                            throw;
                        }
                    }
                    if (itemList[index].status == ClearanceItem.ItemStatus.landmine)
                    {
                        count++;
                    }
                }
            }
        }

        if(tempList.Count > 0)
        {
            foreach (var item in tempList)
            {
                int tempRaw = item / this.col;
                int tempCol = item % this.col;
                FindEmptyAndFlag(tempRaw, tempCol, totalList, setList);
            }
        }
        index = raw * this.col + col;
        totalList.Add(index);
        itemList[index].SetCurStutas(count);
    }
Vue-Unity-WebGL 是一个具有极高可扩展性和灵活性的 Unity3D web 端开发框架,它将 Vue.js 与 Unity Web Player 和 WebGL 等技术相结合,为开发者提供了最佳的解决方案。 Vue-Unity-WebGL 框架具有很高的兼容性和易用性,开发者可以更加灵活地应用该框架来定制自己的项目。由于该框架具备了许多优秀的特性,如自适应布局、多平台支持等,使得开发者可以轻松地实现用户体验和开发效率的提升。此外,Vue-Unity-WebGL 框架不仅提供了可视化开发工具,还提供了完整的运行环境,为开发者提供了优秀的开发体验。 Vue-Unity-WebGL 框架的另一个重要特点是其大量的插件与扩展功能,这些插件和扩展可以为项目的开发和管理提供坚强的技术支持。比如,通过 vue-router 可以控制路由,Vue-Unity-WebGL 可以协作处理组件数据和 Unity3D 渲染等复杂的操作,而 Vuex 则可以使开发者方便地处理应用数据流和组件状态的管理。这些插件和扩展功能极大地提高了 Vue-Unity-WebGL 框架的可扩展性和灵活性,使得开发者可以更加容易地进行定制。 综上所述,Vue-Unity-WebGL 框架是一个快速、可靠且强大的解决方案,这使得开发者能够轻松地编写出高质量的 Unity3D web 应用程序。该框架具有大量的功能,实现可扩展性、灵活性、易用性和可维护性,比其他框架更具有竞争力。在未来的发展中,Vue-Unity-WebGL 框架将会被更多的开发者喜爱和应用,并在技术社区中拥有更广泛的影响力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值