/// <summary> /// Get messages to send in response to a KittyMessage /// </summary> /// <param name="playerId"> The uid of the player </param> /// <param name="kittyMessage"></param> /// <returns> List of messages to be sent </returns> public MessagePackets HandleKitty(string playerId, KittyMessage kittyMessage) { lock (this) { GameManager gm = GetGameManager(playerId); return(Do(gm, () => gm.HandleKitty(kittyMessage))); } }
private void HandleKitty(KittyMessage kittyMessage) { ViewController.Instance.ShowCardsInKitty(kittyMessage.Kitty); ViewController.Instance.UpdateLog(kittyMessage.ChoosingPlayer, string.Format("Choosing {0} cards to discard...", kittyMessage.Kitty.Length)); if (kittyMessage.ChoosingPlayer == PlayerName) { ViewController.Instance.EnableDiscardCardsInKitty(kittyMessage.Kitty.Length); } else { ViewController.Instance.EnableClearCardsInKitty(); } }
/// <summary> /// Handle a KittyMessage /// </summary> /// <param name="kittyMessage"></param> /// <returns> List of messages to be sent </returns> public override MessagePackets HandleKitty(KittyMessage kittyMessage) { // Update player model Player player = GetCurrentPlayer(); player.Cards.AddRange(Kitty); foreach (Card c in kittyMessage.Kitty) { player.Cards.Remove(c); if (PinochleTrickDecider.IsPoint(c)) { player.SecretScore++; } } // Initiate trump round return(StartTrump(GetCurrentPlayerIndex())); }
/// <summary> /// Handle a KittyMessage. By default, do nothing. /// Subclasses should override to enable different behaviors. /// </summary> /// <param name="kittyMessage"></param> /// <returns> List of messages to be sent </returns> public virtual MessagePackets HandleKitty(KittyMessage kittyMessage) { throw GetNotSupportedException("KittyMessage"); }
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); } }
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()); }