Example #1
0
    private void HighlightSkipCellBasedDirection
        (Vector2Int originalPos, Vector2Int directionPos, OctiPawn myOcti)
    {
        Vector2Int blockingOctPos = originalPos;

        blockingOctPos += directionPos;

        Vector2Int futurePos = originalPos;

        futurePos += directionPos;
        futurePos += directionPos;

        bool isThereBlock = (takenSpaces.Contains(blockingOctPos));
        bool isThereFreeSpaceAfterwards = (freeSpaces.Contains(futurePos));

        if (isThereBlock && isThereFreeSpaceAfterwards)
        {
            Cell[] allCells = FindObjectsOfType <Cell>();

            foreach (Cell myCell in allCells)
            {
                bool hasOctiDirection = (myOcti.myDirections.Contains(directionPos));
                bool isSpaceFree      = (myCell.GetMyCellCords() == futurePos);

                if (isSpaceFree && hasOctiDirection)
                {
                    myCell.ChangeMyState(true);
                    myCell.isaSkipCell = true;
                }
            }
        }
    }
Example #2
0
    public void HighlightAvailableCells(OctiPawn myOcti)
    {
        Vector2Int octPos = myOcti.GetOctiCords();

        HighlightCellBasedDirection
            (octPos, MovementDirection.Backward, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Forward, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Right, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Left, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Backwardright, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Backwardleft, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Forwardright, myOcti);
        HighlightCellBasedDirection
            (octPos, MovementDirection.Forwardleft, myOcti);
    }
Example #3
0
File: Cell.cs Project: waxenon/octi
    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;
        }
    }