示例#1
0
    private bool OccupiedByEnemey(SegmentOccupationState currentState, SegmentOccupationState futureState)
    {
        if (currentState == SegmentOccupationState.Empty)
        {
            return(false);
        }

        if ((int)futureState < 7 && (int)currentState >= 7)
        {
            return(true);
        }
        else if ((int)futureState >= 7 && (int)currentState < 7)
        {
            return(true);
        }

        return(false);
    }
示例#2
0
    public GameObject PopulateStart(SegmentOccupationState serverState)//populates this segmant based on the state of the server
    {
        state = serverState;
        if (serverState == SegmentOccupationState.Empty)
        {
            return(null);
        }

        GameObject playerPeice = null;
        Material   peiceMat    = whiteMat;
        int        player      = 0;
        int        peice       = 0;
        bool       isPlayer1   = false;

        if ((int)serverState > 0 && (int)serverState <= 6)//if it is a player 1 peice
        {
            peice = (int)serverState;
            //peiceMat = whiteMat;
            player    = 1;
            isPlayer1 = true;
        }
        else if ((int)serverState != 0 && (int)serverState >= 7)
        {//if it is a player 2 peice
            peice     = (int)serverState - 6;
            peiceMat  = blackMat;
            player    = 2;
            isPlayer1 = false;
        }
        else
        {
            print("Error: server state out of bounds");
        }

        playerPeice = HandleInstantiatePeice(peiceMat, player, isPlayer1, (Peices)peice);


        return(playerPeice);
    }
示例#3
0
    private void SetPeice(bool isPlayer1, Peices peice)
    {
        switch (peice)
        {
        case Peices.Pawn:
            state = isPlayer1 ? SegmentOccupationState.P1Pawn : SegmentOccupationState.P2Pawn;
            break;

        case Peices.Rook:
            state = isPlayer1 ? SegmentOccupationState.P1Rook : SegmentOccupationState.P2Rook;
            break;

        case Peices.Knight:
            state = isPlayer1 ? SegmentOccupationState.P1Knight : SegmentOccupationState.P2Knight;
            break;

        case Peices.Bishop:
            state = isPlayer1 ? SegmentOccupationState.P1Bishop : SegmentOccupationState.P2Bishop;
            break;

        case Peices.Queen:
            state = isPlayer1 ? SegmentOccupationState.P1Queen : SegmentOccupationState.P2Queen;
            break;

        case Peices.King:
            state = isPlayer1 ? SegmentOccupationState.P1King : SegmentOccupationState.P2King;
            break;

        case Peices.Empty:
            state = SegmentOccupationState.Empty;
            break;

        default:
            state = SegmentOccupationState.Empty;
            break;
        }
    }
示例#4
0
    public bool HandleMove(byte[] updatedState)
    {
        Vector2 currentIndex = new Vector2(-1, -1);
        Vector2 targetIndex  = new Vector2(-1, -1);


        //determine which spaces can need to be updated
        for (int i = 0; i < updatedState.Length; i++)
        {
            int y = i / boardSize;
            int x = i % boardSize;

            if (updatedState[i] == 0)
            {
                if (updatedState[i] != (int)boardSpaces[x, y].GetComponent <BoardSegment>().state)
                {
                    currentIndex = new Vector2(x, y);
                }
            }
            else
            {
                if (updatedState[i] != (int)boardSpaces[x, y].GetComponent <BoardSegment>().state)
                {
                    targetIndex = new Vector2(x, y);
                }
            }
        }

        if (targetIndex.x < 0 || targetIndex.y < 0 || currentIndex.x < 0 || currentIndex.y < 0)
        {
            return(false);                                                                                    //there was no change in board state
        }
        BoardSegment targetSegmant = boardSpaces[(int)targetIndex.x, (int)targetIndex.y].GetComponent <BoardSegment>();
        //BoardSegment currentSegmant = boardSpaces[(int)currentIndex.x, (int)currentIndex.y].GetComponent<BoardSegment>();

        //remove "taken peices"
        SegmentOccupationState futureState = (SegmentOccupationState)updatedState[targetSegmant.pos.packetIndex];

        if (OccupiedByEnemey(targetSegmant.state, futureState))
        {
            GameObject p = peices[(int)targetIndex.x, (int)targetIndex.y];
            if (p != null)
            {
                peices[(int)targetIndex.x, (int)targetIndex.y] = null;
                //print("DESTROYING");
                Destroy(p);
            }
            else
            {
                //print("alwats null");
                return(false);
            }
        }

        //move peices on gameboard
        peices[(int)currentIndex.x, (int)currentIndex.y].GetComponent <PlayerPeice>().MovePeice(targetSegmant.snapPointHover.position, targetSegmant.snapPointPlaced.position);


        //update gamestate
        peices[(int)targetIndex.x, (int)targetIndex.y]   = peices[(int)currentIndex.x, (int)currentIndex.y];
        peices[(int)currentIndex.x, (int)currentIndex.y] = null;

        peices[(int)targetIndex.x, (int)targetIndex.y].GetComponent <PlayerPeice>().acessIndex = targetIndex;

        boardSpaces[(int)targetIndex.x, (int)targetIndex.y].GetComponent <BoardSegment>().state   = boardSpaces[(int)currentIndex.x, (int)currentIndex.y].GetComponent <BoardSegment>().state;
        boardSpaces[(int)currentIndex.x, (int)currentIndex.y].GetComponent <BoardSegment>().state = SegmentOccupationState.Empty;


        return(true);
    }