Example #1
0
 private void CreateCraters()
 {
     foreach (Player player in manager.players)
     {
         Player.Coordinate coordinates = player.coordinates;
         Tile baseTile = grid[coordinates.x, coordinates.y];
         Tile crater;
         do
         {
             crater = baseTile.adjacencyList[UnityEngine.Random.Range(0, baseTile.adjacencyList.Count)];
         } while (crater.terrainType == TerrainTypes.CRATER);
         crater.tileState   = TileState.UNAVAILABLE;
         crater.terrainType = TerrainTypes.CRATER;
         crater.tileOwner   = PlayerNumber.NONE;
         crater.gameObject.GetComponent <MeshRenderer>().material.SetColor("PlayerColour", Color.black);
         crater.ChangeTile();
     }
 }
Example #2
0
    public void CreateHexTileMap()
    {
        delta = 1;
        int counter = 0;

        for (int z = 0; z < maxHeight; z++)
        {
            if (currentHeight <= maxHeight && z <= maxHeight / 2)
            {
                currentHeight++;
            }
            else if (currentHeight > minHeight && z >= maxHeight / 2)
            {
                currentHeight--;
            }
            if ((z + 1) % 2 == 0 && z <= maxHeight / 2)
            {
                counter++;
            }
            //Debug.Log(xOffset * counter);
            for (int x = 0; x < currentHeight; x++)
            {
                //grid[z, x] = new Tile(defaultTilePrefab);
                grid[z, x]           = Instantiate(defaultTilePrefab).AddComponent <Tile>().SetTile(this, defaultTilePrefab);
                grid[z, x].tileState = TileState.UNCLAIMED;
                grid[z, x].name      = $"{x},{z}";
                if (z % 2 == 0)
                {
                    grid[z, x].transform.position = new Vector3((x * xOffset) - xOffset * counter, 0, z * zOffset);
                }
                else
                {
                    grid[z, x].transform.position = new Vector3((x * xOffset + (xOffset / 2)) - xOffset * counter, 0, z * zOffset);
                }
                grid[z, x].gameObject.GetComponent <MeshRenderer>().material.SetColor("PlayerColour", Color.gray);
            }
            for (int x = currentHeight; x < maxHeight; x++)
            {
                grid[z, x]             = Instantiate(emptyGO).AddComponent <Tile>().SetTile(TileState.UNAVAILABLE);
                grid[z, x].tileOwner   = PlayerNumber.NONE;
                grid[z, x].terrainType = TerrainTypes.CRATER;
                grid[z, x].name        = $"Unreachable-{x},{z}";
            }
            if ((z + 1) % 2 == 0 && z >= maxHeight / 2)
            {
                counter--;
            }
        }
        foreach (Player player in manager.players)
        {
            Player.Coordinate coordinates = player.coordinates;
            Tile baseTile = grid[coordinates.x, coordinates.y];
            player.ownedTiles.Add(baseTile);
            Debug.Log(player.playerID);
            baseTile.tileState   = TileState.UNAVAILABLE;
            baseTile.tileOwner   = player.playerID;
            baseTile.terrainType = TerrainTypes.BASE;
            baseTile.ChangeTile();
            baseTile.gameObject.GetComponent <MeshRenderer>().material.SetColor("PlayerColour", player.playerColour);
        }
        for (int i = 0; i < numberOfFertiles; i++)
        {
            Tile fertile = grid[maxHeight / 2, maxHeight / 2];
            fertile.terrainType = TerrainTypes.FERTILE;
            fertile.tileOwner   = PlayerNumber.NONE;
            fertile.gameObject.GetComponent <MeshRenderer>().material.SetColor("PlayerColour", Color.green);
            fertile.ChangeTile();
        }
    }