Exemple #1
0
		public void AddRange(Player player, IEnumerable<Card> cardCollection, DeckPosition deckPosition)
		{
			switch (deckPosition)
			{
				case DeckPosition.Top:
					_Cards.InsertRange(0, cardCollection.Reverse());
					break;
				case DeckPosition.Bottom:
					_Cards.AddRange(cardCollection);
					break;
			}
			this.Sort();

			if (cardCollection.Count() > 0)
			{
				if (_AsynchronousChanging)
				{
					if (_AsynchronousPileChangedEventArgs == null)
						_AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
					else
						_AsynchronousPileChangedEventArgs.AddedCards.AddRange(cardCollection);
				}
				else if (PileChanged != null)
				{
					lock (PileChanged)
					{
						PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
						PileChanged(this, pcea);
					}
				}
			}
		}
 public CardReceivedEventArgs(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
 {
     this.FromPlayer = fromPlayer;
     this.Card       = card;
     this.Location   = location;
     this.Position   = position;
 }
Exemple #3
0
        private void NextCard_Click(object sender, EventArgs e)
        {
            DeckPosition deckPos = (DeckPosition)Convert.ToInt32((sender as Button).Tag);

            drill.NextCard(deckPos);
            wordTextBox.Text = drill.CurrentWord();
        }
Exemple #4
0
    private int GetIndexFromPosition(DeckPosition pos)
    {
        int newPositionIndex = 0;

        switch (pos)
        {
        case DeckPosition.Top:
            newPositionIndex = LastIndex;
            break;

        case DeckPosition.Middle:
            newPositionIndex = UnityEngine.Random.Range(0, LastIndex);
            break;

        case DeckPosition.Bottom:
            newPositionIndex = 0;
            break;
        }

        if (_cards.Count == 0)
        {
            newPositionIndex = 0;
        }

        return(newPositionIndex);
    }
Exemple #5
0
    private int GetIndexFromPosition(DeckPosition position)
    {
        int newPositionIndex = 0;

        // Index is zero on an empty deck, though this will have to be interpreted
        if (_cards.Count == 0)
        {
            newPositionIndex = 0;
        }

        // Index is last in deck "on the top"
        if (position == DeckPosition.Top)
        {
            newPositionIndex = LastIndex;
        }
        // randomizes index if drawing from deck "body"
        else if (position == DeckPosition.Middle)
        {
            newPositionIndex = UnityEngine.Random.Range(0, LastIndex);
        }
        // Index is 0 "on the bottom"
        else if (position == DeckPosition.Bottom)
        {
            newPositionIndex = 0;
        }

        return(newPositionIndex);
    }
Exemple #6
0
    private int GetIndexFromPosition(DeckPosition position)
    {
        int newPositionIndex = 0;

        //if our deck is empty, index should always be 0
        if (_cards.Count == 0)
        {
            newPositionIndex = 0;
        }
        //get end index if it's on 'front the top'
        if (position == DeckPosition.Top)
        {
            newPositionIndex = LastIndex;
        }
        //randomize if drawing from the middle
        else if (position == DeckPosition.Middle)
        {
            newPositionIndex = UnityEngine.Random.Range(0, LastIndex);
        }
        //get 0 index if it's 'from the bottom'
        else if (position == DeckPosition.Bottom)
        {
            newPositionIndex = 0;
        }

        return(newPositionIndex);
    }
 public CardGainEventArgs(Game game, Card card, DeckLocation location, DeckPosition position, Boolean bought)
 {
     this.Game     = game;
     this.Card     = card;
     this.Location = location;
     this.Position = position;
     this.Bought   = bought;
 }
 public CardsAddedToDeckEventArgs(Card card, DeckPosition deckPosition)
 {
     this.Cards = new CardCollection()
     {
         card
     };
     this.DeckPosition = deckPosition;
 }
Exemple #9
0
    // adds cards to the deck from a given list
    public void Add(List <T> cards, DeckPosition position = DeckPosition.Top)
    {
        int itemCount = cards.Count;

        for (int i = 0; i < itemCount; i++)
        {
            Add(cards[i], position);
        }
    }
Exemple #10
0
    public T Draw(DeckPosition position = DeckPosition.Top)
    {
        if (IsEmpty)
        {
            //Debug.LogWarning("Deck: Cannot draw new item - deck is empty!");
            return(null);
        }

        int targetIndex = GetIndexFromPosition(position);

        T cardToRemove = _cards[targetIndex];

        Remove(targetIndex);

        return(cardToRemove);
    }
Exemple #11
0
    public void Add(T card, DeckPosition position = DeckPosition.Top)
    {
        if (card == null)
        {
            return;
        }
        int targetIndex = GetIndexFromPosition(position);

        if (targetIndex == LastIndex)
        {
            cards.Add(card);
        }
        else
        {
            cards.Insert(targetIndex, card);
        }
        CardAdded?.Invoke(card);
    }
Exemple #12
0
        internal CardCollection Retrieve(Player player, DeckPosition position, Predicate <Card> match, int count)
        {
            CardCollection matching = _Cards.FindAll(match);

            if (count >= 0 && count < matching.Count)
            {
                if (position == DeckPosition.Bottom)
                {
                    matching.RemoveRange(0, matching.Count - count);
                }
                else
                {
                    matching.RemoveRange(count, matching.Count - count);
                }
                if (matching.Count != count)
                {
                    throw new Exception("Incorrect number of cards drawn!");
                }
            }
            _Cards.RemoveAll(c => matching.Contains(c));

            if (matching.Count > 0)
            {
                if (_AsynchronousChanging)
                {
                    if (_AsynchronousPileChangedEventArgs == null)
                    {
                        _AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Removed, matching);
                    }
                    else
                    {
                        _AsynchronousPileChangedEventArgs.AddedCards.AddRange(matching);
                    }
                }
                else if (PileChanged != null)
                {
                    PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Removed, matching);
                    PileChanged(this, pcea);
                }
            }
            return(matching);
        }
    public void Add(T card, DeckPosition position = DeckPosition.Top)
    {
        //bodyguard
        if (card == null)
        {
            return;
        }

        int targetIndex = GetIndexFromPosition(position);

        // to add it to 'Top' we actually want to add it at the end, by default Inset() moves the current index upwards
        if (targetIndex == LastIndex)
        {
            _cards.Add(card);
        }
        else
        {
            _cards.Insert(targetIndex, card);
        }
        CardAdded?.Invoke(card);
    }
