コード例 #1
0
    public void SetTilemapType(Vector3 worldPosition, MapGridObject.Type tilemapType)
    {
        MapGridObject mapGridObject = grid.GetGridObject(worldPosition);

        if (mapGridObject != null)
        {
            mapGridObject.SetGridType(tilemapType);
        }
    }
コード例 #2
0
    public Map()
    {
        grid = new Grid <MapGridObject>(10, 10, 1f, Vector3.zero, (Grid <MapGridObject> g, int x, int y) => new MapGridObject(g, x, y));

        int minesPlaced        = 0;
        int generateMineAmount = 10;

        while (minesPlaced < generateMineAmount)
        {
            int x = Random.Range(0, grid.GetWidth());
            int y = Random.Range(0, grid.GetHeight());

            MapGridObject mapGridObject = grid.GetGridObject(x, y);

            if (mapGridObject.GetGridType() != MapGridObject.Type.Mine)
            {
                mapGridObject.SetGridType(MapGridObject.Type.Mine);
                minesPlaced++;
            }
        }

        for (int x = 0; x < grid.GetWidth(); x++)
        {
            for (int y = 0; y < grid.GetHeight(); y++)
            {
                MapGridObject mapGridObject = grid.GetGridObject(x, y);
                if (mapGridObject.GetGridType() == MapGridObject.Type.Empty)
                {
                    //tinh gtri o ke ben bom
                    List <MapGridObject> neighbourList = GetNeighbourList(x, y);

                    int mineCount = 0;
                    foreach (MapGridObject neighbour in neighbourList)
                    {
                        if (neighbour.GetGridType() == MapGridObject.Type.Mine)
                        {
                            mineCount++;
                        }
                    }
                    switch (mineCount)
                    {
                    case 1: mapGridObject.SetGridType(MapGridObject.Type.MineNum_1); break;

                    case 2: mapGridObject.SetGridType(MapGridObject.Type.MineNum_2); break;

                    case 3: mapGridObject.SetGridType(MapGridObject.Type.MineNum_3); break;

                    case 4: mapGridObject.SetGridType(MapGridObject.Type.MineNum_4); break;

                    case 5: mapGridObject.SetGridType(MapGridObject.Type.MineNum_5); break;

                    case 6: mapGridObject.SetGridType(MapGridObject.Type.MineNum_6); break;

                    case 7: mapGridObject.SetGridType(MapGridObject.Type.MineNum_7); break;

                    case 8: mapGridObject.SetGridType(MapGridObject.Type.MineNum_8); break;
                    }
                }
            }
        }
    }