Example #1
0
 /**
  * przekazujemy hex który jest pusty. wtedy metoda sprawdza sąsiednie, jeśli sąsiedni jest pusty i zakrtyty to rekurencyjnie wywołuje tą metodę jeszcze raz
  */
 private void ProccessEmpty(HexField hex)
 {
     Field field = (Field)hex.hexLogic;
     if(field.top.enabled == true && field.flag.enabled == false){
         field.top.enabled = false;
         List<HexField> listNeigbors = boardManager.GetNeigbors(hex.GetCoordinates());
         foreach (HexField neigborHex in listNeigbors) {
             if(field.type == Field.TypeNames.EMPTY){
                 ProccessEmpty(neigborHex);
             }
         }
     }
 }
        /**
         * do rzeczywistej budowy potrzebujemy rozmiar  hexa i ilość hexów, nie potrzebujemy rozmiaru mapy
         */
        private BoardHex BuildCalc()
        {
            if (board.IsReady() == true)               //znaczy że ta plansza jest już zbudowana
            {
                return(board);
            }
            hexPattern.gameObject.SetActive(false);
            float calcHeigh  = HexMath.CalculateColumnHeight(recommendHexHeight, rowNumber);
            float halfHeight = calcHeigh / 2;            //rowNumber / 2;
            float halfWidth  = 0;

            if (rowNumber > 1 && symmetricHorizontal == false)             // jak symmetricHorizontal true to nie ma przesunięcia wynikającego z połowy hexa na szerokość
            {
                halfWidth = HexMath.CalculateMultiRowWidth(hexWidth, colNumber) / 2;
            }
            else
            {
                halfWidth = HexMath.CalculateRowWidth(hexWidth, colNumber) / 2;
            }
            Transform hexObject;

            board.Config(colNumber, rowNumber, new Vector2(hexWidth, recommendHexHeight), isEven, symmetricHorizontal);
            this.listenerList.OnBuildStart(hexPattern, colNumber, rowNumber, new Vector2(hexWidth, recommendHexHeight), isEven, symmetricHorizontal);
            int inverse = 0;             //ponieważ inverse nie jest hexem o y = 0 tylko jest zależny od rowNumber musimy mieć inną wartość inverse

            if (isEven == true && rowNumber % 2 == 1)
            {
                inverse = 0;
            }
            else if (isEven == true && rowNumber % 2 == 0)
            {
                inverse = 1;
            }
            else if (isEven == false && rowNumber % 2 == 1)
            {
                inverse = 1;
            }
            else if (isEven == false && rowNumber % 2 == 0)
            {
                inverse = 0;
            }
            for (int y = rowNumber - 1; y >= 0; y--)
            {
                for (int x = 0; x < colNumber; x++)
                {
                    if (symmetricHorizontal && x == colNumber - 1 && inverse == 0)
                    {
                        break;
                    }
                    Vector3 newCoordinates;
                    if (isEven)
                    {
                        newCoordinates = HexMath.ConvertEvenROffsetToCubeCoordinate(x, y);
                    }
                    else
                    {
                        newCoordinates = HexMath.ConvertOddROffsetToCubeCoordinate(x, y);
                    }
                    bool listenerResult = this.listenerList.OnCreateHexStart(newCoordinates, new Vector2(x, y), (inverse == 1)?true:false);
                    if (listenerResult == false)
                    {
                        continue;
                    }
                    hexObject = (Transform)Instantiate(hexPattern.transform, new Vector3(0, 0, 0), Quaternion.identity);
                    hexObject.gameObject.SetActive(true);
                    hexObject.transform.parent = board.transform;
                    HexField hexComponent = hexObject.GetComponent <HexField> ();
                    hexComponent.Init();
                    hexComponent.SetPosition(new Vector3(hexWidth * x + hexWidth - inverse * 0.5f * hexWidth - halfWidth, -3 * (y) * recommendHexHeight / 4 + halfHeight - recommendHexHeight / 2, 0));
                    hexComponent.SetSize(new Vector2(hexWidth, recommendHexHeight));
                    board.Add(newCoordinates, hexComponent);
                    hexObject.name = "Hex " + hexComponent.GetCoordinates().ToString() + " " + x + " " + y;
                    this.listenerList.OnCreateHexEnd(hexComponent);
                }
                inverse = (inverse == 1)?0:1;              //na wysokość co drugi wiersz ma przesunięcie - w ten sposób to oznaczamy
            }

//			board.SetHexNumber (colNumber, rowNumber);
            board.Recalculate();
            board.SetReady();
            this.listenerList.OnBuildEnd();
            return(board);
        }