public void SelectPole(PoleControl newSelection)
    {
        if (selectedStone == null)
        {
            return;
        }
        float oldX = GetPolePositionX(selectedStone.CurrentPole);
        float newX = newSelection.GetPositionX();

        if (oldX == newX)
        {
            selectedStone = null;
            return;
        }

        StoneControl newSelectedStone = newSelection.GetTopStone();

        if (newSelectedStone != null && selectedStone.Size > newSelectedStone.Size)
        {
            return;
        }

        isUp = true;

        if (oldX < newX)
        {
            rightCount = (newX - oldX) / 6 <= 1? 1 : 2;
        }
        else
        {
            leftCount = (oldX - newX) / 6 <= 1? 1 : 2;
        }
    }
 public void solveTowers(int n, PoleControl startPole, PoleControl endPole, PoleControl tempPole)
 {
     if (n > 0)
     {
         solveTowers(n - 1, startPole, tempPole, endPole);
         print("Move disk from " + startPole.name + " to " + endPole.name);
         steps.Enqueue(new PoleControl[] { startPole, endPole });
         solveTowers(n - 1, tempPole, endPole, startPole);
     }
 }
Beispiel #3
0
    // ********************************************************************************************************
    // OBJECTS CREATION ***************************************************************************************
    // ********************************************************************************************************


    // CREATION OF NEW NORM POLE
    public GameObject CreateNormPole(int poleID, Vector3 startPoint, float startYRotation, BeltType[] beltTypes, PoleParams poleParams, PoleModification poleModif)
    {
        // CREATE THE NORM POLE
        GameObject  newNormPole          = Instantiate(poleNormPrefab, startPoint + new Vector3(0, 2.5f, 0), Quaternion.Euler(0, 0, 0));
        PoleControl newNormPoleControl   = newNormPole.GetComponent <PoleControl>();
        Vector3     newNormPoleScale     = newNormPole.transform.lossyScale;
        Vector3     newNormPoleScaleInv  = new Vector3(1 / newNormPoleScale.x, 1 / newNormPoleScale.y, 1 / newNormPoleScale.z);
        Vector3     newNormPoleAIMoveDir = Quaternion.Euler(0, startYRotation, 0) * newNormPole.transform.forward;

        // TRANSFERRING  GLOBAL OBJECTS, POLE PARAMS, MODIFICATION AND ASSEMBLY TO NEW POLE
        newNormPoleControl.globalObjects = globalObjects;
        newNormPoleControl.poleParams    = poleParams;
        newNormPoleControl.poleModif     = poleModif;
        newNormPoleControl.poleAssembly  = newNormPole.transform.GetChild(0).gameObject;
        newNormPoleControl.AIMoveDir     = newNormPoleAIMoveDir;

        // IF NEW POLE IS PLAYER - UPDATING GLOBAL PARAMS
        if (poleParams.type == PoleType.Player)
        {
            globalObjects.playerPole = newNormPole;
            playerPole = newNormPole;
            mainCamera.GetComponent <CameraControl>().focusObject = newNormPole;
        }

        // SENSOR CREATION
        GameObject newSensor = Instantiate(sensor1Prefab, startPoint + new Vector3(0, 4.5f, 0), newNormPole.transform.rotation, newNormPoleControl.poleAssembly.transform);

        newNormPoleControl.selfSensor  = newSensor;
        newSensor.transform.localScale = newNormPoleScaleInv;

        // CREATING TEXT
        Text newText = Instantiate <Text>(infoText);

        newText.transform.SetParent(mainCanvas.transform);
        newText.transform.position = mainCanvas.transform.TransformPoint((poleID + 1) * 200 - Screen.width / 2 + 10, Screen.height / 2 - 10, 0);

        // CREATING ENERGYBAR
        Image newEnergyBar = Instantiate <Image>(globalObjects.barPrefab);

        newEnergyBar.transform.SetParent(mainCanvas.transform);
        BarControl newEnergyBarControl = newEnergyBar.GetComponent <BarControl>();

        newEnergyBarControl.maxValue     = poleParams.poleMaxEnergy * poleModif.energyMaxCoef;
        newEnergyBarControl.currValue    = poleParams.poleMaxEnergy * poleModif.energyMaxCoef;
        newEnergyBarControl.transparency = poleParams.barTransparency;
        newEnergyBarControl.barHeight    = barHeight;

        // DEFINING COLORS AND TAG
        switch (poleParams.type)
        {
        case PoleType.Player:
            newEnergyBarControl.backGroundCol = new Color32(0, 10, 73, newEnergyBarControl.transparency);
            newEnergyBarControl.foreGroundCol = new Color32(70, 100, 230, newEnergyBarControl.transparency);
            newText.color   = new Color32(0, 230, 10, 255);
            newNormPole.tag = "PlayerTeam";
            break;

        case PoleType.Enemy:
            newEnergyBarControl.backGroundCol = new Color32(0, 10, 73, newEnergyBarControl.transparency);
            newEnergyBarControl.foreGroundCol = new Color32(70, 100, 230, newEnergyBarControl.transparency);
            newText.color   = new Color32(225, 0, 0, 255);
            newNormPole.tag = "EnemyTeam";
            break;

        case PoleType.NeutralStatic:
            newText.color   = new Color32(160, 160, 160, 255);
            newNormPole.tag = "NeutralTeam";
            break;

        case PoleType.NeutralMovable:
            newText.color   = new Color32(200, 200, 200, 255);
            newNormPole.tag = "NeutralTeam";
            break;
        }

        // CREATING BELTS
        if (beltTypes.Length > 4)
        {
            Array.Resize(ref beltTypes, 4);
        }

        GameObject[] belts = new GameObject[beltTypes.Length];
        if (beltTypes.Length > 0)
        {
            // INITIALIZING FIRST BELT PARAMS WITH UNIT PARAMS
            BeltParams[] newBeltsParams = new BeltParams[beltTypes.Length];

            for (int i = 0; i < beltTypes.Length; i++)
            {
                // DEFINITION OF BELT SIDE
                if (UnitGroups.frontUnits.Contains(beltTypes[i]))
                {
                    // FRONT-ORIENTED BELT
                    newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.front, poleID);
                }
                else if (UnitGroups.backUnits.Contains(beltTypes[i]))
                {
                    // BACK-ORIENTED BELT
                    newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.back, poleID);
                }
                else
                {
                    // SIDE-ORIENTED BELT
                    if ((i == 0) || (!UnitGroups.sideUnits.Contains(beltTypes[i - 1])))
                    {
                        // RANDOM SIDE DEFINITION
                        if (UnityEngine.Random.Range(0, 100) < 50)
                        {
                            // BELT IS RANDOMLY LEFT
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.left, poleID);
                        }
                        else
                        {
                            // BELT IS RANDOMLY RIGHT
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.right, poleID);
                        }
                    }
                    else
                    {
                        // DEFINING OTHER DIRECTION THEN IN PREVIOUS BELT
                        if (newBeltsParams[i - 1].side == BeltSide.left)
                        {
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.right, poleID);
                        }
                        else
                        {
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.left, poleID);
                        }
                    }
                }

                // CREATING BELT OBJECT
                belts[i] = CreateBeltObject(poleID, newBeltsParams[i], ref poleModif, newNormPole, 0.55f - i * 0.1f);
            }
        }

        // TRANSFERRING BELTS, SENSOR, TEXT AND HEALTHBAR TO THE NEW POLE OBJECT
        if (beltTypes.Length > 0)
        {
            Array.Resize(ref newNormPoleControl.belts, belts.Length);
            Array.Resize(ref newNormPoleControl.beltTypes, beltTypes.Length);
            belts.CopyTo(newNormPoleControl.belts, 0);
            beltTypes.CopyTo(newNormPoleControl.beltTypes, 0);
        }
        newNormPoleControl.poleSensor = newSensor;
        newNormPoleControl.lifeText   = newText;
        newNormPoleControl.energyBar  = newEnergyBar;

        return(newNormPole);
    }