示例#1
0
        public void TestHandleGameTypes(string chosenGame, params Type[] messageTypes)
        {
            // TODO: check values in messages
            // TODO: check game state afterwards (need to expose static game state info)
            string          uid = "uid";
            GameTypeMessage gt  = new GameTypeMessage()
            {
                ChosenGame = chosenGame
            };

            if (messageTypes.Length > 0)
            {
                MessagePackets messages = GamesManager.Get().HandleGameTypes(uid, gt);

                Assert.IsTrue(Utils.VerifyMessagePackets(messages, messageTypes));

                foreach (MessagePacket m in messages.Messages)
                {
                    Assert.AreEqual(m.SendTo.Count(), 1);
                    Assert.AreEqual(m.SendTo.Single(), uid);
                }
            }
            else
            {
                Assert.ThrowsException <Exception>(() => GamesManager.Get().HandleGameTypes(uid, gt));
            }
        }
示例#2
0
        public void TestHandleNewConnection()
        {
            string         uid      = "uid";
            MessagePackets messages = GamesManager.Get().HandleNewConnection(uid);

            Assert.IsTrue(Utils.VerifyMessagePackets(messages, typeof(GameTypeMessage)));

            Assert.AreEqual(messages.Messages[0].SendTo.Count(), 1);
            Assert.AreEqual(messages.Messages[0].SendTo.Single(), uid);

            GameTypeMessage gt = (GameTypeMessage)messages.Messages[0].Message;

            CollectionAssert.AreEqual(gt.GameTypes, new string[3] {
                "Hearts", "Mizerka", "Pinochle"
            });
            Assert.AreEqual(gt.ChosenGame, null);
        }
示例#3
0
 protected override void OnOpen()
 {
     SendDo(() => GamesManager.Get().HandleNewConnection(ID));
 }
示例#4
0
 protected override void OnClose(CloseEventArgs e)
 {
     SendDo(() => GamesManager.Get().HandlePlayerDisconnect(ID));
 }
示例#5
0
            private MessagePackets HandleMessage(string message)
            {
                RestartMessage restartMessage = JsonConvert.DeserializeObject <RestartMessage>(message);

                if (restartMessage.IsValid())
                {
                    return(GamesManager.Get().HandleRestart(ID, restartMessage));
                }

                GameTypeMessage gameTypeMessage = JsonConvert.DeserializeObject <GameTypeMessage>(message);

                if (gameTypeMessage.IsValid())
                {
                    return(GamesManager.Get().HandleGameTypes(ID, gameTypeMessage));
                }

                JoinMessage joinMessage = JsonConvert.DeserializeObject <JoinMessage>(message);

                if (joinMessage.IsValid())
                {
                    return(GamesManager.Get().HandleJoin(ID, joinMessage));
                }

                BidMessage bidMessage = JsonConvert.DeserializeObject <BidMessage>(message);

                if (bidMessage.IsValid())
                {
                    return(GamesManager.Get().HandleBid(ID, bidMessage));
                }

                KittyMessage kittyMessage = JsonConvert.DeserializeObject <KittyMessage>(message);

                if (kittyMessage.IsValid())
                {
                    return(GamesManager.Get().HandleKitty(ID, kittyMessage));
                }

                TrumpMessage trumpMessage = JsonConvert.DeserializeObject <TrumpMessage>(message);

                if (trumpMessage.IsValid())
                {
                    return(GamesManager.Get().HandleTrump(ID, trumpMessage));
                }

                MeldMessage meldMessage = JsonConvert.DeserializeObject <MeldMessage>(message);

                if (meldMessage.IsValid())
                {
                    return(GamesManager.Get().HandleMeld(ID, meldMessage));
                }

                PassMessage passMessage = JsonConvert.DeserializeObject <PassMessage>(message);

                if (passMessage.IsValid())
                {
                    return(GamesManager.Get().HandlePass(ID, passMessage));
                }

                TurnMessage turnMessage = JsonConvert.DeserializeObject <TurnMessage>(message);

                if (turnMessage.IsValid())
                {
                    return(GamesManager.Get().HandleTurn(ID, turnMessage));
                }

                return(new MessagePackets());
            }