/// <summary> /// Play card from player. /// </summary> /// <param name="host">The host.</param> /// <param name="data">Data received from client.</param> public static void PlayCard(PirateHost host, PirateMessage data) { Contract.Requires(host != null && data != null && data.Head == PirateMessageHead.Pcrd); var playerName = PirateMessage.GetPlayerName(data); var player = host.PlayerFromString(playerName); var card = Card.FromString(data.Body); if(!player.CardPlayable(card, host.Game.Round.BoardCards.FirstCard)) { ErrorMessage(host, player, PirateError.CardNotPlayable); var returnCard = new PirateMessage(PirateMessageHead.Xcrd, card.ToString()); host.SendMessage(player, returnCard); RequestCard(host, player); return; } Console.WriteLine(player.Name + " plays " + card.ToShortString()); var msg = new PirateMessage( PirateMessageHead.Pcrd, PirateMessage.ConstructBody(player.ToString(), card.ToString())); foreach(var pclient in host.GetPlayers()) { host.SendMessage(pclient, msg); } player.PlayCard(card); //host.Game.Round.PlayCard(player, card); if(!host.Game.Round.Finished) { RequestCard(host, host.PlayerFromIndex(host.Game.Round.CurrentPlayer)); }else { host.Game.NewRound(); } }