コード例 #1
0
    private void openCards()
    {
        for (int i = 0; i < selectedCards.Count; i++)
        {
            miniCard miniCardInstance = ((GameObject)Instantiate(miniCard, new Vector2(cardOpenRectancle[6].position.x + openedCards[Client.playerPosition].Count * 0.25f,
                                                                                       cardOpenRectancle[6].position.y), Quaternion.identity)).GetComponent <miniCard>();
            miniCardInstance.cardIndex = selectedCards[i].cardIndex;
            miniCardInstance.showFace();
            openedCards[Client.playerPosition].Add(miniCardInstance);
        }

        string openedData = "";

        //Clear selected cards
        foreach (card card in selectedCards)
        {
            openedData += card.cardIndex.ToString() + "|";
            myDeck.Remove(card.cardIndex);
            myDeckObjects.Remove(card);
            Destroy(card.gameObject);
        }
        selectedCards.Clear();

        deckArranger(Client.playerPosition);

        openedBefore = true;
        openedArranger(Client.playerPosition);

        client.Send("COPNC|" + openedData);
    }
コード例 #2
0
 void sortCardList(List <miniCard> cardList)
 {
     for (int i = 0; i < cardList.Count - 1; i++)
     {
         for (int j = 0; j < cardList.Count - i - 1; j++)
         {
             if (cardList[j + 1].cardIndex < cardList[j].cardIndex)
             {
                 miniCard tempCard = cardList[j];
                 cardList[j]     = cardList[j + 1];
                 cardList[j + 1] = tempCard;
             }
         }
     }
 }
コード例 #3
0
    public void openedArranger(int playerPosition)
    {
        sortCardList(openedCards[playerPosition]);

        int counter_x = 0, counter_y = 0;

        for (int i = 0; i < openedCards[playerPosition].Count; i++)
        {
            miniCard card = openedCards[playerPosition][i];

            int startPoint = 0;

            if (playerPosition == Client.playerPosition)
            {
                startPoint = 6;
            }
            else if (playerPosition == Client.playerPosition % 4 + 1)
            {
                startPoint = 4;
            }
            else if (playerPosition == (Client.playerPosition + 1) % 4 + 1)
            {
                startPoint = 0;
            }
            else
            {
                startPoint = 2;
            }

            card.transform.position = new Vector2(cardOpenRectancle[startPoint].position.x + counter_x * 0.25f,
                                                  cardOpenRectancle[startPoint].position.y - counter_y * 0.5f);
            counter_x++;

            if (i != openedCards[playerPosition].Count - 1 && (
                    card.cardIndex != openedCards[playerPosition][i + 1].cardIndex - 1) || (card.cardIndex + 1) % 13 == 0)
            {
                counter_x++;
            }

            if (counter_x * 0.25f > cardOpenRectancle[startPoint + 1].position.x)
            {
                counter_y++;
                counter_x = 0;
            }
        }
    }
コード例 #4
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;
        }
    }