コード例 #1
0
        public void MementoRestoresDeck()
        {
            PowerCardDeck deck = new PowerCardDeck(new PowerCard[] {
                PowerCard.For <Drought>(),
                PowerCard.For <DevouringAnts>(),
                PowerCard.For <DriftDownIntoSlumber>(),
                PowerCard.For <EnticingSplendor>(),
                PowerCard.For <LureOfTheUnknown>(),
                PowerCard.For <NaturesResilience>(),
                PowerCard.For <PullBeneathTheHungryEarth>(),
                PowerCard.For <QuickenTheEarthsStruggles>(),
                PowerCard.For <RainOfBlood>(),
                PowerCard.For <SapTheStrengthOfMultitudes>(),
                PowerCard.For <SongOfSanctity>(),
                PowerCard.For <SteamVents>(),
                PowerCard.For <UncannyMelting>(),
            }, new Random());

            // Given: saving state
            var memento = deck.SaveToMemento();

            //   And: draw first 4 cards
            string originalFirstFourCards = deck.Flip(4).Select(c => c.Name).Join(",");

            //   And: draw some more we don't care about
            deck.Flip(4);

            //  When: restore state using memento
            deck.RestoreFrom(memento);

            //  Then: first 4 cards should be the same
            deck.Flip(4).Select(c => c.Name).Join(",").ShouldBe(originalFirstFourCards);
        }
コード例 #2
0
ファイル: DrawFromDeck.cs プロジェクト: rettigcd/spiritisland
    static async Task <DrawCardResult> DrawInner(Spirit spirit, PowerCardDeck deck, int numberToDraw, int numberToKeep)
    {
        List <PowerCard> candidates = deck.Flip(numberToDraw);

        var selectedCards = new List <PowerCard>();

        while (numberToKeep-- > 0)
        {
            var selected = await TakeCard(spirit, candidates);

            selectedCards.Add(selected);
        }

        deck.Discard(candidates);
        return(new DrawCardResult(selectedCards[0].PowerType)
        {
            SelectedCards = selectedCards.ToArray(),
            Rejected = candidates
        });
    }