コード例 #1
0
ファイル: Game.xaml.cs プロジェクト: lunglunglee/New
        void GamePlay_OpponentPlayed(object sender, OpponentPlayedEventArgs e)
        {
            // We received notification that the opponent has chosen a gamepiece (rock, paper, scissors)
            // The event argument contains the piece the opponent chose.
            _opponentsChoice = e.gamepiece;

            // If I have already chosen, then we are ready to see who won
            if (!String.IsNullOrWhiteSpace(_myChoice))
            {
                // Color the opponent's gamepiece
                SelectGamePiece(OpponentGamePieces, _opponentsChoice);
                DetermineWinner();
            }
        }
コード例 #2
0
ファイル: GamePlay.cs プロジェクト: lunglunglee/New
        /// <summary>
        /// Handles the PacketReceived event of the Channel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SilverlightPlayground.UDPMulticast.UdpPacketReceivedEventArgs"/> instance containing the event data.</param>
        void Channel_PacketReceived(object sender, UdpPacketReceivedEventArgs e)
        {
            string message = e.Message.Trim('\0');

            string[] messageParts = message.Split(GameCommands.CommandDelimeter.ToCharArray());

            if (messageParts.Length == 2)
            {
                switch (messageParts[0])
                {
                case GameCommands.Join:
                    OnPlayerJoined(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.AcceptChallenge:
                    OnChallengeAccepted(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.Challenge:
                    OnChallengeReceived(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.NewGame:
                    OnNewGame(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.Leave:
                    OnPlayerLeft(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.LeaveGame:
                    OnLeaveGame(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.RejectChallenge:
                    OnChallengeRejected(new PlayerInfo(messageParts[1], e.Source));
                    break;

                case GameCommands.Ready:
                    Debug.WriteLine("Ready received");
                    break;

                default:
                    break;
                }
            }
            else if (messageParts.Length == 3 && messageParts[0] == GameCommands.Play)
            {
                OpponentPlayedEventArgs args = new OpponentPlayedEventArgs();
                args.gamepiece  = messageParts[2];
                args.playerInfo = new PlayerInfo(messageParts[1], e.Source);
                if (OpponentPlayed != null)
                {
                    OpponentPlayed(this, args);
                }
            }
            else
            {
                // Ignore messages that don't have the expected number of parts.
            }
        }