Beispiel #1
0
 void Start()
 {
     CD = FindObjectOfType <cardDistrubuter>();
     GM = FindObjectOfType <gameManager>();
 }
Beispiel #2
0
    // Read messages from the server
    private void OnIncomingData(string data)
    {
        string[] aData = data.Split('|');

        Debug.Log(data);

        switch (aData[0])
        {
        case "SWHO":
            for (int i = 1; i < aData.Length - 1; i = i + 2)
            {
                GameClient c = new GameClient();
                c.name           = aData[i];
                c.playerPosition = int.Parse(aData[i + 1]);
                otherPlayers.Add(c);
            }

            Send("CWHO|" + clientName);
            break;

        case "SCNN":
            GameClient cl = new GameClient();
            cl.name           = aData[1];
            cl.playerPosition = int.Parse(aData[2]);
            otherPlayers.Add(cl);
            try
            {
                GM.printNames();
            }
            catch { }
            break;

        case "SPSTN":
            playerPosition = int.Parse(aData[1]);
            Send("CSTRT");
            break;

        case "SSTRT":
            try
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }
            break;

        case "STURN":
            if (playerPosition == int.Parse(aData[1]))
            {
                gameManager.yourTurn = true;
            }
            break;

        case "STCRD":
            CD = FindObjectOfType <cardDistrubuter>();
            int playerPos = int.Parse(aData[1]);
            if (playerPos != playerPosition)
            {
                CD.takeCard(playerPos);
            }
            break;

        case "STHRW":
            GM = FindObjectOfType <gameManager>();
            int throwPlayerPos = int.Parse(aData[1]);
            if (throwPlayerPos != playerPosition)
            {
                GM.throwCard(throwPlayerPos, short.Parse(aData[2]));
                if (throwPlayerPos % 4 + 1 == playerPosition)
                {
                    gameManager.yourTurn      = true;
                    cardDistrubuter.cardTaken = false;
                }
            }

            break;

        case "STGND":
            CD = FindObjectOfType <cardDistrubuter>();
            int playerIndex = int.Parse(aData[1]);
            if (playerIndex != playerPosition)
            {
                CD.takeGround(playerIndex);
            }
            break;


        case "SOPNC":
            playerIndex = int.Parse(aData[1]);
            for (int i = 2; i < aData.Length && aData[i] != ""; i++)
            {
                miniCard cardInstance = Instantiate(GM.miniCard).GetComponent <miniCard>();
                cardInstance.cardIndex = short.Parse(aData[i]);
                cardInstance.showFace();
                gameManager.openedCards[playerIndex].Add(cardInstance);
                GM.openedArranger(playerIndex);
            }
            break;
        }
    }