コード例 #1
0
    /// <summary>
    /// Gives a color to hexnode,
    /// checks if an triple group have same color,
    /// if it has corrects the colors of hexnode
    /// </summary>
    /// <param name="tempNode"></param>
    /// <param name="random"></param>
    public void giveAColorToTheCreatedHexNode(HexaNode tempNode, bool random)
    {
        if (giveColorFromStart(random, tempNode))
        {
            return;
        }
        List <List <int> > allTripleGroups = getGroupofTriples(tempNode);
        int randomColorIndex = UnityEngine.Random.Range(0, ColorSystem.colorCount);

        tempNode.myColorIndex = randomColorIndex;
        if (allTripleGroups.checkGroupTriplesHaveSameCountOfColorByGivenCountOfColor(1) == true)
        {
            for (int i = 0; i < ColorSystem.colorCount - 1; i++)
            {
                randomColorIndex++;
                if (randomColorIndex >= ColorSystem.colorCount)
                {
                    randomColorIndex -= ColorSystem.colorCount;
                }
                tempNode.myColorIndex = randomColorIndex;
                if (allTripleGroups.checkGroupTriplesHaveSameCountOfColorByGivenCountOfColor(1) == false)
                {
                    break;
                }
            }
        }
        tempNode.changeColor(randomColorIndex);
        return;
    }
コード例 #2
0
    private bool giveColorFromStart(bool random, HexaNode tempNode)
    {
        int tempNodeCount = NodeManager.mapNodes.Count;
        int columnIndex   = (tempNodeCount - 1).GetColumnOfIndex(height);
        int rowIndex      = (tempNodeCount - 1).GetRowOfIndex(height);

        //Hexagons colors in first column and lowest y axised row's first columns on map can be selected randomly.
        if (random || (columnIndex == 0) || ((columnIndex % 2 != 0) && (rowIndex == 0)))
        {
            tempNode.changeColor(UnityEngine.Random.Range(0, ColorSystem.colorCount));
            return(true);
        }
        return(false);
    }
コード例 #3
0
    /// <summary>
    /// Adding new nodes and removing exloding nodes in giving column
    /// </summary>
    /// <param name="nodesInColumn"></param>
    /// <param name="columIndex"></param>
    private void addAndRemoveNewNodestoTheGame(List <int> nodesInColumn, int columIndex)
    {
        nodesInColumn.Sort();
        int insertIndex = (columIndex + 1) * GameManager.instance.gridSys.height;//column to insert
        int explodingNodeCountInAColumn = nodesInColumn.Count;

        for (int i = explodingNodeCountInAColumn - 1; i >= 0; i--)
        {
            HexaNode tempNode = GameManager.instance.gridSys.giveMeAnHexaNode(giveNodesUpperPosition(i, explodingNodeCountInAColumn, insertIndex));
            NodeManager.mapNodes.Insert(insertIndex, tempNode);
            Destroy(NodeManager.mapNodes[nodesInColumn[i]].gameObject);
            NodeManager.mapNodes.RemoveAt(nodesInColumn[i]);
        }
        StartCoroutine(startRoutinesOfNodesInSameColumn(insertIndex, nodesInColumn));
    }
コード例 #4
0
    private void createGrid()
    {
        //scale calculation for placing hexs correct positions according to x and y
        float oneSideScale = Mathf.Clamp(height, 7, 100) < (Mathf.Clamp(width, 7, 100)) + 2f ? 5f / ((Mathf.Clamp(width, 7, 100)) * 3.2f * 1f / 4f + 1f / 4f) : 5f / (Mathf.Clamp(height, 7, 100) * 3.2f * 1f / 4f + 1f / 4f);

        correctScales(oneSideScale);
        xPlusPos = oneSideScale / 2f + oneSideScale / 4f;                     //extra offsets for correctly placing to screen size
        yPlusPos = 2f * oneSideScale / 4f * Mathf.Sqrt(3f);                   //
        xOffSet  = ((width * (3f * oneSideScale / 4f) + oneSideScale / 4f) - oneSideScale) / 2f;
        yOffSet  = (height * yPlusPos + (yPlusPos / 2f)) * oneSideScale / 2f; //ekran yerleşimi için
        Vector3 position = Vector3.zero, rotation = Hex.transform.rotation.eulerAngles;

        NodeManager.mapNodes = new List <Node>(width * height);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                position = getPositionOfGivenNodeIndex(NodeManager.mapNodes.Count);
                HexaNode temp = giveMeANewNode(position).GetComponent <HexaNode>();
                NodeManager.mapNodes.Add(temp);
                giveAColorToTheCreatedHexNode(temp, false);
            }
        }
    }