Beispiel #1
0
    void OnClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //is selecting on the board
            //if (selectedX >= 0 && selectedY >= 0) {

            if (selectedX >= 0 && selectedY >= 0)
            {
                // piece is not already selected
                if (selectedPiece == null)
                {
                    SelectPiece(selectedX, selectedY);

                    // piece is selected
                    // move or drop piece
                }
                else
                {
                    //piece is on the board: move it
                    if (!selectedPiece.isCaptured)
                    {
                        MovePiece();
                    }
                    else
                    {
                        //piece is on side table: drop it
                        if (selectedPiece.isPlayerOne)
                        {
                            table1.DropPiece(selectedX, selectedY);
                        }
                        else
                        {
                            table2.DropPiece(selectedX, selectedY);
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    // Read messages from the server
    private void OnIncomingData(string data)
    {
        Debug.Log("Client: " + data);

        if (boardManager == null)
        {
            boardManager = BoardManager.GetInstance();
        }

        string[] aData = data.Split('|');

        switch (aData [0])
        {
        case "SWHO":
            for (int i = 1; i < aData.Length - 1; i++)
            {
                UserConnected(aData [i], false);
            }
            Send("CWHO|" + clientName + "|" + (isHost ? "host":"!host"));
            break;

        case "SCNN":
            UserConnected(aData [1], false);
            break;

        case "SMOV":

            if (isHost != boardManager.isPlayerOnesTurn)
            {
                int xOld = int.Parse(aData [1]);
                int yOld = int.Parse(aData [2]);
                int xNew = int.Parse(aData [3]);
                int yNew = int.Parse(aData [4]);

                boardManager.selectedPiece = (boardManager.pieces [xOld, yOld]);
                Square move = new Square(new Vector2Int(xNew, yNew));
                boardManager.MovePiece(move);
            }

            break;

        case "SDROP":

            sideTable = isHost ? boardManager.table2 : boardManager.table1;

            if (isHost != boardManager.isPlayerOnesTurn)
            {
                int xOld = int.Parse(aData [1]);
                int yOld = int.Parse(aData [2]);
                int xNew = int.Parse(aData [3]);
                int yNew = int.Parse(aData [4]);

                sideTable.selectedX = xOld;
                sideTable.selectedY = yOld;

                sideTable.SelectPiece();

                sideTable.DropPiece(xNew, yNew);
            }

            break;
        }
    }