当前位置: 首页>>代码示例>>C#>>正文


C# CardCollection.AsParallel方法代码示例

本文整理汇总了C#中CardCollection.AsParallel方法的典型用法代码示例。如果您正苦于以下问题:C# CardCollection.AsParallel方法的具体用法?C# CardCollection.AsParallel怎么用?C# CardCollection.AsParallel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CardCollection的用法示例。


在下文中一共展示了CardCollection.AsParallel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PerformCleanup

		private void PerformCleanup()
		{
			// Sets up card movements to indicate where each card should go.
			CardMovementCollection cardsToMove = new CardMovementCollection(this.SetAside, c => c.CanCleanUp, DeckLocation.SetAside, DeckLocation.Discard);
			cardsToMove.AddRange(this.Hand, DeckLocation.Hand, DeckLocation.Discard);
			cardsToMove.AddRange(this.InPlay, DeckLocation.InPlay, DeckLocation.Discard);

			foreach (Card durationCard in this.InPlay.Where(c => !c.CanCleanUp))
				cardsToMove[durationCard].Destination = DeckLocation.SetAside;
			IEnumerable<CardMovement> inPlayCards = cardsToMove.Where(cm => cm.CurrentLocation == DeckLocation.InPlay);

			ParallelQuery<CardMovement> pqCardsToMove = cardsToMove.AsParallel().Where(cm =>
				cm.CurrentLocation == DeckLocation.InPlay &&
				cm.Destination == DeckLocation.SetAside &&
				cm.Card.ModifiedBy != null &&
				cardsToMove.Contains(cm.Card.ModifiedBy.PhysicalCard) &&
				cardsToMove[cm.Card.ModifiedBy.PhysicalCard].Destination == DeckLocation.Discard);

			pqCardsToMove.ForAll(cm => cardsToMove[cm.Card.ModifiedBy.PhysicalCard].Destination = DeckLocation.SetAside);

			int drawSize = 5;
			if (CleaningUp != null)
			{
				Boolean cancelled = false;
				// Possibly changing events that can happen in the game
				CleaningUpEventArgs cuea = null;

				do
				{
					cuea = new CleaningUpEventArgs(this, 5, ref cardsToMove);
					cuea.Cancelled |= cancelled;
					CleaningUp(this, cuea);

					OptionCollection options = new OptionCollection();
					IEnumerable<Type> cardTypes = cuea.Actions.Keys;
					foreach (Type key in cardTypes)
						options.Add(new Option(cuea.Actions[key].Text, false));
					if (options.Count > 0)
					{
						options.Sort();
						Choice choice = new Choice("Performing Clean-up", options, this, cuea);
						ChoiceResult result = this.MakeChoice(choice);

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

					cancelled |= cuea.Cancelled;
				} while (CleaningUp != null);

				if (cuea != null)
					cancelled |= cuea.Cancelled;

				if (cancelled)
					return;

				if (cuea.NextPlayer != null)
					_CurrentTurn.NextPlayer = cuea.NextPlayer;
				_CurrentTurn.NextGrantedBy = cuea.NextGrantedBy;
				drawSize = cuea.DrawSize;
			}

			// Discard any Revealed cards (should be none?)
			this.DiscardRevealed();

			CardsDiscardAction cdaHand = null;
			if (cardsToMove.Count(c => c.CurrentLocation == DeckLocation.Hand) > 0)
				cdaHand = new CardsDiscardAction(this, null, "Discard hand", player_DiscardHand, true) { Data = cardsToMove };

			// Discard non-Duration (or Duration-modifying) cards in In Play & Set Aside at the same time
			this.Discard(DeckLocation.InPlayAndSetAside, cardsToMove.Where(cm =>
				(cm.CurrentLocation == DeckLocation.InPlay || cm.CurrentLocation == DeckLocation.SetAside) &&
				cm.Destination == DeckLocation.Discard).Select<CardMovement, Card>(cm => cm.Card), cdaHand);

			// Discard Hand
			this.AddCardsInto(DeckLocation.Discard,
				this.RetrieveCardsFrom(DeckLocation.Hand, c =>
					cardsToMove[c].CurrentLocation == DeckLocation.Hand && cardsToMove[c].Destination == DeckLocation.Discard));

			// Move Duration (and Duration-modifying) cards from In Play into Set Aside
			this.MoveInPlayToSetAside(c => cardsToMove.Contains(c) && cardsToMove[c].CurrentLocation == DeckLocation.InPlay && cardsToMove[c].Destination == DeckLocation.SetAside);

			// Move any cards that have had their Destination changed to their appropriate locations
			IEnumerable<Card> replaceCards = cardsToMove.Where(cm => cm.Destination == DeckLocation.Deck).Select(cm => cm.Card);
			if (replaceCards.Count() > 0)
			{
				Choice replaceChoice = new Choice("Choose order of cards to put back on your deck", null, replaceCards, this, true, replaceCards.Count(), replaceCards.Count());
				ChoiceResult replaceResult = this.MakeChoice(replaceChoice);
				this.RetrieveCardsFrom(DeckLocation.InPlay, c => cardsToMove[c].CurrentLocation == DeckLocation.InPlay && replaceResult.Cards.Contains(c));
				this.RetrieveCardsFrom(DeckLocation.SetAside, c => cardsToMove[c].CurrentLocation == DeckLocation.SetAside && replaceResult.Cards.Contains(c));
				this.AddCardsToDeck(replaceResult.Cards, DeckPosition.Top);
			}

#if DEBUG
			if (this.InPlay.Count > 0)
				throw new Exception("Something happened -- there are cards left in the player's In Play area!");
//.........这里部分代码省略.........
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:101,代码来源:Player.cs


注:本文中的CardCollection.AsParallel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。