Exemple #1
0
        public DealManager(GameManager game)
        {
            this.game = game;

            this.cardDeck = new Queue <Card>(CardsCollection.FullDeckOfCards);

            this.playerCards = new[] { new Hand(), new Hand(), new Hand(), new Hand() }; // 4 players

            this.southNorthPlayersCardsTaken = new CardsCollection();
            this.eastWestPlayersCardsTaken   = new CardsCollection();

            this.southNorthBelotes = 0;
            this.eastWestBelotes   = 0;

            this.southNorthTeamTakesLastHand = null;
        }
Exemple #2
0
        private PlayAction PlayCard(IPlayer player, Contract contract, IList <Card> currentTrickCards)
        {
            // Prepare played cards and allowed cards
            var currentPlayerCards = this.playerCards[(int)this.game[player]];
            var allowedCards       = new CardsCollection(currentPlayerCards.GetAllowedCards(contract, currentTrickCards));

            // Play card
            var playAction = player.PlayCard(allowedCards.ToList(), currentTrickCards.ToList());

            // Check for invalid card
            if (!allowedCards.Contains(playAction.Card))
            {
                throw new InvalidPlayerActionException(player, string.Format("Invalid card: {0}", playAction.Card));
            }

            // Save belote to team points
            playAction.Belote = false;
            if (playAction.AnnounceBeloteIfAvailable && currentPlayerCards.IsBeloteAllowed(contract, currentTrickCards, playAction.Card))
            {
                switch (this.game[player])
                {
                case PlayerPosition.South:
                    this.southNorthBelotes++;
                    break;

                case PlayerPosition.East:
                    this.eastWestBelotes++;
                    break;

                case PlayerPosition.North:
                    this.southNorthBelotes++;
                    break;

                case PlayerPosition.West:
                    this.eastWestBelotes++;
                    break;
                }

                playAction.Belote = true;
            }

            // Remove played card from the players cards
            this.playerCards[(int)this.game[player]].Remove(playAction.Card);
            return(playAction);
        }
 static CardsCollection()
 {
     FullDeckOfCards = new CardsCollection
     {
         new Card(CardType.Seven, CardSuit.Clubs),
         new Card(CardType.Seven, CardSuit.Diamonds),
         new Card(CardType.Seven, CardSuit.Hearts),
         new Card(CardType.Seven, CardSuit.Spades),
         new Card(CardType.Eight, CardSuit.Clubs),
         new Card(CardType.Eight, CardSuit.Diamonds),
         new Card(CardType.Eight, CardSuit.Hearts),
         new Card(CardType.Eight, CardSuit.Spades),
         new Card(CardType.Nine, CardSuit.Clubs),
         new Card(CardType.Nine, CardSuit.Diamonds),
         new Card(CardType.Nine, CardSuit.Hearts),
         new Card(CardType.Nine, CardSuit.Spades),
         new Card(CardType.Ten, CardSuit.Clubs),
         new Card(CardType.Ten, CardSuit.Diamonds),
         new Card(CardType.Ten, CardSuit.Hearts),
         new Card(CardType.Ten, CardSuit.Spades),
         new Card(CardType.Jack, CardSuit.Diamonds),
         new Card(CardType.Jack, CardSuit.Hearts),
         new Card(CardType.Jack, CardSuit.Spades),
         new Card(CardType.Jack, CardSuit.Clubs),
         new Card(CardType.Queen, CardSuit.Clubs),
         new Card(CardType.Queen, CardSuit.Diamonds),
         new Card(CardType.Queen, CardSuit.Hearts),
         new Card(CardType.Queen, CardSuit.Spades),
         new Card(CardType.King, CardSuit.Clubs),
         new Card(CardType.King, CardSuit.Diamonds),
         new Card(CardType.King, CardSuit.Hearts),
         new Card(CardType.King, CardSuit.Spades),
         new Card(CardType.Ace, CardSuit.Clubs),
         new Card(CardType.Ace, CardSuit.Diamonds),
         new Card(CardType.Ace, CardSuit.Hearts),
         new Card(CardType.Ace, CardSuit.Spades)
     };
 }