Exemple #14
0
    //Deck Position Code
    private int GetIndexFromPosition(DeckPosition position)
    {
        int newPositionIndex = 0;

        if (cards.Count == 0)
        {
            newPositionIndex = 0;
        }
        if (position == DeckPosition.Top)
        {
            newPositionIndex = LastIndex;
        }
        else if (position == DeckPosition.Middle)
        {
            newPositionIndex = UnityEngine.Random.Range(0, LastIndex);
        }
        else if (position == DeckPosition.Bottom)
        {
            newPositionIndex = 0;
        }

        return(newPositionIndex);
    }
Exemple #15
0
        public void AddRange(Player player, IEnumerable <Card> cardCollection, DeckPosition deckPosition)
        {
            switch (deckPosition)
            {
            case DeckPosition.Top:
                _Cards.InsertRange(0, cardCollection.Reverse());
                break;

            case DeckPosition.Bottom:
                _Cards.AddRange(cardCollection);
                break;
            }
            this.Sort();

            if (cardCollection.Count() > 0)
            {
                if (_AsynchronousChanging)
                {
                    if (_AsynchronousPileChangedEventArgs == null)
                    {
                        _AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
                    }
                    else
                    {
                        _AsynchronousPileChangedEventArgs.AddedCards.AddRange(cardCollection);
                    }
                }
                else if (PileChanged != null)
                {
                    lock (PileChanged)
                    {
                        PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
                        PileChanged(this, pcea);
                    }
                }
            }
        }
		/// <summary>
		/// Tries to gain the specified card into the location and position of the deck specified
		/// </summary>
		/// <param name="card">The card to gain from the supply</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="isBought">Indicating whether or not the card was bought</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		private Boolean Gain(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			if (card == null)
				return false;

			Boolean cancelled = false;
			Boolean lostTrackOf = false;
			if (CurrentTurn != null)
				CurrentTurn.Gained(card);

			CardGainInto(card, location, position, isBought, false, false);

			if (CardGained != null)
			{
				// This is a little bit wacky, but we're going to set up an event listener INSIDE this method that listens to both
				// the Discard Pile and the Draw Pile for changes.  We need to do this in order to capture any "Lost Track" updates
				// that might happen from one card covering up another card (e.g. this card being gained) and causing the game state
				// to "Lose Track" of the card being gained in this method.
				_LostTrackStack[card] = false;
				Pile.PileChangedEventHandler pceh = new Pile.PileChangedEventHandler(DiscardPile_PileChanged_CaptureLostTrack);
				this.DiscardPile.PileChanged += pceh;

				List<Object> handledBy = new List<Object>();
				CardGainEventArgs cgea = null;
				Boolean actionPerformed = false;
				do
				{
					actionPerformed = false;

					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.HandledBy.AddRange(handledBy);
					cgea.Cancelled = cancelled;
					cgea.IsLostTrackOf = lostTrackOf;
					CardGained(this, cgea);
					handledBy = cgea.HandledBy;
					cancelled |= cgea.Cancelled;
					lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
					location = cgea.Location;
					position = cgea.Position;

					IEnumerator<Player> enumerator = this._Game.GetPlayersStartingWithEnumerator(this);
					while (enumerator.MoveNext())
					{
						Boolean isAnyRequired = false;
						List<String> options = new List<String>();
						IEnumerable<Type> cardTypes = cgea.Actions.Keys;
						foreach (Type key in cardTypes)
						{
							if (enumerator.Current == cgea.Actions[key].Player)
							{
								options.Add(cgea.Actions[key].Text);
								isAnyRequired |= cgea.Actions[key].IsRequired;
							}
						}
						if (options.Count > 0)
						{
							Choice choice = new Choice(String.Format("{0} gained {1}", this == enumerator.Current ? "You" : this.ToString(), card), null, new CardCollection() { card }, options, this, cgea, false, isAnyRequired ? 1 : 0, 1);
							ChoiceResult result = enumerator.Current.MakeChoice(choice);

							if (result.Options.Count > 0)
							{
								options.Sort();
								cgea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(enumerator.Current, ref cgea);
								actionPerformed = true;
							}

							if (enumerator.Current == this && (cgea.Location != location || cgea.Position != position))
								CardGainInto(card, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);

							cancelled |= cgea.Cancelled;
							lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
							location = cgea.Location;
							position = cgea.Position;
						}
					}
				} while (CardGained != null && actionPerformed);

				if (pceh != null)
					this.DiscardPile.PileChanged -= pceh;
				_LostTrackStack.Remove(card);
			}

			CardGainFinish(card, location, position, isBought, cancelled, lostTrackOf);

			return true;
		}
		/// <summary>
		/// Tries to gain the specified cardType from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="cardType">The card type we're trying to gain</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, Type cardType, DeckLocation location, DeckPosition position)
		{
			return Gain(supply, cardType, location, position, false);
		}
		/// <summary>
		/// Tries to gain from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, DeckLocation location, DeckPosition position)
		{
			return Gain(supply, supply.TopCard == null ? null : supply.TopCard.CardType, location, position, false);
		}
		private CardGainEventArgs CardGainCheckAllowed(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			Boolean cancelled = false;
			CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);

			if (CardGaining != null)
			{
				do
				{
					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.Cancelled = cancelled;
					CardGaining(this, cgea);

					Boolean isAnyRequired = false;
					List<String> options = new List<String>();
					IEnumerable<Type> cardTypes = cgea.Actions.Keys;
					foreach (Type key in cardTypes)
					{
						options.Add(cgea.Actions[key].Text);
						isAnyRequired |= cgea.Actions[key].IsRequired;
					}

					if (options.Count > 0)
					{
						options.Sort();
						Choice choice = new Choice(String.Format("You are gaining {0}", card), null, new CardCollection() { card }, options, this, cgea, false, isAnyRequired ? 1 : 0, 1);
						ChoiceResult result = this.MakeChoice(choice);

						if (result.Options.Count > 0)
							cgea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(this, ref cgea);
					}

					cancelled = cgea.Cancelled;
					location = cgea.Location;
					position = cgea.Position;
				} while (CardGaining != null && cgea.HandledBy.Count > 0);
			}
			return cgea;
		}
		public void AddCardsInto(Type deckType, IEnumerable<Card> cards, DeckPosition position)
		{
			if (cards.Count() == 0)
				return;
			foreach (Card card in cards)
			{
				card.ModifiedBy = null;
				card.AddedTo(deckType, this);
			}
			PlayerMats.Add(this, deckType, cards);
		}
		public void AddCardsInto(DeckLocation location, IEnumerable<Card> cards, DeckPosition position)
		{
			if (this.Phase != PhaseEnum.Endgame)
			{
				foreach (Card card in cards)
					card.AddedTo(location, this);
			}

			DeckPosition realPosition = ResolveDeckPosition(location, position);
			switch (location)
			{
				case DeckLocation.Hand:
					foreach (Card card in cards)
						card.ModifiedBy = null;
					_Hand.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.Revealed:
					foreach (Card card in cards)
						card.ModifiedBy = null;
					_Revealed.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.Discard:
					foreach (Card card in cards)
						card.ModifiedBy = null;
					_DiscardPile.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.Deck:
					foreach (Card card in cards)
						card.ModifiedBy = null;
					_DrawPile.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.InPlay:
					_InPlay.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.SetAside:
					_SetAside.AddRange(this, cards, realPosition);
					break;

				case DeckLocation.Private:
					foreach (Card card in cards)
						card.ModifiedBy = null;
					_Private.AddRange(this, cards, realPosition);
					break;
			}
		}
