Example #1
0
 public void NetworkCardObject()
 {
     var networkObj = new NetworkCardObject(ServerCommands.AnnounceCard, new CardBallotNo(), new CardBallotYes(), new CardPolicyVeto(), new CardPolicyLiberal());
     var decoder = new NetworkCardObject.CardObjectReader();
     var bytes = decoder.GenerateByteStream(networkObj);
     var generatedObj = decoder.GenerateObject(bytes, false);
     Assert.IsInstanceOfType(generatedObj, typeof(NetworkCardObject));
     var generatedCardObj = generatedObj as NetworkCardObject;
     Assert.IsTrue(generatedCardObj.Cards.Length == networkObj.Cards.Length);
     for(var i = 0; i < generatedCardObj.Cards.Length; i++)
         Assert.AreSame(generatedCardObj.Cards[i].GetType(), networkObj.Cards[i].GetType());
     CompareDefaultObject(networkObj, generatedCardObj);
 }
        static DecodeNetworkObjects()
        {
            var messageDecoder = new NetworkMessageObject.MessageObjectReader();
            var boolDecoder = new NetworkBoolObject.BoolObjectReader();
            var newPlayerDecoder = new NetworkNewPlayerObject.NewPlayerObjectReader();
            var cardDecoder = new NetworkCardObject.CardObjectReader();
            var playerDecoder = new NetworkPlayerObject.PlayerObjectReader();
            var byteDecoder = new NetworkByteObject.ByteObjectDecoder();
            RegisterDecoder(Message, messageDecoder);
            RegisterDecoder(ReceiveMessage, messageDecoder);
            RegisterDecoder(PlayerConnected, newPlayerDecoder);
            RegisterDecoder(PlayerDisconnected, newPlayerDecoder);
            RegisterDecoder(AnnounceCard, cardDecoder);
            RegisterDecoder(SendGameState, new NetworkGameStateObject.GameStateObjectReader());
            RegisterDecoder(RevealRole, new NetworkRevealRoleObject.RevealRoleObjectReader());
            RegisterDecoder(Multiple, new NetworkMultipleObject.MultipleObjectReader());
            RegisterDecoder(AnnouncePresident, playerDecoder);
            RegisterDecoder(AnnounceChancellor, playerDecoder);
            RegisterDecoder(CastVote, boolDecoder);
            RegisterDecoder(PlayerVoted, playerDecoder);
            RegisterDecoder(AnnounceVotes, new NetworkVoteResultObject.VoteResultObjectDecoder());
            RegisterDecoder(PolicyCardsDrawn, byteDecoder);
            RegisterDecoder(PresidentPickPolicyCard, cardDecoder);
            RegisterDecoder(ChancellorPickPolicyCard, cardDecoder);
            RegisterDecoder(PresidentPolicyCardPicked, byteDecoder);
            RegisterDecoder(ChancellorPolicyCardPicked, byteDecoder);
            RegisterDecoder(CardPlayed, cardDecoder);
            RegisterDecoder(RevealMembership, newPlayerDecoder);
            RegisterDecoder(KillPlayer, playerDecoder);
            RegisterDecoder(NotHitler, playerDecoder);
            RegisterDecoder(PresidentRequestVetoAllowed, boolDecoder);
            RegisterDecoder(AnnounceVetoResult, boolDecoder);

            RegisterDecoder(PresidentAction, byteDecoder);
            RegisterDecoder(PresidentDoingAction, playerDecoder);

            RegisterDecoder(PresidentActionExamine, cardDecoder);
            //Other Actions are plain objects

            //Examine object is a plain object notifying the server the player is done
            RegisterDecoder(PresidentActionKillResponse, playerDecoder);
            RegisterDecoder(PresidentActionChoosePresidentResponse, playerDecoder);
            RegisterDecoder(PresidentActionInvestigatePresidentResponse, playerDecoder);
        }