private void BuildConnection(int objectId, CardColor color, Player player) { var connection = MapConnections.Single(c => c.Connection.Id == objectId); List <Card> cards; if (connection.Connection.IsTunnel) { int nesessaryAdditionalCards = 0; for (int i = 0; i < 3; i++) { var card = Deck.Dequeue(); if (card.Color == color) { nesessaryAdditionalCards++; } } cards = player.BuildTunnel(color, connection.Connection.Length + nesessaryAdditionalCards); if (cards != null) { Players.Single(p => p.Color == player.Color).Cards.RemoveAll(pc => cards.Select(c => c.Id).ToList().Contains(pc.Id)); } return; } cards = player.BuildTunnel(color, connection.Connection.Length); Players.Single(p => p.Color == player.Color).Cards.RemoveAll(pc => cards.Select(c => c.Id).ToList().Contains(pc.Id)); }
private void BuildConnection(Player player) { MapConnection selectedConnection; while (true) { var selectedConnectionId = player.SelectConnection(); selectedConnection = MapConnections.Single(c => c.Connection.Id == selectedConnectionId); if (selectedConnection.IsFree) { break; } } BuildSet buildSet = new BuildSet(); buildSet.Color = selectedConnection.Connection.Color == (int)CardColor.Common ? player.SelectColor() : (CardColor)selectedConnection.Connection.Color; buildSet.JokersToBuild = selectedConnection.Connection.JokersRequired.GetValueOrDefault(0); buildSet.WagonsCost = selectedConnection.Connection.Length; if (selectedConnection.Connection.IsTunnel) { var tunnelCards = new List <Card>(); for (int i = 0; i < 3; i++) { var card = Deck.Dequeue(); tunnelCards.Add(card); UsedCards.Add(card); } var toAddCards = tunnelCards.Count(c => c.Color == buildSet.Color || c.Color == CardColor.Joker); buildSet.TunnelCost = toAddCards; } var cardsToBuild = player.GetCardsToBuild(buildSet); if (cardsToBuild == null) { ProvideCards(player); return; } UsedCards.AddRange(cardsToBuild); player.Cards.RemoveAll(c => cardsToBuild.Contains(c)); MapConnections.Single(c => c.Connection.Id == selectedConnection.Connection.Id).Owner = player; }