Exemple #22
0
		internal CardCollection Retrieve(Player player, DeckPosition position, Predicate<Card> match, int count)
		{
			CardCollection matching = _Cards.FindAll(match);
			if (count >= 0 && count < matching.Count)
			{
				if (position == DeckPosition.Bottom)
					matching.RemoveRange(0, matching.Count - count);
				else
					matching.RemoveRange(count, matching.Count - count);
				if (matching.Count != count)
					throw new Exception("Incorrect number of cards drawn!");
			}
			_Cards.RemoveAll(c => matching.Contains(c));

			if (matching.Count > 0)
			{
				if (_AsynchronousChanging)
				{
					if (_AsynchronousPileChangedEventArgs == null)
						_AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Removed, matching);
					else
						_AsynchronousPileChangedEventArgs.AddedCards.AddRange(matching);
				}
				else if (PileChanged != null)
				{
					PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Removed, matching);
					PileChanged(this, pcea);
				}
			}
			return matching;
		}
Exemple #23
0
 /// <summary>
 /// Retrieve current card for specified deck.
 /// </summary>
 /// <param name="deckPosition"></param>
 /// <returns></returns>
 public Card CurrentCard(DeckPosition deckPosition)
 {
     return(Decks[deckPosition].CurrentCard());
 }
		public CardsAddedToDeckEventArgs(IEnumerable<Card> cards, DeckPosition deckPosition)
		{
			this.Cards = new CardCollection(cards);
			this.DeckPosition = deckPosition;
		}
		public CardsAddedToDeckEventArgs(Card card, DeckPosition deckPosition)
		{
			this.Cards = new CardCollection() { card };
			this.DeckPosition = deckPosition;
		}
		public CardGainEventArgs(Game game, Card card, DeckLocation location, DeckPosition position, Boolean bought)
		{
			this.Game = game;
			this.Card = card;
			this.Location = location;
			this.Position = position;
			this.Bought = bought;
		}
		public CardReceivedEventArgs(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
		{
			this.FromPlayer = fromPlayer;
			this.Card = card;
			this.Location = location;
			this.Position = position;
		}
		public CardsDrawnEventArgs(IEnumerable<Card> cards, DeckPosition fromDeckPosition, int numberToDraw)
		{
			this.Cards.AddRange(cards);
			this.FromDeckPosition = fromDeckPosition;
			this.NumberToDraw = numberToDraw;
		}
		private void CardGainFinish(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (CardGainFinished != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainFinished(this, cgea);
			}
		}
		public DeckPosition ResolveDeckPosition(DeckLocation location, DeckPosition position)
		{
			switch (location)
			{
				case DeckLocation.Hand:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Revealed:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Discard:
					return position == DeckPosition.Automatic ? DeckPosition.Top : position;

				case DeckLocation.Deck:
					return position == DeckPosition.Automatic ? DeckPosition.Top : position;

				case DeckLocation.InPlay:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.SetAside:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.PlayerMat:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.Private:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;

				case DeckLocation.InPlayAndSetAside:
					return position == DeckPosition.Automatic ? DeckPosition.Bottom : position;
			}
			return position;
		}
Exemple #31
0
 /// <summary>
 /// Retrieve prev card for specified deck.
 /// </summary>
 /// <param name="deckPos"></param>
 /// <returns></returns>
 public Card PrevCard(DeckPosition deckPosition)
 {
     return(Decks[deckPosition].PrevCard());
 }
		public void AddCardInto(DeckLocation location, Card card, DeckPosition position)
		{
			AddCardsInto(location, new CardCollection() { card }, position);
		}
Exemple #33
0
 /// <summary>
 /// Retrieve next card for specified deck.
 /// </summary>
 /// <param name="deckPos"></param>
 /// <returns></returns>
 public Card NextCard(DeckPosition deckPosition)
 {
     return(Decks[deckPosition].NextCard());
 }
		public void AddCardInto(Type deckType, Card card, DeckPosition position)
		{
			AddCardsInto(deckType, new CardCollection() { card }, position);
		}
		public void AddCardToDeck(Card card, DeckPosition deckPosition)
		{
			AddCardInto(DeckLocation.Deck, card, deckPosition);
			if (CardsAddedToDeck != null)
			{
				CardsAddedToDeckEventArgs catdea = new CardsAddedToDeckEventArgs(card, deckPosition);
				CardsAddedToDeck(this, catdea);
			}
			
		}
		internal CardCollection RetrieveCardsFrom(DeckLocation location, DeckPosition position, Predicate<Card> match, int count)
		{
			CardCollection cards;
			switch (location)
			{
				case DeckLocation.Hand:
					cards = _Hand.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Revealed:
					cards = _Revealed.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Discard:
					cards = _DiscardPile.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Deck:
					cards = _DrawPile.Retrieve(this, position, match, count);
					if (cards.Count < count && _DrawPile.Count == 0 && _DiscardPile.Count > 0)
						this.ShuffleForDrawing();
					cards.AddRange(_DrawPile.Retrieve(this, position, match, count < 0 ? count : count - cards.Count));
					break;

				case DeckLocation.InPlay:
					cards = _InPlay.Retrieve(this, position, match, count);
					break;

				case DeckLocation.SetAside:
					cards = _SetAside.Retrieve(this, position, match, count);
					break;

				case DeckLocation.Private:
					cards = _Private.Retrieve(this, position, match, count);
					break;

				case DeckLocation.InPlayAndSetAside:
					cards = _InPlay.Retrieve(this, position, match, count);
					cards.AddRange(_SetAside.Retrieve(this, position, match, count < 0 ? count : count - cards.Count));
					break;

				default:
					cards = new CardCollection();
					break;
			}
			cards.RemovedFrom(location, this);
			return cards;
		}
 public CardsAddedToDeckEventArgs(CardCollection cards, DeckPosition deckPosition)
 {
     this.Cards        = cards;
     this.DeckPosition = deckPosition;
 }
		/// <summary>
		/// Tries to gain the specified card from the trash specified into the location and position of the deck specified
		/// </summary>
		/// <param name="trash">The trash pile to look through</param>
		/// <param name="card">The card to gain from the trash</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Trash trash, Card card, DeckLocation location, DeckPosition position)
		{
			if (trash.Contains(card))
			{
				CardGainEventArgs cgea = CardGainCheckAllowed(card, location, position, false);
				if (!cgea.Cancelled)
					return this.Gain(trash.Retrieve(this, card), cgea.Location, cgea.Position, cgea.Bought);
				else
				{
					CardGainFinish(card, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);
					return true;
				}
			}
			return false;
		}
Exemple #39
0
 //Draws next item (top of deck). default to top
 public T Draw(DeckPosition position = DeckPosition.Top)
 {
     if (IsEmpty)
     {
         Debug.LogWarning("Deck: Cannot draw new item - deck is empty!");
         return(default);
		/// <summary>
		/// Tries to gain the number of cards specified from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="count">How many cards to gain</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, DeckLocation location, DeckPosition position, int count)
		{
			Boolean success = true;
			for (int i = 0; i < count; i++)
				success &= this.Gain(supply, supply.TopCard == null ? null : supply.TopCard.CardType, location, position, false);
			return success;
		}
		public CardsAddedToDeckEventArgs(CardCollection cards, DeckPosition deckPosition)
		{
			this.Cards = cards;
			this.DeckPosition = deckPosition;
		}
		/// <summary>
		/// Tries to gain the specified cardType from the specified supply into the location and position of the deck specified
		/// </summary>
		/// <param name="supply">The supply pile to gain from</param>
		/// <param name="cardType">The card type we're trying to gain</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="isBought">Indicating whether or not the card was bought</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		public Boolean Gain(Supply supply, Type cardType, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			if (supply.CanGain(cardType))
			{
				Card supplyCard = supply[cardType].First();
				CardGainEventArgs cgea = CardGainCheckAllowed(supplyCard, location, position, isBought);
				if (!cgea.Cancelled)
					return this.Gain(supply.Take(cardType), cgea.Location, cgea.Position, cgea.Bought);
				else
				{
					CardGainFinish(supplyCard, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);
					return false;
				}
			}
			return false;
		}
 public CardsAddedToDeckEventArgs(IEnumerable <Card> cards, DeckPosition deckPosition)
 {
     this.Cards        = new CardCollection(cards);
     this.DeckPosition = deckPosition;
 }
		private void CardGainInto(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (this.DiscardPile.Contains(card))
				this.RetrieveCardFrom(DeckLocation.Discard, card);
			card.Gaining(this, ref location, ref position);
			this.AddCardInto(location, card, position);
			card.Gained(this);

			if (CardGainedInto != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainedInto(this, cgea);
			}
		}
Exemple #45
0
 // retrieves an item while removing it from the deck
 public T Draw(DeckPosition position = DeckPosition.Top)
 {
     if (IsEmpty)
     {
         // draw fail feedback
         return(default);
		public void Receive(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
		{
			if (CurrentTurn != null)
				CurrentTurn.Received(card);
			this.AddCardInto(location, card, position);
			card.ReceivedBy(this);

			if (CardReceived != null)
			{
				CardReceivedEventArgs crea = new CardReceivedEventArgs(fromPlayer, card, location, position);
				CardReceived(this, crea);
			}
		}
Exemple #47
0
 internal virtual void Gaining(Player player, ref DeckLocation location, ref DeckPosition position)
 {
     Receiving(player, ref location, ref position);
 }
		public CardCollection DrawFrom(DeckPosition deckPosition, int number, Object destination)
		{
			CardCollection cards = new CardCollection();
			if (number <= 0)
				return cards;

			CardCollection cardsFirst = _DrawPile.Retrieve(this, deckPosition, c => true, number);
			cards.AddRange(cardsFirst);
			cards.RemovedFrom(DeckLocation.Deck, this);

			if (_AsynchronousDrawing)
			{
				if (_AsynchronousCardsDrawnEventArgs == null)
					_AsynchronousCardsDrawnEventArgs = new CardsDrawnEventArgs(cardsFirst, deckPosition, number);
				else
					_AsynchronousCardsDrawnEventArgs.Cards.AddRange(cardsFirst);
			}
			else if (CardsDrawn != null)
			{
				CardsDrawnEventArgs cdea = new CardsDrawnEventArgs(cardsFirst, deckPosition, number);
				CardsDrawn(this, cdea);
			}

			if (destination is Type)
				this.AddCardsInto((Type)destination, cardsFirst);
			else if (destination is DeckLocation)
				this.AddCardsInto((DeckLocation)destination, cardsFirst);
			else
				throw new Exception(String.Format("Destination of {0} ({1}) is not supported", destination, destination.GetType()));
			
			if (cardsFirst.Count < number && _DrawPile.Count == 0 && _DiscardPile.Count > 0)
			{
				this.ShuffleForDrawing();

				CardCollection cardsSecond = _DrawPile.Retrieve(this, deckPosition, c => true, number < 0 ? number : number - cards.Count);
				cards.AddRange(cardsSecond);
				cardsSecond.RemovedFrom(DeckLocation.Deck, this);

				if (_AsynchronousDrawing)
				{
					if (_AsynchronousCardsDrawnEventArgs == null)
						_AsynchronousCardsDrawnEventArgs = new CardsDrawnEventArgs(cardsSecond, deckPosition, number);
					else
						_AsynchronousCardsDrawnEventArgs.Cards.AddRange(cardsSecond);
				}
				else if (CardsDrawn != null)
				{
					CardsDrawnEventArgs cdea = new CardsDrawnEventArgs(cardsSecond, deckPosition, number);
					CardsDrawn(this, cdea);
				}

				if (destination is Type)
					this.AddCardsInto((Type)destination, cardsSecond);
				else if (destination is DeckLocation)
					this.AddCardsInto((DeckLocation)destination, cardsSecond);
				else
					throw new Exception(String.Format("Destination of {0} ({1}) is not supported", destination, destination.GetType()));
			}

			return cards;
		}
Exemple #49
0
 internal virtual void Receiving(Player player, ref DeckLocation location, ref DeckPosition position)
 {
 }
		public void AddCardsToDeck(IEnumerable<Card> cards, DeckPosition deckPosition)
		{
			AddCardsInto(DeckLocation.Deck, cards, deckPosition);
			if (CardsAddedToDeck != null)
			{
				CardsAddedToDeckEventArgs catdea = new CardsAddedToDeckEventArgs(cards, deckPosition);
				CardsAddedToDeck(this, catdea);
			}
		}
 public CardsDrawnEventArgs(IEnumerable <Card> cards, DeckPosition fromDeckPosition, int numberToDraw)
 {
     this.Cards.AddRange(cards);
     this.FromDeckPosition = fromDeckPosition;
     this.NumberToDraw     = numberToDraw;
 }