Пример #1
0
        public static bool IsValid(IEnumerable <CardType> deck, GameRules gameRules, bool ignoreMinDeckSize = false)
        {
            var deckList = deck.ToList();

            if ((!ignoreMinDeckSize && deckList.Count < gameRules.MinDeckSize) || deckList.Count > gameRules.MaxDeckSize)
            {
                return(false);
            }
            foreach (var card in deckList)
            {
                if (gameRules.MaxRarityInDeck.ContainsKey(card.Rarity) &&
                    deckList.Count(x => x == card) > gameRules.MaxRarityInDeck[card.Rarity])
                {
                    return(false);
                }
            }
            foreach (var e in gameRules.MaxTagInDeck)
            {
                if (deckList.Count(x => x.Tags.Contains(e.Key)) > e.Value)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
 public GameState(List <Deck> decks, Func <EffectMaker> globalEffects, GameRules gameRules = null, Random random = null)
 {
     if (decks.Count != 2)
     {
         throw new ArgumentException("Should have exactly 2 decks");
     }
     GlobalEffects = globalEffects;
     GameRules     = gameRules ?? new GameRules();
     Random        = random ?? new Random();
     Players       = new ReadOnlyCollection <PlayerState>(decks.Select(deck => new PlayerState(this, deck)).ToList());
     Turn          = 1;
 }
Пример #3
0
 public Deck(Dictionary <CardType, int> deck, GameRules gameRules)
 {
     this.deck = new List <CardType>();
     foreach (var e in deck)
     {
         for (int i = 0; i < e.Value; ++i)
         {
             this.deck.Add(e.Key);
         }
     }
     GameRules = gameRules;
 }
Пример #4
0
        public static Deck MakeRandomDeck(ICardCollection cardCollection, GameRules gameRules, int deckSize, Random random)
        {
            var cards = cardCollection.GetCards().ToList();

            if (deckSize < gameRules.MinDeckSize || deckSize > gameRules.MaxDeckSize)
            {
                throw new ArgumentException("Deck size is incorrect");
            }
            var deck = new Deck(gameRules);

            while (deck.Count < deckSize)
            {
                var card = random.ChoiceOrDefault(cards.Where(x => deck.CanAddCard(x)));
                if (card == null)
                {
                    throw new ArgumentException("Collection is not large enough");
                }
                deck.Add(card);
            }
            return(deck);
        }
Пример #5
0
 public Deck(IEnumerable <CardType> deck, GameRules gameRules)
 {
     this.deck = deck.ToList();
     GameRules = gameRules;
 }
Пример #6
0
 public Deck(GameRules gameRules)
 {
     deck      = new List <CardType>();
     GameRules = gameRules;
 }
Пример #7
0
 public static Deck MakeRandomDeck(ICardCollection cardCollection, GameRules gameRules, Random random)
 {
     return(MakeRandomDeck(cardCollection, gameRules, gameRules.MinDeckSize, random));
 }