コード例 #1
0
    void OnEvent(byte eventcode, object content, int senderid)
    {
        switch (eventcode)
        {
        case EventCodes.B_ALL_PLAYERS_READY:
        {
            Assert.IsNull(content);
            AllPlayersReady();
        }
        break;

        case EventCodes.B_FIRST_PLAYER:
        {
            Assert.IsTrue(content.GetType() == typeof(int));
            NotifyFirstPlayer((int)content);
        }
        break;

        case EventCodes.B_CURRENT_PLAYER:
        {
            Assert.IsTrue(content.GetType() == typeof(int));
            NotifyCurrentPlayer((int)content);
        }
        break;

        case EventCodes.A_BEGIN_TURN_DRAW_CARDS:
        {
            Assert.IsTrue(content.GetType() == typeof(string));
            Card[] cardsToChoose = MyJson.FromJson <Card>((string)content);

            turnController.ShowCardSelector(cardsToChoose);
        }
        break;

        case EventCodes.A_FIRST_HAND:
        {
            Assert.IsTrue(content.GetType() == typeof(string));
            Card[] cardsToAdd = MyJson.FromJson <Card>((string)content);

            handController.UpdatePlayerCards(cardsToAdd);
        }
        break;

        case EventCodes.N_HAND_STATUS:
        {
            Assert.IsTrue(content.GetType() == typeof(int[]));
            Assert.IsTrue(((int[])content).Length == 2);

            int sender = ((int[])content)[0];
            Assert.IsTrue(sender != PhotonNetwork.player.ID);

            int totalCards = ((int[])content)[1];
            handController.UpdateEnemyCards(totalCards);
        }
        break;

        case EventCodes.A_BEGIN_TURN_PICK_CARD:
        {
            Assert.IsTrue(content.GetType() == typeof(string));
            Card card = JsonUtility.FromJson <Card>((string)content);

            turnController.CloseCardSelector();
            handController.UpdatePlayerCards(new Card[] { card });
        }
        break;

        case EventCodes.A_PLAY_CARD:
        {
            Assert.IsTrue(content.GetType() == typeof(object[]));
            Assert.IsTrue(((object[])content).Length == 5);

            int    playerId       = (int)((object[])content)[0];
            int    response       = (int)((object[])content)[1];
            string cardId         = (string)((object[])content)[2];
            int    positionInHand = (int)((object[])content)[3];
            int    squarePosition = (int)((object[])content)[4];

            ConfirmPlayCardFromHand(playerId, response, cardId, positionInHand, squarePosition);
        }
        break;
        }
    }