Beispiel #1
0
    public Hex[][] GenerateBoard(BoardBlueprint blueprint)
    {
        GameObject boardParent = new GameObject();

        boardParent.name = "Board";
        CalculateHexNumbers(blueprint.basicHex);
        int[] board = blueprint.board;

        Hex[][] hexBoard    = new Hex[board.Length][];
        Vector3 startingPos = blueprint.startingPoint;
        int     halvedTable = (int)Mathf.Round(board.Length / 2);


        for (int i = 0; i < board.Length; i++)
        {
            GenerateLine(startingPos, board[i], i, hexBoard, blueprint, boardParent);

            if (i < halvedTable)
            {
                startingPos = new Vector3(startingPos.x - hexPk / 2 - blueprint.hexOffSet / 2, startingPos.y - ((3 * hexA) / 2) - blueprint.hexOffSet, startingPos.z);
            }
            else
            {
                startingPos = new Vector3(startingPos.x + hexPk / 2 + blueprint.hexOffSet / 2, startingPos.y - ((3 * hexA) / 2) - blueprint.hexOffSet, startingPos.z);
            }
        }

        return(hexBoard);
    }
Beispiel #2
0
    private void GenerateLine(Vector3 linePosition, int lineSize, int lineNumber, Hex[][] hexBoard, BoardBlueprint blueprint, GameObject parent)
    {
        hexBoard[lineNumber] = new Hex[lineSize];
        Vector3 position;

        for (int i = 0; i < lineSize; i++)
        {
            position = new Vector3(linePosition.x + (hexPk * i) + blueprint.hexOffSet * i, linePosition.y, 0);
            blueprint.basicHex.GetComponent <Hex>();
            Hex hex = Instantiate(blueprint.basicHex, position, blueprint.basicHex.transform.rotation, parent.gameObject.transform).GetComponent <Hex>();
            hex.name = $"Hex X: {lineNumber} Y: {i}";
            hex.InputPosition(lineNumber, i);
            //Initialize HEX inner info about its line and element number for ex. [lineNumber][i]
            hexBoard[lineNumber][i] = hex; //Add hex to HEX board
        }
    }