private static UpdateTableMessage ProvidePlayerNewCards(string clientId, List <int> cardsToRemove, bool dicrease = false) { var client = AbstractPlayers.First(pl => pl.Id == clientId); if (cardsToRemove.Count >= 0) { foreach (var i in cardsToRemove) { client.Hand.RemoveAll(c => c.Id == i); } } int additionalCardsCount = dicrease ? cardsToRemove.Count - 1 : cardsToRemove.Count; for (int i = 0; i < additionalCardsCount; i++) { if (HandCards.Count <= 0) { break; } client.Hand.Add(HandCards.Dequeue() as HandCard); } var updateMessage = new UpdateTableMessage(); updateMessage.Hand = client.Hand; updateMessage.IsBroadcast = false; updateMessage.IsMyTurn = false; updateMessage.CardsLeftInDeck = HandCards.Count; return(updateMessage); }
protected internal void LaunchGame() { if (!_clients.All(c => c.IsReady) || _clients.Count != 2) { return; } Console.WriteLine("All players are ready, let's start!"); var launcher = new Launcher(_clients.Select(c => c.Id).ToList()); launcher.ProvideRolesForPlayers(); launcher.ProvideHandCardsForPlayers(); foreach (var client in _clients) { var player = launcher.Players.First(pl => pl.Id == client.Id); var gameMessage = new UpdateTableMessage(); gameMessage.IsBroadcast = false; gameMessage.RoleCard = player.Role; gameMessage.Hand = player.Hand; gameMessage.IsMyTurn = player.Role.Role == RoleType.Green; SendMessage(gameMessage, client.Id); var initializeTableMessage = new InitializeTableMessage(); initializeTableMessage.GoldCards = launcher.GoldCardsForGame; initializeTableMessage.StartCards = launcher.StartCards; initializeTableMessage.Players = Table.Players; SendMessage(initializeTableMessage, client.Id); } MessageManager.Players.Enqueue(_clients.First(c => c.Id != launcher.Players.First(pl => pl.Role.Role == RoleType.Green).Id)); MessageManager.Players.Enqueue(_clients.First(c => c.Id == launcher.Players.First(pl => pl.Role.Role == RoleType.Green).Id)); MessageManager.AbstractPlayers = launcher.Players; MessageManager.HandCards = launcher.ShuffledHandCards; }
private void UpdateTable(UpdateTableMessage obj) { if (_viewIsAppeared) { var itemIndex = ViewModel.FavoriteNews.IndexOf(obj.News); _tableView.BeginUpdates(); _tableView.ReloadRows(new NSIndexPath[] { NSIndexPath.FromRowSection(itemIndex, 0) }, UITableViewRowAnimation.Automatic); _tableView.EndUpdates(); } }
private void HandleUpdateTableMessage(UpdateTableMessage message) { MyHand.UpdateCards(message.Hand); CardsInDeck = message.CardsLeftInDeck; OnPropertyChanged(nameof(CardsInDeck)); _isMyTurn = message.IsMyTurn; if (message.RoleCard != null) { CurrentPlayer.Role = message.RoleCard; RoleImage = message.RoleCard.ImagePath; OnPropertyChanged(nameof(RoleImage)); } }