コード例 #1
0
ファイル: Client.cs プロジェクト: connellyj/card-games
 private void HandleTrump(TrumpMessage trumpMessage)
 {
     if (trumpMessage.TrumpSuit == string.Empty)
     {
         ViewController.Instance.UpdateLog(trumpMessage.ChoosingPlayer, "Choosing trump...");
         if (trumpMessage.ChoosingPlayer == PlayerName)
         {
             ViewController.Instance.ShowTrumpWindow(true);
             if (trumpMessage.ExtraOptions != null)
             {
                 ViewController.Instance.UpdateExtraTrumpOptions(trumpMessage.ExtraOptions);
             }
             if (trumpMessage.UnavailableOptions != null)
             {
                 ViewController.Instance.UpdateDisabledTrumpOptions(trumpMessage.UnavailableOptions);
             }
         }
     }
     else
     {
         string trumpOption = SuitUnicodeMap.ContainsKey(trumpMessage.TrumpSuit) ? SuitUnicodeMap[trumpMessage.TrumpSuit] : trumpMessage.TrumpSuit;
         ViewController.Instance.UpdateTrumpInfo(trumpOption);
         ViewController.Instance.UpdateLog(trumpMessage.ChoosingPlayer, "Trump is: " + trumpOption);
     }
 }
コード例 #2
0
ファイル: GamesManager.cs プロジェクト: connellyj/card-games
 /// <summary>
 /// Get messages to send in response to a TrumpMessage
 /// </summary>
 /// <param name="playerId"> The uid of the player </param>
 /// <param name="trumpMessage"></param>
 /// <returns> List of messages to be sent </returns>
 public MessagePackets HandleTrump(string playerId, TrumpMessage trumpMessage)
 {
     lock (this)
     {
         GameManager gm = GetGameManager(playerId);
         return(Do(gm, () => gm.HandleTrump(trumpMessage)));
     }
 }
コード例 #3
0
        /// <summary>
        /// Handle a TrumpMessage.
        /// </summary>
        /// <param name="trumpMessage"></param>
        /// <returns> List of messages to be sent </returns>
        public override MessagePackets HandleTrump(TrumpMessage trumpMessage)
        {
            MessagePackets messages = new MessagePackets();

            // Broadcast to all players
            messages.Add(GetBroadcastMessage(trumpMessage));

            // Set trump suit
            ((PinochleTrickDecider)GetDecider()).Trump = trumpMessage.TrumpSuit;

            // Initiate meld round
            messages.Add(StartMeld(trumpMessage.TrumpSuit));

            return(messages);
        }
