Exemplo n.º 1
0
    void Start()
    {
        GameTile[] gameTileHolder = GetComponentsInChildren <GameTile> ();
        for (int i = 0; i < gameTileHolder.Length; i++)
        {
            gameTiles.Add(gameTileHolder [i]);
            gameTileHolder [i].Initialize();
        }

        //Time to randomize and make some impassable tiles
        int     numImpassableTiles = Mathf.RoundToInt(Random.Range(minMaxImpassableTiles.x, minMaxImpassableTiles.y));
        Vector3 checkCoordinates   = Vector3.zero;

        for (int i = 0; i < numImpassableTiles; i++)
        {
            GameTile foundTile = GetTileFromPos(GetRandomPositionOnBoard());
            if (foundTile != null)
            {
                if (!foundTile.CheckSides())
                {
                    i -= 1;
                    continue;
                }
                else
                {
                    foundTile.SetImpassible();
                }
            }
            else
            {
                Debug.Log("We didnt find anything " + checkCoordinates);
            }
        }

        for (int i = 0; i < numTransmitterPos; i++)
        {
            GameTile foundTile = GetTileFromPos(GetRandomPositionOnBoard());
            if (foundTile.type == GameTile.TileType.Transmitter || foundTile.type == GameTile.TileType.Impassible)
            {
                i -= 1;
                continue;
            }
            if (!foundTile.CheckTransmitterPlacement(minSpaceBetweenTransmitters))
            {
                i -= 1;
                continue;
            }
            else
            {
                foundTile.SetTransmitter();
                transmitterPoints.Add(foundTile);
            }
        }

        for (int i = 0; i < 4; i++)
        {
            GameTile foundTile = GetTileFromPos(GetRandomPositionOnBoard());
            if (foundTile.type != GameTile.TileType.Passable)
            {
                i -= 1;
                continue;
            }
            if (!foundTile.CheckSpawnPlacement(minSpaceBetweenSpawnpointsAndTransmitters, minSpaceBetweenSpawnpoints))
            {
                i -= 1;
                continue;
            }
            else
            {
                foundTile.SetSpawnTile();
                spawnPoints.Add(foundTile);
            }
        }
        initialized = true;
    }