예제 #1
0
        public CompState CompressState()
        {
            CompState sendState = new CompState {
                P1             = instance.playerOne.IdUser,
                P2             = instance.playerTwo.IdUser,
                P1Lp           = instance.playerOneLifePoints,
                P2Lp           = instance.playerTwoLifePoints,
                PlayerCrystals = instance.playerCrystals,
                PlayerGems     = instance.playerGems,
                GoesFirst      = instance.firstMovePl,
                OnMove         = instance.plOnMove,
                P1Hand         = new List <int>(),
                P2Hand         = new List <int>(),
                P1Table        = new List <CompCard>(),
                P2Table        = new List <CompCard>(),
            };

            foreach (Card card in instance.playerOneHand)
            {
                sendState.P1Hand.Add(card.IdCard);
            }
            foreach (Card card in instance.playerTwoHand)
            {
                sendState.P2Hand.Add(card.IdCard);
            }
            foreach (Card card in instance.playerOneTable)
            {
                sendState.P1Table.Add(new CompCard(card.IdCard, card.Name, card.Attack, card.Health, card.Shield));
            }
            foreach (Card card in instance.playerTwoTable)
            {
                sendState.P2Table.Add(new CompCard(card.IdCard, card.Name, card.Attack, card.Health, card.Shield));
            }
            return(sendState);
        }
예제 #2
0
        public void UncompressState(CompState state, Dictionary <int, Card> myDeck, Dictionary <int, Card> oponentDeck, User me, User oponent)
        {
            this.playerOneLifePoints = state.P1Lp;
            this.playerTwoLifePoints = state.P2Lp;
            this.playerCrystals      = state.PlayerCrystals;
            this.playerGems          = state.PlayerGems;
            this.firstMovePl         = state.GoesFirst;
            this.plOnMove            = state.OnMove;

            if (state.P1 == me.IdUser)
            {
                this.PlayerOne = me;
                foreach (int cardId in state.P1Hand)
                {
                    Card value;
                    myDeck.TryGetValue(cardId, out value);
                    instance.playerOneHand.Add(value);
                }
                this.PlayerTwo = oponent;
                foreach (CompCard card in state.P1Table)
                {
                    Card value;
                    myDeck.TryGetValue(card.IdCard, out value);
                    value.Attack = card.Attack;
                    value.Health = card.Health;
                    value.Shield = card.Shield;
                    instance.playerOneHand.Add(value);
                }
                foreach (CompCard card in state.P2Table)
                {
                    Card value;
                    oponentDeck.TryGetValue(card.IdCard, out value);
                    value.Attack = card.Attack;
                    value.Health = card.Health;
                    value.Shield = card.Shield;
                    instance.playerTwoHand.Add(value);
                }
            }
            else
            {
                this.PlayerTwo = me;
                foreach (int cardId in state.P2Hand)
                {
                    Card value;
                    myDeck.TryGetValue(cardId, out value);
                    instance.playerTwoHand.Add(value);
                }
                this.PlayerOne = oponent;
                foreach (CompCard card in state.P1Table)
                {
                    Card value;
                    oponentDeck.TryGetValue(card.IdCard, out value);
                    value.Attack = card.Attack;
                    value.Health = card.Health;
                    value.Shield = card.Shield;
                    instance.playerOneHand.Add(value);
                }
                foreach (CompCard card in state.P2Table)
                {
                    Card value;
                    myDeck.TryGetValue(card.IdCard, out value);
                    value.Attack = card.Attack;
                    value.Health = card.Health;
                    value.Shield = card.Shield;
                    instance.playerTwoHand.Add(value);
                }
            }
        }