コード例 #4
0
        /// <summary>
        /// Handle a TrumpMessage.
        /// </summary>
        /// <param name="trumpMessage"></param>
        /// <returns> List of messages to be sent </returns>
        public override MessagePackets HandleTrump(TrumpMessage trumpMessage)
        {
            MessagePackets messages = new MessagePackets();

            // Broadcast to all players
            messages.Add(GetBroadcastMessage(trumpMessage));

            // Save trump and update player model
            ((TrumpDecider)GetDecider()).Trump = trumpMessage.TrumpSuit;
            Player choosingPlayer = GetPlayersMutable().Where(p => p.Name == trumpMessage.ChoosingPlayer).Single();

            choosingPlayer.TrumpUsed.Add(trumpMessage.TrumpSuit);

            // Send out cards and start first trick
            messages.Add(GetStartMessages());
            messages.Add(GetTrickInfoMessage());
            messages.Add(StartTrick(GetDealerIndex()));
            return(messages);
        }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: connellyj/card-games
 /// <summary>
 /// Handle a TrumpMessage. By default, do nothing.
 /// Subclasses should override to enable different behaviors.
 /// </summary>
 /// <param name="trumpMessage"></param>
 /// <returns> List of messages to be sent </returns>
 public virtual MessagePackets HandleTrump(TrumpMessage trumpMessage)
 {
     throw GetNotSupportedException("TrumpMessage");
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: connellyj/card-games
    private void HandleMessage(string message)
    {
        try
        {
            lock (MessageTasks)
            {
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(message);
                if (errorResponse.IsValid())
                {
                    Debug.Log("ErrorResponse: " + errorResponse.ErrorMessage);
                    return;
                }

                DisconnectMessage disconnectMessage = JsonConvert.DeserializeObject <DisconnectMessage>(message);
                if (disconnectMessage.IsValid())
                {
                    HandleDisconnect(disconnectMessage);
                    return;
                }

                RestartMessage restartMessage = JsonConvert.DeserializeObject <RestartMessage>(message);
                if (restartMessage.IsValid())
                {
                    HandleRestart(restartMessage);
                    return;
                }

                GameTypeMessage gameTypeMessage = JsonConvert.DeserializeObject <GameTypeMessage>(message);
                if (gameTypeMessage.IsValid())
                {
                    ViewController.Instance.UpdateGameTypes(gameTypeMessage.GameTypes);
                    return;
                }

                JoinResponse joinResponse = JsonConvert.DeserializeObject <JoinResponse>(message);
                if (joinResponse.IsValid())
                {
                    HandleJoinResponse(joinResponse);
                    return;
                }

                AvailableGamesMessage gamesMessage = JsonConvert.DeserializeObject <AvailableGamesMessage>(message);
                if (gamesMessage.IsValid())
                {
                    ViewController.Instance.UpdateAvailableGames(gamesMessage.AvailableGames);
                    return;
                }

                JoinMessage joinMessage = JsonConvert.DeserializeObject <JoinMessage>(message);
                if (joinMessage.IsValid())
                {
                    HandleJoin(joinMessage);
                    return;
                }

                StartMessage startMessage = JsonConvert.DeserializeObject <StartMessage>(message);
                if (startMessage.IsValid())
                {
                    HandleStart(startMessage);
                    return;
                }

                BidMessage bidMessage = JsonConvert.DeserializeObject <BidMessage>(message);
                if (bidMessage.IsValid())
                {
                    HandleBid(bidMessage);
                    return;
                }

                KittyMessage kittyMessage = JsonConvert.DeserializeObject <KittyMessage>(message);
                if (kittyMessage.IsValid())
                {
                    HandleKitty(kittyMessage);
                    return;
                }

                TrumpMessage trumpMessage = JsonConvert.DeserializeObject <TrumpMessage>(message);
                if (trumpMessage.IsValid())
                {
                    HandleTrump(trumpMessage);
                    return;
                }

                MeldPointsMessage meldPointsMessage = JsonConvert.DeserializeObject <MeldPointsMessage>(message);
                if (meldPointsMessage.IsValid())
                {
                    HandleMeldPoints(meldPointsMessage);
                    return;
                }

                MeldMessage meldMessage = JsonConvert.DeserializeObject <MeldMessage>(message);
                if (meldMessage.IsValid())
                {
                    HandleMeld(meldMessage);
                    return;
                }

                PassMessage passMessage = JsonConvert.DeserializeObject <PassMessage>(message);
                if (passMessage.IsValid())
                {
                    HandlePass(passMessage);
                    return;
                }

                ScoreMessage scoreMessage = JsonConvert.DeserializeObject <ScoreMessage>(message);
                if (scoreMessage.IsValid())
                {
                    HandleScore(scoreMessage);
                    return;
                }

                TurnMessage turnMessage = JsonConvert.DeserializeObject <TurnMessage>(message);
                if (turnMessage.IsValid())
                {
                    HandleTurn(turnMessage);
                    return;
                }

                TrickMessage trickMessage = JsonConvert.DeserializeObject <TrickMessage>(message);
                if (trickMessage.IsValid())
                {
                    HandleTrick(trickMessage);
                    return;
                }

                TrickInfoMessage trickInfoMessage = JsonConvert.DeserializeObject <TrickInfoMessage>(message);
                if (trickInfoMessage.IsValid())
                {
                    HandleTrickInfo(trickInfoMessage);
                    return;
                }

                GameOverMessage gameOverMessage = JsonConvert.DeserializeObject <GameOverMessage>(message);
                if (gameOverMessage.IsValid())
                {
                    HandleGameOver(gameOverMessage);
                    return;
                }
            }
        }
        catch (Exception err)
        {
            Debug.Log("OnMessage error: " + err.Message);
            Debug.Log("OnMessage stack trace: " + err.StackTrace);
        }
    }
コード例 #7
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());
            }