Exemplo n.º 1
0
        // Called when we receive a real-time message from the network.
        // Messages in our game are made up of 2 bytes: the first one is 'F' or 'U'
        // indicating
        // whether it's a final or interim score. The second byte is the score.
        // There is also the
        // 'S' message, which indicates that the game should start.

        public void OnRealTimeMessageReceived(RealTimeMessage rtm)
        {
            byte[] buf    = rtm.GetMessageData();
            string sender = rtm.SenderParticipantId;

            Log.Debug(TAG, "Message received: " + (char)buf[0] + "/" + (int)buf[1]);

            if (buf[0] == 'F' || buf[0] == 'U')
            {
                int participantScore = 0;
                mParticipantScore.TryGetValue(sender, out participantScore);
                // score update.
                int existingScore = mParticipantScore.ContainsKey(sender) ?
                                    participantScore : 0;
                int thisScore = (int)buf[1];
                if (thisScore > existingScore)
                {
                    // this check is necessary because packets may arrive out of
                    // order, so we
                    // should only ever consider the highest score we received, as
                    // we know in our
                    // game there is no way to lose points. If there was a way to
                    // lose points,
                    // we'd have to add a "serial number" to the packet.
                    mParticipantScore[sender] = thisScore;
                }

                // update the scores on the screen
                UpdatePeerScoresDisplay();

                // if it's a final score, mark this participant as having finished
                // the game
                if ((char)buf[0] == 'F')
                {
                    mFinishedParticipants.Add(rtm.SenderParticipantId);
                }
            }
        }
Exemplo n.º 2
0
 public void OnRealTimeMessageReceived(RealTimeMessage p0)
 {
     Toast.MakeText(this, "Message Received", ToastLength.Short).Show();
     _gameFragment.ReceiveMessage(p0.GetMessageData());
 }
Exemplo n.º 3
0
 public void OnRealTimeMessageReceived(RealTimeMessage p0)
 {
     Toast.MakeText(this, "Message Received", ToastLength.Short).Show();
     _gameFragment.ReceiveMessage(p0.GetMessageData());
 }