private bool HandleCard(LobbyCard command, Client client) { if (client.Info.Id != Lobby.Info.Clients[Turn].Id) { return(false); } CardInfo cardToRemove = null; foreach (var card in client.Info.Deck) { if (card.ColorId == command.Info.ColorId && card.FaceId == command.Info.FaceId) { cardToRemove = card; } } if (cardToRemove == null) { return(false); } Lobby.Broadcast(client.Info.Name + " played a " + command.Info.Face.Name + " of " + command.Info.Color.Name + "."); Table[client.Info] = cardToRemove; client.Info.Deck.Remove(cardToRemove); DisplayTable(); NextTurn(); return(true); }
public bool Run(NetworkStream stream, string input) { var args = Regex.Split(input, @"\s+"); var proto = new LobbyCard { Info = new CardInfo() }; if (args.Length < 2) { proto.Info.Face = null; proto.Info.Color = null; } else { proto.Info.FaceId = (CardFace.EFace)Convert.ToInt32(args[0]); proto.Info.ColorId = (CardColor.EColor)Convert.ToInt32(args[1]); } stream.Write(proto.ProtobufTypeAsBytes, 0, 2); ProtoBuf.Serializer.SerializeWithLengthPrefix(stream, proto, ProtoBuf.PrefixStyle.Fixed32); return(true); }
public bool Run(NetworkStream stream, string input) { var args = Regex.Split(input, @"\s+"); if (args.Length < 3 || args[1].Length <= 0 || args[2].Length <= 0) { return(false); } var proto = new LobbyCard { Info = new CardInfo { Face = CardFace.From(args[1].ToLower()), Color = CardColor.From(args[2].ToLower()) } }; stream.Write(proto.ProtobufTypeAsBytes, 0, 2); ProtoBuf.Serializer.SerializeWithLengthPrefix(stream, proto, ProtoBuf.PrefixStyle.Fixed32); return(true); }