Esempio n. 1
0
        /**
         * Default equals method
         */
        public override bool Equals(Object o)
        {
            if (o == null)
            {
                return(false);
            }

            if (o is Meld)
            {
                Meld other = (Meld)o;

                if (_cards.Count != other._cards.Count)
                {
                    return(false);
                }

                foreach (Card c in this._cards)
                {
                    if (!other._cards.Contains(c))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        public void LayOff(Player player, Card c, Meld m)
        {
            //check state
            if (!CanMeldLayOff(player))
            {
                _currentError = ErrorMessage.NotPlayerTurn;
                throw new ArgumentException("It is not this player's turn to meld or lay off", "player");
            }
            //check if player has the card
            PlayerHasCard(player, c);

            //try to add, check if the condition satisfies
            if (m.CanAddACard(c))
            {
                m.AddACard(c);
            }
            else
            {
                _currentError = ErrorMessage.InvalidLayoff;
                throw new ArgumentException("Cannot add this card to existing meld", "c");
            }
            RemovePlayerCard(player, c);

            LayOffMove move = new LayOffMove(player, c, m);

            AfterActStuff(move);
            LayoffHappened(move);

            _currentError = ErrorMessage.NoError;
        }
Esempio n. 3
0
        //meld a list of cards
        //player
        //List<Card>
        public void Meld(Player player, IList <Card> lCard)
        {
            //check state
            if (!CanMeldLayOff(player))
            {
                _currentError = ErrorMessage.NotPlayerTurn;
                throw new ArgumentException("It is not this player's turn to meld or lay off", "player");
            }
            if (player == Player.One && !HasListOfCard(Player.One, lCard))
            {
                _currentError = ErrorMessage.NotPlayerCard;
                throw new ArgumentException("Player one does not have all the card required for the meld", "player");
            }
            else if (player == Player.Two && !HasListOfCard(Player.Two, lCard))
            {
                _currentError = ErrorMessage.NotPlayerCard;
                throw new ArgumentException("Player two does not have all the card required for the meld", "player");
            }

            //check if it is a valid meld
            var m = new Meld();

            if (m.IsValid(lCard))
            {
                m = new Meld(lCard);
            }
            else
            {
                _currentError = ErrorMessage.InvalidMeld;
                throw new ArgumentException("Cannot form a meld from a list of cards", "lCard");
            }

            //remove lCard from player
            RemovePlayerCardList(player, lCard);
            //put the meld under this player's name
            AddToPlayerMeld(player, m);

            var meldMove = new MeldMove(player, new Meld(lCard));

            AfterActStuff(meldMove);
            MeldHappend(meldMove);

            _currentError = ErrorMessage.NoError;
        }
Esempio n. 4
0
 public LayOffMove(Player player, Card card, Meld meld)
     : base(player)
 {
     _card = card;
     _meld = meld;
 }
Esempio n. 5
0
 public MeldMove(Player player, Meld meld)
     : base(player)
 {
     _meld = meld;
 }
Esempio n. 6
0
 //add a meld to Player
 private void AddToPlayerMeld(Player player, Meld m)
 {
     GetMelds(player).Add(m);
 }
Esempio n. 7
0
 //meld with an actual meld object
 public void Meld(Player player, Meld m)
 {
     Meld(player, m.ToList());
 }