Пример #1
0
    private bool IsPeice(PlayerPeice peice, BoardSegment segment)
    {
        if (peice)
        {
            return(true);
        }
        else
        {
            if (segment)
            {
                if (segment.state == SegmentOccupationState.Empty)
                {
                    this.peice = Board.peices[segment.pos.indexX, segment.pos.indexY].GetComponent <PlayerPeice>();
                }


                if (this.peice)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            //return false;
        }

        return(false);
    }
Пример #2
0
    public void HoverPeice(int x, int y)
    {
        //Vector3 hoverTarget = segment.snapPointHover.position;//Board.boardSpaces[(int)peice.acessIndex.x, (int)peice.acessIndex.y].GetComponent<BoardSegment>().snapPointHover.position
        //BoardSegment segment =

        PlayerPeice peice       = Board.peices[x, y].GetComponent <PlayerPeice>();
        Vector3     hoverTarget = Board.boardSpaces[x, y].GetComponent <BoardSegment>().snapPointHover.position;

        peice.HoverUp(hoverTarget);
    }
Пример #3
0
    public void ProcessUpdate(int gameStatus, int whoseTurn, byte[] spaces)
    {
        whosTurn = whoseTurn;

        playUI.UpdateTurnDisplay(whoseTurn);

        if (gameBoard.HandleMove(spaces))
        {
            peiceSelected = false;
            peice         = null;
            // segment = null;
        }

        if (gameStatus > 0)
        {
            playUI.UpdateVictory(gameStatus);
        }
    }
Пример #4
0
    //TODO: Generate an *x8 board
    //TODO: Chanvge the color of the board segements
    //TODO: Populate the game board with player peices
    //TODO: Impliment singelton


    /*
     * // Start is called before the first frame update
     * void Start()
     * {
     * BuildBoard();
     *
     * }
     *
     *
     * void Update()
     * {
     *
     * }
     */

    #region BoardGeneration
    public GameObject[,] BuildBoard(byte[] serverState, bool rebuildBoard = false)
    {
        //TODO: Place Peices on board according to the server state

        if (boardSpaces != null)
        {
            if (rebuildBoard)
            {
                DeconstructBoard();
            }
            else
            {
                return(boardSpaces);
            }
        }


        boardSpaces = new GameObject[boardSize, boardSize];
        peices      = new GameObject[boardSize, boardSize];

        int   totalIterations = 0;
        float segmentSpaceing = 1 + offset;

        for (int y = 0; y < boardSize; y++)
        {
            for (int x = 0; x < boardSize; x++)
            {
                GameObject b = InstantiateSegmant(new Vector3((segmentSpaceing) * x, 0, (segmentSpaceing) * y)); //spawn board segmants
                boardSpaces[x, y] = b;                                                                           //store a refrence to the segmant
                BoardSegment bs = b.GetComponent <BoardSegment>();                                               //
                bs.init(new BoardPOS(x, y), blackMat, whiteMat);

                //print("totalIterations: " + totalIterations);

                //int sState = (int)serverState[totalIterations];

                //print("serverState: " + (SegmentOccupationState)serverState[totalIterations]);

                GameObject peice = bs.PopulateStart((SegmentOccupationState)serverState[totalIterations]);

                if (peice)
                {
                    peices[x, y] = peice;
                    PlayerPeice peiceScript = peice.GetComponent <PlayerPeice>();
                    peiceScript.acessIndex = new Vector2(x, y);
                }

                if (y % 2 != 0 && y != 0)         //every other row
                {
                    if (totalIterations % 2 == 0) //if we are even
                    {
                        SwapToBlack(b);
                    }
                }
                else if (totalIterations % 2 != 0 && totalIterations != 0)//if we are odd
                {
                    SwapToBlack(b);
                }


                totalIterations++;
            }
        }

        return(boardSpaces);
    }
Пример #5
0
    }//update

    private void HandleSelection()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        //print("Casting");
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))//, 50000, peiceMask))
        {
            PlayerPeice  p;
            BoardSegment b = null;

            //bool isPeice = true;

            //print("castHit");
            GameObject obj = hit.collider.gameObject;
            if (obj != null)
            {
                p = obj.GetComponentInParent <PlayerPeice>();

                b = obj.GetComponentInParent <BoardSegment>();

                if (p == null && b == null)//if it's not a player peice
                {
                    return;
                }
            }
            else
            {
                return;
            }



            if (p)
            {
                if (p.owner == playerState)
                {
                    if (p == peice) //we have clicked on our selected peice again
                    {
                        peiceSelected = false;
                        peice         = null;
                    }
                    else //we have clicked on one of our peices
                    {
                        peice = p;
                        ControllerGameClient.singleton.SendPacketToServer(PacketBuilder.Hover((int)peice.acessIndex.x, (int)peice.acessIndex.y));
                        peiceSelected = true;
                    }
                }
                else if (peiceSelected)   //we have a piece selected and we are clicking on the opponents peice

                {
                    SendMoveToServer((int)p.acessIndex.x, (int)p.acessIndex.y);
                }
            }
            else if (peiceSelected && b)   //we have selected a segmant and we have a piece selected

            {
                SendMoveToServer(b.pos.indexX, b.pos.indexY);
            }


            /*
             * //Debug.Log(hit.collider.gameObject.name);
             * peice = hit.collider.gameObject.GetComponentInParent<PlayerPeice>();
             * segment = hit.collider.gameObject.GetComponent<BoardSegment>();
             *
             *
             * if (IsPeice(peice, segment)) {
             *
             *  ControllerGameClient.singleton.SendPacketToServer(PacketBuilder.Hover((int)peice.acessIndex.x, (int)peice.acessIndex.y));
             * }
             * //Debug.Log(peice.peiceType + " " + peice.owner);
             */
        }

        /*
         *         else if (Physics.Raycast(ray, out hit, 50000, boardMask) && peiceSelected) {
         *
         *             segment = hit.collider.gameObject.GetComponent<BoardSegment>();
         *
         *
         *
         *
         *
         *         }//raycasthit
         */
    }