Exemple #1
0
    //change turn method switches the bool state

    public void ChangeTurn()
    {
        isItRedsTrun = !isItRedsTrun;
        FindObjectOfType <DDmanager>().HideAllDD();

        FindObjectOfType <CellManager>().HideAllCells();
        FindObjectOfType <CellManager>().UpdateFreeSpaces();

        myEndTurn.ChangeButtonState(false);

        Cell[] allCells = FindObjectsOfType <Cell>();

        foreach (Cell cell in allCells)
        {
            cell.isaSkipCell = false;
        }

        OctiPawn[] allOctis = FindObjectsOfType <OctiPawn>();

        foreach (OctiPawn maybeDeathOcti in allOctis)
        {
            if (maybeDeathOcti.isDeathHighlight)
            {
                Destroy(maybeDeathOcti);
                Destroy(maybeDeathOcti.gameObject);
            }
        }

        //0 is green win
        //1 is red win
        //2 is no win event

        //IsRedWin() is an int return type

        WinManager myWinManager = FindObjectOfType <WinManager>();

        if (myWinManager.IsRedWin() == 0)
        {
            //print("green wins");

            SaveData.Instance.DeleteGame(RECENT_KEY, 9999);
            WinTrack.winInt = 0;
            mySceneManager.LoadNextSceneOnDelay(1);
        }
        else if (myWinManager.IsRedWin() == 1)
        {
            //print("red wins");

            SaveData.Instance.DeleteGame(RECENT_KEY, 9999);
            WinTrack.winInt = 1;
            mySceneManager.LoadNextSceneOnDelay(1);
        }


        //turned off for developig purposes
        //
        //Camera mainCam = FindObjectOfType<Camera>();
        //mainCam.transform.Rotate(0.0f, 0.0f, 180.0f, Space.Self);
    }
Exemple #2
0
    public void MoveOctiToCell(bool isLoad)
    {
        Vector3Int gameSaveVar = new Vector3Int();

        CalculateWorldPosForOcti();

        OctiPawn[] allOcti       = FindObjectsOfType <OctiPawn>();
        OctiPawn   theChosenOcti = null;

        Vector2Int oldOctPos = new Vector2Int();
        Vector2Int avragePos = new Vector2Int();

        bool hasOctiMovPotential = false;

        //find selected octi

        foreach (OctiPawn octi in allOcti)
        {
            if (octi.IsOctiHighlighted())
            {
                theChosenOcti = octi;

                gameSaveVar.x = theChosenOcti.octiId;
                gameSaveVar.y = 1;
                oldOctPos     = octi.GetOctiCords();

                octi.transform.position = new Vector3
                                          (
                    worldPosForOct.x,
                    worldPosForOct.y,
                    -2
                                          );

                octi.SetOctiCords(cords);

                //the rest of this code is for
                //eating an octi in case there is one to eat
                //by avraging the pos of the chosen octi
                //with the cell to get the cell inbetween

                int avragePosX = Avrage(oldOctPos.x, cords.x);
                int avragePosY = Avrage(oldOctPos.y, cords.y);

                Vector2Int directionVec = new Vector2Int();
                directionVec.x = cords.x - oldOctPos.x;
                directionVec.y = cords.y - oldOctPos.y;

                foreach (Vector2Int curDirection in theChosenOcti.myDirections)
                {
                    if (curDirection == directionVec)
                    {
                        DD[] allOctisDDs =
                            theChosenOcti.GetComponentsInChildren <DD>();

                        foreach (DD dd in allOctisDDs)
                        {
                            if (dd.direction == curDirection)
                            {
                                gameSaveVar.z = dd.directionID;
                            }
                        }
                    }
                    else if (curDirection * 2 == directionVec)
                    {
                        DD[] allOctisDDs =
                            theChosenOcti.GetComponentsInChildren <DD>();

                        foreach (DD dd in allOctisDDs)
                        {
                            if (dd.direction == curDirection)
                            {
                                gameSaveVar.z = dd.directionID;
                            }
                        }
                    }
                }

                avragePos = new Vector2Int(avragePosX, avragePosY);

                OctiPawn[] allOctis = FindObjectsOfType <OctiPawn>();
                foreach (OctiPawn octiPawn in allOctis)
                {
                    bool isPosSame  = (octiPawn.GetOctiCords() == avragePos);
                    bool isSkipCell = isaSkipCell;

                    bool isSkip      = (isPosSame && isSkipCell);
                    bool isOctiEnemy = (octiPawn.isRed != theChosenOcti.isRed);

                    if (isSkip && isOctiEnemy)
                    {
                        if (theChosenOcti.isRed && !octiPawn.isDeathHighlight)
                        {
                            FindObjectOfType <TurnManager>().redDDcount += octiPawn.myDirections.Count;
                            FindObjectOfType <TurnManager>().UpdateDDcountText();
                        }
                        else if (!octiPawn.isDeathHighlight)
                        {
                            FindObjectOfType <TurnManager>().greenDDcount += octiPawn.myDirections.Count;
                            FindObjectOfType <TurnManager>().UpdateDDcountText();
                        }
                        octiPawn.DeathSelect();
                    }
                }
            }
        }

        FindObjectOfType <CellManager>().HideAllCells();
        FindObjectOfType <CellManager>().UpdateFreeSpaces();

        if (theChosenOcti != null && isaSkipCell)
        {
            FindObjectOfType <CellManager>().HighlightAvialabeChainCells(theChosenOcti);
            Cell[] allCells = FindObjectsOfType <Cell>();

            foreach (Cell myCell in allCells)
            {
                if (myCell.isActive)
                {
                    hasOctiMovPotential = true;
                }
            }
        }
        if (!isLoad)
        {
            FindObjectOfType <GameSave>().SaveGameData(gameSaveVar);
            print(gameSaveVar);
        }

        if (hasOctiMovPotential)
        {
            myEndTurn.ChangeButtonState(true);
            theChosenOcti.isOnChain = true;
        }
        else
        {
            theChosenOcti.ChangeHighlightState(false);
            FindObjectOfType <TurnManager>().ChangeTurn();
            FindObjectOfType <ProcessManager>().isProcessNow = false;
        }
    }