/// <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; }
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); }