private string ChooseMiscTile(TileForGeneration tile)
    {
        int    rand = 0;
        string path = null;

        switch (tile.style)
        {
        case 0:
            rand = Random.Range(0, desertObject.Length);
            path = "Tile/desertLand/" + desertObject[rand].name;
            break;

        case 1:
            rand = Random.Range(0, greenObject.Length);
            path = "Tile/greenLand/" + greenObject[rand].name;
            break;

        case 2:
            rand = Random.Range(0, evilObject.Length);
            path = "Tile/evilLand/" + evilObject[rand].name;
            break;

        case 3:
            rand = Random.Range(0, snowObject.Length);
            path = "Tile/snowLand/" + snowObject[rand].name;
            break;
        }
        return(path);
    }
    public string ChooseTile(TileForGeneration tile)
    {
        string path = null;

        switch (tile.stratElt)
        {
        case MapGenerator.strategic.castle:
            path = ChooseCastle(tile);
            break;

        case MapGenerator.strategic.nothing:
            path = ChooseMiscTile(tile);
            break;
        }
        return(path);
    }
Exemple #3
0
    //calcul le germe le plus proche de la position de la tile
    public int belongsZone(TileForGeneration tile)
    {
        float distanceMin = 1000;
        int   zone        = 1000;

        for (int i = 0; i < germs.Length; i++)
        {
            float distance = Vector3.Distance(germs[i].position, tile.position);
            //Debug.Log(tile.name+" "+tile.position + "to germ "+ i +" "+germs[i].position+" = " + distance + "compar" + distanceMin);
            if (distance < distanceMin)
            {
                distanceMin = distance;
                zone        = germs[i].style;
            }
        }
        return(zone);
    }
    private string ChooseCastle(TileForGeneration tile)
    {
        string castle = "";

        switch (tile.style)
        {
        case 0:
            castle = "desertCastle";
            break;

        case 1:
            castle = "greenCastle";
            break;

        case 2:
            castle = "hellCastle";
            break;

        case 3:
            castle = "snowCastle";
            break;
        }
        return(CastleLoader(castle));
    }
Exemple #5
0
    public void CreateMap()
    {
        float mapSize = GameObject.Find("MapSize").GetComponent <Slider>().value;

        mapWidth = Mathf.RoundToInt(mapSize);
        if (mapWidth % 2 == 0)
        {
            mapWidth = mapWidth + 1;
        }
        castleNumber = numberOfGerm();
        tileLoader   = new TileLoader();
        tileLoader.ConstructTileTab();

        int heightColumn = 3;

        mapColumnSize.Add(heightColumn);
        float positionX = -((mapWidth - 1) / 2);
        float positionZ = -1;

        //Initialisation de la map
        map = new List <TileForGeneration[]>();
        for (int width = 0; width < mapWidth; width++)
        {
            map.Add(new TileForGeneration[heightColumn]);
            if (width <= mapWidth / 2)
            {
                heightColumn += 1;
                mapColumnSize.Add(heightColumn);
            }
            else
            {
                heightColumn -= 1;
                mapColumnSize.Add(heightColumn);
            }
        }
        heightColumn = 3;

        for (int width = 0; width < mapWidth; width++)
        {
            for (int height = 0; height < heightColumn; height++)
            {
                Vector3 position = new Vector3(positionX, 0, positionZ + height);
                map[width][height]                = new TileForGeneration();
                map[width][height].position       = position;
                map[width][height].name           = "Tile" + width + height;
                map[width][height].stratElt       = strategic.nothing;
                map[width][height].neighbors      = new List <TileForGeneration>();
                map[width][height].neighborsNames = new List <string>();
                map[width][height].gameObject     = null;
            }
            positionX += 0.86f;
            if (positionX <= 0)
            {
                positionZ    -= 0.5f;
                heightColumn += 1;
            }
            else
            {
                positionZ    += 0.5f;
                heightColumn -= 1;
            }
        }


        placeGerm();
        placeCastle();
        placeResources();
        Map.instance.InitializeMap(mapWidth);
        //Construction de la map
        positionX    = -((mapWidth - 1) / 2);
        positionZ    = -1;
        heightColumn = 3;
        for (int width = 0; width < mapWidth; width++)
        {
            for (int height = 0; height < heightColumn; height++)
            {
                map[width][height].style = belongsZone(map[width][height]);
                string path = tileLoader.ChooseTile(map[width][height]);

                string controller;
                //Tile attribution to players
                if ((width == 0 && height == 0) || (width == 0 && height == 1))
                {
                    controller = "redPlayer";
                }
                else if ((width == mapWidth - 1 && height == 0) || (width == mapWidth - 1 && height == 1))
                {
                    controller = "bluePlayer";
                }
                else
                {
                    controller = "neutral";
                }

                DetermineNeighbors(map[width][height], width, height, heightColumn);

                //Préparation des datas pour initialisation des Tiles chez le client
                int      sizeNeighborsList = map[width][height].neighbors.Count;
                string[] neighborsName     = new string[sizeNeighborsList];
                for (int i = 0; i < sizeNeighborsList; i++)
                {
                    neighborsName[i] = map[width][height].neighbors[i].name;
                }

                object[] tileInitDataForClient = new object[7 + neighborsName.Length];
                tileInitDataForClient[0] = map[width][height].style;
                tileInitDataForClient[1] = map[width][height].name;
                tileInitDataForClient[2] = map[width][height].stratElt.ToString();
                tileInitDataForClient[3] = controller;
                tileInitDataForClient[4] = map[width][height].foodIncome;
                tileInitDataForClient[5] = map[width][height].goldIncome;
                tileInitDataForClient[6] = map[width][height].strategicIncome;

                for (int i = 7; i < 7 + neighborsName.Length; i++)
                {
                    tileInitDataForClient[i] = neighborsName[i - 7];
                }

                map[width][height].gameObject = PhotonNetwork.InstantiateSceneObject(path, map[width][height].position, Quaternion.Euler(0, -30, 0), 0, tileInitDataForClient);

                map[width][height].gameObject.transform.parent     = mapGroup.transform;
                map[width][height].gameObject.transform.localScale = new Vector3(1, 1, 1);
                map[width][height].gameObject.name = map[width][height].name;

                //Initialisation tiles coté serveur
                Tile tileScript = map[width][height].gameObject.GetComponent <Tile>();
                tileScript.neighboursName = new List <string>();
                foreach (string tilename in neighborsName)
                {
                    tileScript.neighboursName.Add(tilename);
                }
                tileScript.InitializeTile(map[width][height].style, map[width][height].stratElt, map[width][height].foodIncome,
                                          map[width][height].goldIncome, map[width][height].strategicIncome);
                Map.instance.tileList.Add(tileScript);
            }

            positionX += 0.86f;
            if (positionX <= 0)
            {
                heightColumn += 1;
            }
            else
            {
                heightColumn -= 1;
            }
        }

        Map.instance.InitializeTargetingSphere();

        foreach (Tile tile in Map.instance.tileList)
        {
            tile.CreateNeighboursList();
        }
    }
