Ejemplo n.º 1
0
 public Hex GetDirection(int dir)
 {
     return(AxialHex.GetDirection(dir));
 }
Ejemplo n.º 2
0
 public override int RoundToDir(int dir)
 {
     return(AxialHex.RoundToDir(dir));
 }
Ejemplo n.º 3
0
 public float GetHeuristic(Hex goal)
 {
     return(AxialHex.GetHeuristic(this, goal));
 }
Ejemplo n.º 4
0
 public float GetCost(int dir)
 {
     return(AxialHex.GetCost(dir));
 }
Ejemplo n.º 5
0
 public Hex[] GetDirections()
 {
     return(AxialHex.GetDirections());
 }
Ejemplo n.º 6
0
    public void CreateHexBoard(int radius)
    {
        if (radius <= 0)
        {
            return;
        }

        int prevRadius = 0;         //hexBoard == null _WHEN_ prevRadius <= 0

        if (tileBoard != null)
        {
            prevRadius = (tileBoard.GetLength(0) - 1) / 2 + 1;
        }

        if (radius < prevRadius)
        {
            for (int i = 0; i < prevRadius; i++)
            {
                Hex nextHex = AxialHex.GetDirection(4) * i;
                for (int dir = 0; dir < 6; dir++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (i >= radius)
                        {
                            //Destroy
                            if (debugMode)
                            {
                                Debug.Log(nextHex.ToArrayPos(prevRadius).x + "," + nextHex.ToArrayPos(prevRadius).y + " is destroyed");
                            }
                            Destroy(tileBoard[nextHex.ToArrayPos(prevRadius).y, nextHex.ToArrayPos(prevRadius).x].gameObject);

                            nextHex = nextHex.GetNeighbour(dir);
                        }
                    }
                }
            }
        }

        HexScript[,] newHexBoard = new HexScript[(radius - 1) * 2 + 1, (radius - 1) * 2 + 1];

        //Center piece
        if (0 < prevRadius)
        {
            //Migrate
            newHexBoard[0, 0] = (HexScript)tileBoard[0, 0];
            if (debugMode)
            {
                Debug.Log("hexBoard[0,0] can be taken from old array[0,0]");
            }
        }
        else
        {
            //Instantiate
            newHexBoard[0, 0] = Instantiate(tilePrefab[(int)tileType]).GetComponent <HexScript>();
            newHexBoard[0, 0].transform.parent = hexBoardParent;
            if (debugMode)
            {
                Debug.Log("hexBoard[0,0] is instantiated");
            }
        }

        //Set Scale
        newHexBoard[0, 0].transform.localScale = Vector3.one * tileSize;
        newHexBoard[0, 0].position             = new Hex(0, 0);

        newHexBoard[0, 0].isChecked    = false;
        newHexBoard[0, 0].isObstacle   = false;
        newHexBoard[0, 0].movementCost = Mathf.Infinity;
        newHexBoard[0, 0].parentTile   = null;
        newHexBoard[0, 0].state        = TileState.Empty;

        //Ring search
        for (int i = 1; i < radius; i++)
        {
            Hex nextHex = AxialHex.GetDirection(4) * i;
            for (int dir = 0; dir < 6; dir++)
            {
                for (int j = 0; j < i; j++)
                {
                    Hex arrayPos    = nextHex.ToArrayPos(radius);
                    Hex oldArrayPos = nextHex.ToArrayPos(prevRadius);

                    if (i < prevRadius)
                    {
                        //Migrate
                        newHexBoard[arrayPos.y, arrayPos.x] = (HexScript)tileBoard[oldArrayPos.y, oldArrayPos.x];
                        if (debugMode)
                        {
                            Debug.Log("hexBoard[" + arrayPos.y + "," + arrayPos.x + "] can be taken from old array[" + oldArrayPos.y + "," + oldArrayPos.x + "]");
                        }
                    }
                    else
                    {
                        //Instantiate
                        newHexBoard[arrayPos.y, arrayPos.x] = Instantiate(tilePrefab[(int)tileType]).GetComponent <HexScript>();
                        newHexBoard[arrayPos.y, arrayPos.x].transform.parent = hexBoardParent;
                        //newHexBoard[nextHex.ToArrayPos(radius).y, nextHex.ToArrayPos(radius).x].position = new AxialHex(nextHex.y, nextHex.x);
                        if (debugMode)
                        {
                            Debug.Log("hexBoard[" + arrayPos.y + "," + arrayPos.x + "] is instantiated");
                        }
                    }

                    //Set Scale
                    newHexBoard[arrayPos.y, arrayPos.x].transform.localScale = Vector3.one * tileSize;
                    newHexBoard[arrayPos.y, arrayPos.x].position             = new Hex(nextHex.x, nextHex.y);

                    newHexBoard[arrayPos.y, arrayPos.x].isChecked    = false;
                    newHexBoard[arrayPos.y, arrayPos.x].isObstacle   = false;
                    newHexBoard[arrayPos.y, arrayPos.x].movementCost = Mathf.Infinity;
                    newHexBoard[arrayPos.y, arrayPos.x].parentTile   = null;
                    newHexBoard[arrayPos.y, arrayPos.x].state        = TileState.Empty;

                    nextHex = nextHex.GetNeighbour(dir);
                }
            }
        }

        //Save new board
        tileBoard = newHexBoard;
        return;
    }