Summary description for Card.
Ejemplo n.º 1
0
        internal override int Add( Card value )
        {
            if( InnerList.Count >= 4 )

                throw new InvalidOperationException("A hand can contain maximum of 4 cards");

            int ret =  InnerList.Add( value );
            RaiseChanged();
            return ret;
        }
Ejemplo n.º 2
0
        public static Image GetCardImage( Card card )
        {
            int index = 0;

            switch ( card.CardType )
            {
                case CardType.Ace:
                    index = 0;
                    break;
                case CardType.King:
                    index = 1;
                    break;
                case CardType.Queen:
                    index = 2;
                    break;
                case CardType.Jack:
                    index = 3;
                    break;
                case CardType.Ten:
                    index = 4;
                    break;
                case CardType.Nine:
                    index = 5;
                    break;
                case CardType.Eight:
                    index = 6;
                    break;
                case CardType.Seven:
                    index = 7;
                    break;
            }

            index *= 4;

            switch ( card.CardColor )
            {
                case CardColor.Spades:
                    index += 0;
                    break;
                case CardColor.Hearts:
                    index += 1;
                    break;
                case CardColor.Diamonds:
                    index += 2;
                    break;
                case CardColor.Clubs:
                    index += 3;
                    break;
            }

            return _imageList.Images[ index ];
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Raises the CardsChanged event
 /// </summary>
 protected void RaiseCardPlayed( Card card )
 {
     if( _cardPlayed != null )
         {
             _cardPlayed( this, card );
         }
 }
Ejemplo n.º 4
0
 internal virtual void Remove( Card value )
 {
     InnerList.Remove( value );
     RaiseChanged( );
 }
Ejemplo n.º 5
0
        private int GetDistanceTrumps( Card card, Card maxCard )
        {
            int x = 0, y = 0;

            switch ( card.CardType )
            {
                case CardType.Jack:
                    x = 8;
                    break;
                case CardType.Nine:
                    x = 7;
                    break;
                case CardType.Ace:
                    x = 6;
                    break;
                case CardType.Ten:
                    x = 5;
                    break;
                case CardType.King:
                    x = 4;
                    break;
                case CardType.Queen:
                    x = 3;
                    break;
                case CardType.Eight:
                    x = 2;
                    break;
                case CardType.Seven:
                    x = 1;
                    break;
            }

            switch ( maxCard.CardType )
            {
                case CardType.Jack:
                    y = 8;
                    break;
                case CardType.Nine:
                    y = 7;
                    break;
                case CardType.Ace:
                    y = 6;
                    break;
                case CardType.Ten:
                    y = 5;
                    break;
                case CardType.King:
                    y = 4;
                    break;
                case CardType.Queen:
                    y = 3;
                    break;
                case CardType.Eight:
                    y = 2;
                    break;
                case CardType.Seven:
                    y = 1;
                    break;
            }

            return y - x;
        }
Ejemplo n.º 6
0
 private int EvalutePointsOnTrumpColor( Card targetCard )
 {
     int POINTS_TO_ADD = 10;
     if ( targetCard.CardColor == GetTrumpColor() )
     {
         return POINTS_TO_ADD;
     }
     else
     {
         return 0;
     }
 }
Ejemplo n.º 7
0
        private int EvalutePointsOnPartnerAnnounce( Card targetCard )
        {
            // 1.2
            int points = 0;
            const int POINTS_TO_ADD = 10;

            foreach ( KeyValuePair< Announcement, Player> kv in _allAnnounces )
            {
                Announcement announce = kv.Key;
                if ( announce.Type == AnnouncementTypeEnum.Spades ||
                    announce.Type == AnnouncementTypeEnum.Hearts ||
                    announce.Type == AnnouncementTypeEnum.Diamonds ||
                    announce.Type == AnnouncementTypeEnum.Clubs )
                {
                    if ( targetCard.CardColor == GetCardColor( announce.Type ) )
                    {
                        Player player = kv.Value;

                        if ( player == _playingManager.GetPartner( this ) )
                        {
                            points += POINTS_TO_ADD;
                        }

                        if ( player != this && player != _playingManager.GetPartner( this ) )
                        {
                            points -= POINTS_TO_ADD;
                        }
                    }
                }
            }

            return points;
        }
Ejemplo n.º 8
0
 private void MoveCardToTable( PlayerPosition position, Card playedCard )
 {
     switch ( position )
     {
         case PlayerPosition.South:
             _cardTableSouth.Visible = true;
             _cardTableSouth.Card = playedCard;
             break;
         case PlayerPosition.East:
             _cardTableEast.Visible = true;
             _cardTableEast.Card = playedCard;
             break;
         case PlayerPosition.North:
             _cardTableNorth.Visible = true;
             _cardTableNorth.Card = playedCard;
             break;
         case PlayerPosition.West:
             _cardTableWest.Visible = true;
             _cardTableWest.Card = playedCard;
             break;
     }
 }
Ejemplo n.º 9
0
        private void CheckBelotForValidColor( Player player, Card playedCard, CardsCollection foundCards )
        {
            foreach( Card card in player.Cards )
            {
                if( playedCard.CardColor == card.CardColor )
                {
                    if( playedCard.CardType == CardType.Queen && card.CardType == CardType.King )
                    {
                        foundCards.Add( playedCard );
                        foundCards.Add( card );
                    }

                    if(playedCard.CardType == CardType.King && card.CardType == CardType.Queen)
                    {
                        foundCards.Add( card );
                        foundCards.Add( playedCard );
                    }
                }
            }
        }
Ejemplo n.º 10
0
        internal void Add( Player player, Card card )
        {
            _cardToPlayerMap.Add( card, player );
            _currentHand.Add( card );

            _playedCards.Add( card );
            _remainingCards.Remove( card );

            CheckForBelotCombination ( player, card );

            if( _currentHand.Count < 4 ) // current hand is open
            {
                _isHandClosed = false;
            }
            else // current hand is closed
            {
                _currentHand.SetWinner( DetermineCurrentHandWinner() );
                _playedHands.Add( _currentHand );
                _currentHand = new Hand();
                _isHandClosed = true;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// If card played by this player is valid according to game rules
        /// </summary>
        public bool IsValid( Player player, Card card )
        {
            if( player == null)
                throw new ArgumentNullException( "Player", "Player cannot be null");

            if(	card == null)
                throw new ArgumentNullException( "Card", "Played card cannot be null");

            CardColor wantedColor;
            Card biggestCard;

            // if player plays first card in hand he can play any card
            if( _currentHand.IsEmpty )
            {
                return true;
            }
            else
            {
                wantedColor = GetPlayingColor( _currentHand );
                biggestCard = GetBiggestCard( _currentHand );
            }

            if( _currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps )
            {
                #region Game of all trumps
                if( card.CardColor == wantedColor )
                {
                    if( IsBigger( card, biggestCard ) )
                    {
                        // card is biggest for now in wanted color
                        return true;
                    }
                    else
                    {
                        // card is not biggest but player has no bigger one
                        return !HasBigger( biggestCard, player.Cards, wantedColor );
                    }
                }
                else if( !HasPlayingColor( wantedColor, player.Cards ) )
                {
                    // if player does not have currently wanted color he can play any card
                    return true;
                }
                #endregion
            }
            else if( _currentAnnouncement.Type == AnnouncementTypeEnum.NoTrumps )
            {
                #region Game of no trumps
                if( card.CardColor == wantedColor )
                {
                    //player may play any card in wanted color
                    return true;
                }
                else
                {
                    // player does not have currently wanted color he can play any card
                    return ( !HasPlayingColor( wantedColor, player.Cards ) );
                }
                #endregion
            }
            else
            {
                #region Game of color trumps
                CardColor trumpColor = GetTrumpColor( );

                if( card.CardColor == wantedColor )
                {
                    if( trumpColor == wantedColor )
                    {
                        if( IsBigger( card, biggestCard ) )
                        {
                            // card is biggest for now
                            return true;
                        }
                        else
                        {
                            // card is not biggest but player has no bigger one
                            return !HasBigger( biggestCard, player.Cards, wantedColor );
                        }
                    }
                    else
                    {
                        // card is not trump and may not be bigger
                        return true;
                    }
                }
                else
                {
                    if( HasPlayingColor( wantedColor, player.Cards ) )
                    {
                        // player has cards in wanted color but plays from different one
                        return false;
                    }
                    else
                    {
                        if( trumpColor == wantedColor )
                        {
                            // if player does not have currently wanted color or trump color he can play any card
                            return true;
                        }
                        else
                        {
                            biggestCard = GetBiggestCard( _currentHand, trumpColor );

                            Player biggestCardOwner = _cardToPlayerMap[biggestCard] as Player;

                            if( biggestCardOwner == _game.GetTeamPlayer( player ) )
                            {
                                //if hand is held by partner player may not give trump
                                return true;
                            }
                            else
                            {
                                // player must give bigger trump
                                if( !HasPlayingColor( trumpColor, player.Cards ) )
                                {
                                    // player does not have trumps
                                    return true;
                                }
                                else
                                {
                                    if ( biggestCard.CardColor != trumpColor )
                                    {
                                        // biggest card for now is not a trump
                                        // so player must play a trump
                                        return ( card.CardColor == trumpColor );
                                    }
                                    else
                                    {
                                        if ( IsBigger( card, biggestCard ) )
                                        {
                                            // card is biggest for now
                                            return true;
                                        }
                                        else
                                        {
                                            // card is not biggest but player has no bigger one
                                            return !HasBigger( biggestCard, player.Cards, trumpColor );
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }

            return false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the player who played a given card
        /// </summary>
        /// <param name="card">the card to check for</param>
        /// <returns>the player who played the given card or null if card has not passed</returns>
        public Player GetPlayerWhoPlayedCard( Card card )
        {
            if( card == null )
            {

            }
            return _cardToPlayerMap[card];
        }
Ejemplo n.º 13
0
 internal virtual int Add( Card value )
 {
     int ret =  InnerList.Add( value );
     RaiseChanged();
     return ret;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public virtual int IndexOf( Card value )
 {
     return( InnerList.IndexOf( value ) );
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Whether the collection contains a specific card.
 /// </summary>
 public bool Contains( Card value )
 {
     // If value is not of type Card, this will return false.
     return( InnerList.Contains( value ) );
 }
Ejemplo n.º 16
0
        private bool IsConsequent( Card x, Card y )
        {
            if( x.CardType == CardType.Eight && y.CardType == CardType.Seven )
                return true;

            if( x.CardType == CardType.Nine && y.CardType == CardType.Eight )
                return true;

            if( x.CardType == CardType.Ten && y.CardType == CardType.Nine )
                return true;

            if( x.CardType == CardType.Jack && y.CardType == CardType.Ten )
                return true;

            if( x.CardType == CardType.Queen && y.CardType == CardType.Jack )
                return true;

            if( x.CardType == CardType.King && y.CardType == CardType.Queen )
                return true;

            if( x.CardType == CardType.Ace && y.CardType == CardType.King )
                return true;

            else return false;
        }
Ejemplo n.º 17
0
 private void ComputerPlayerPlayed( Player player, Card playedCard )
 {
     SetPlayerActive( null );
     MoveCardToTable( player.Position, playedCard );
 }
Ejemplo n.º 18
0
        private void CheckForBelotCombination( Player player, Card playedCard )
        {
            CardsCollection foundCards = new CardsCollection();
            CardColor trumpColor = GetTrumpColor( );

            if( _currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps )
            {
                if( _currentHand.IsEmpty )
                {
                    CheckBelotForValidColor( player, playedCard, foundCards );
                }
                else
                {
                    if( playedCard.CardColor == GetPlayingColor( _currentHand ) )
                    {
                        CheckBelotForValidColor( player, playedCard, foundCards );
                    }
                }
            }
            else if( _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps && playedCard.CardColor == trumpColor )
            {
                CheckBelotForValidColor( player, playedCard, foundCards );
            }

            if( foundCards.Count != 0 )
            {
                BelotFound( player, new BelotCombination( foundCards, 20) );
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Compares in such order 7,8,Q,K,10,A,9,J
        /// </summary>
        private int CompareTrumps( Card cardX, Card cardY )
        {
            int x = 0, y = 0;

            switch( cardX.CardType )
            {
                case CardType.Jack:
                    x = 8;
                    break;
                case CardType.Nine:
                    x = 7;
                    break;
                case CardType.Ace:
                    x = 6;
                    break;
                case CardType.Ten:
                    x = 5;
                    break;
                case CardType.King:
                    x = 4;
                    break;
                case CardType.Queen:
                    x = 3;
                    break;
                case CardType.Eight:
                    x = 2;
                    break;
                case CardType.Seven:
                    x = 1;
                    break;
            }

            switch( cardY.CardType )
            {
                case CardType.Jack:
                    y = 8;
                    break;
                case CardType.Nine:
                    y = 7;
                    break;
                case CardType.Ace:
                    y = 6;
                    break;
                case CardType.Ten:
                    y = 5;
                    break;
                case CardType.King:
                    y = 4;
                    break;
                case CardType.Queen:
                    y = 3;
                    break;
                case CardType.Eight:
                    y = 2;
                    break;
                case CardType.Seven:
                    y = 1;
                    break;
            }

            if( x > y )
                return 1;
            else if( x < y )
                return -1;
            else
                return 0;
        }
Ejemplo n.º 20
0
        private bool HasBigger( Card biggestCard, CardsCollection cards, CardColor wantedColor )
        {
            bool hasBigger = false;
            foreach( Card card in cards )
            {
                if( card.CardColor == wantedColor )
                {
                    if( _cardComparer.Compare( card, biggestCard ) > 0 )
                    {
                        hasBigger = true;
                        break;
                    }
                }
            }

            return hasBigger;
        }
Ejemplo n.º 21
0
 public void PlayCard( Card card )
 {
     RaiseCardPlayed( card );
 }
Ejemplo n.º 22
0
 private bool IsBigger( Card card, Card biggestCard )
 {
     return _cardComparer.Compare( card, biggestCard ) > 0;
 }
Ejemplo n.º 23
0
        private int EvalutePointsOnRemaining( Card targetCard )
        {
            // 1.1
            const int POINTS_TO_ADD = 20;
            int points = POINTS_TO_ADD;

            Card maxCard = GetCurrentMaxCardInColor( targetCard.CardColor );
            int distance = GetDistance( targetCard, maxCard, _playingManager.CurrentAnnouncement );
            int remainingCards = 0;

            foreach ( Card card in this.Cards )
            {
                if ( card.CardColor == targetCard.CardColor && card != targetCard )
                {
                    remainingCards++;
                }
            }

            int passedCards = 0;
            foreach ( Card card in _playingManager.PlayedCards )
            {
                if ( card.CardColor == targetCard.CardColor )
                {
                    passedCards++;
                }
            }

            if ( remainingCards >= distance )
            {
                points += ( remainingCards - distance ) * POINTS_TO_ADD - distance - passedCards;
            }
            else
            {
                points = 0;
            }

            return points;
        }
Ejemplo n.º 24
0
 public CardClickedEventArgs( Card card )
 {
     _card = card;
 }
Ejemplo n.º 25
0
        private int GetDistance( Card card, Card maxCard, Announcement announce )
        {
            int distance = 0;
            if ( card.CardColor != maxCard.CardColor )
            {
                throw new ArgumentException( "When comparing distance between two cards, they must have same color" );
            }

            CardColor trumpColor = GetTrumpColor();

            switch ( announce.Type )
            {
                case AnnouncementTypeEnum.AllTrumps:
                    distance = GetDistanceTrumps( card, maxCard );
                    break;
                case AnnouncementTypeEnum.NoTrumps:
                    distance = GetDistanceNoTrumps( card, maxCard );
                    break;
                case AnnouncementTypeEnum.Spades:
                case AnnouncementTypeEnum.Hearts:
                case AnnouncementTypeEnum.Diamonds:
                case AnnouncementTypeEnum.Clubs:
                    if ( card.CardColor == trumpColor )
                        distance = GetDistanceTrumps( card, maxCard );
                    else
                        distance = GetDistanceNoTrumps( card, maxCard );
                    break;
            }

            return distance;
        }
Ejemplo n.º 26
0
        internal void PlayerPlayedCard( Player player, Card playedCard )
        {
            _playingManager.Add( player, playedCard );

            player.Cards.Remove( playedCard );

            foreach( Card card in player.Cards )
            {
                card.IsSelectable = false;
            }

            if( _playingManager.IsHandClosed )
            {
                Hand lastHand = _playingManager.GetLastHand();
                CalculatePoints( lastHand );
                _game.HandIsClosed( lastHand );
                NextHand();
            }
            else
            {
                PlayerHasTurn( _game.GetNextPlayer( player ) );
            }
        }
Ejemplo n.º 27
0
        private bool IsCurrentMaxCardInPlayingColor( Card targetCard )
        {
            CardComparer comparer = new CardComparer( _playingManager.CurrentAnnouncement.Type );
            bool foundBigger = false;

            foreach ( Card remCard in _playingManager.RemainingCards )
            {
                if ( targetCard.CardColor == remCard.CardColor )
                {
                    if ( comparer.Compare( targetCard, remCard ) < 0 )
                    {
                        foundBigger = true;
                        break;
                    }
                }
            }

            if ( !foundBigger )
            {
                foreach ( Card remCard in _playingManager.CurrentHand )
                {
                    if ( targetCard.CardColor == remCard.CardColor )
                    {
                        if ( comparer.Compare( targetCard, remCard ) < 0 )
                        {
                            foundBigger = true;
                            break;
                        }
                    }
                }
            }

            return !foundBigger;
        }
Ejemplo n.º 28
0
        internal virtual void Insert( int index, Card value )
        {
            if ((index < 0) || (index > this.InnerList.Count))
            {
                throw new ArgumentOutOfRangeException("Card inserted on wrong place");
            }

            InnerList.Insert( index, value );
            RaiseChanged( );
        }