Exemple #6
0
    public void DetermineNeighbors(TileForGeneration tile, int xTile, int yTile, int heighColumn)
    {
        int rightColumnHeigh, leftColumnHeigh;
        int partOfMap = -1; //0=left, 1=middle, 2=right

        if (xTile < (mapWidth - 1) / 2)
        {
            partOfMap        = 0;
            rightColumnHeigh = heighColumn + 1;
            if (xTile > 0)
            {
                leftColumnHeigh = heighColumn - 1;
            }
            else
            {
                leftColumnHeigh = -1;
            }
        }
        else if (xTile > (mapWidth - 1) / 2)
        {
            partOfMap       = 2;
            leftColumnHeigh = heighColumn + 1;
            if (xTile < mapWidth - 1)
            {
                rightColumnHeigh = heighColumn - 1;
            }
            else
            {
                rightColumnHeigh = -1;
            }
        }
        else
        {
            partOfMap        = 1;
            leftColumnHeigh  = heighColumn - 1;
            rightColumnHeigh = heighColumn - 1;
        }

        int x = xTile - 1;
        int yMin, yMax;

        if (x >= 0)
        {
            if (partOfMap == 0 || partOfMap == 1)
            {
                yMin = yTile - 1;
                yMax = yTile;
            }
            else
            {
                yMin = yTile;
                yMax = yTile + 1;
            }

            if (yMax <= leftColumnHeigh - 1)
            {
                tile.neighbors.Add(map[x][yMax]);
                tile.neighborsNames.Add(map[x][yMax].name);
            }
            if (yMin >= 0)
            {
                tile.neighbors.Add(map[x][yMin]);
                tile.neighborsNames.Add(map[x][yMin].name);
            }
        }

        x = xTile;
        if (yTile + 1 <= heighColumn - 1)
        {
            tile.neighbors.Add(map[x][yTile + 1]);
            tile.neighborsNames.Add(map[x][yTile + 1].name);
        }

        if (yTile - 1 >= 0)
        {
            tile.neighbors.Add(map[x][yTile - 1]);
            tile.neighborsNames.Add(map[x][yTile - 1].name);
        }

        x = xTile + 1;
        if (x <= mapWidth - 1)
        {
            if (partOfMap == 2 || partOfMap == 1)
            {
                yMin = yTile - 1;
                yMax = yTile;
            }
            else
            {
                yMin = yTile;
                yMax = yTile + 1;
            }
            if (yMax <= rightColumnHeigh - 1)
            {
                tile.neighbors.Add(map[x][yMax]);
                tile.neighborsNames.Add(map[x][yMax].name);
            }

            if (yMin >= 0)
            {
                tile.neighbors.Add(map[x][yMin]);
                tile.neighborsNames.Add(map[x][yMin].name);
            }
        }
    }