Exemple #1
0
    public void RemoveAmountOfCardFromCollection(Card card, int amountToRemove)
    {
        int index = GetIndexOfCard(card);

        amountOfEachCard[index] -= amountToRemove;
        CardsCollection.SumToCurrentAmount(card, -amountToRemove);
    }
Exemple #2
0
        public void Initialize_With_String()
        {
            var cards = new CardsCollection("Ah 2s 7d Ts Jc");

            Assert.Equal(5, cards.Count);
            Assert.Equal("Ah 2s 7d Ts Jc", cards.ToString());
        }
Exemple #3
0
        public async Task <IActionResult> Delete([FromForm] int id, string name)
        {
            if (name.ToLower() == "default")
            {
                return(RedirectToAction("AllCards"));
            }

            CardsCollection cardsVM = await _cardsService.GetCardsById(id);

            if (cardsVM != null)
            {
                Task <bool> result = _crudCardsService.DeleteAsync(cardsVM);

                if (result.Result == true)
                {
                    return(RedirectToAction("AllCards"));
                }
                else
                {
                    ModelState.AddModelError("", "Collection Not Delete");
                }
            }
            else
            {
                ModelState.AddModelError("", "Collection Not Found");
            }
            return(View("AllCards"));
        }
Exemple #4
0
        private void DrawCards(Player player, CardsCollection cards)
        {
            switch (player.Position)
            {
            case PlayerPosition.South:
                _panelSouth.Cards = cards;
                break;

            case PlayerPosition.East:
                _panelEast.Cards = cards;
                break;

            case PlayerPosition.North:
                _panelNorth.Cards = cards;
                break;

            case PlayerPosition.West:
                _panelWest.Cards = cards;
                break;

            default:
                _panelSouth.Cards = cards;
                break;
            }
        }
Exemple #5
0
        public async Task <IActionResult> CreateCards([FromForm] string name)
        {
            if (ModelState.IsValid)
            {
                string id = GetCurrentUserId();

                // if user id not found => redirect to login view
                if (id == String.Empty)
                {
                    return(RedirectToAction(nameof(AccountController.Login), "Account"));
                }

                CardsCollection cardsCollection = new CardsCollection
                {
                    AppUserId      = id,
                    DateOfCreation = DateTimeOffset.Now,
                    Name           = name
                };

                var result = await _crudCardsService.AddAsync(cardsCollection);

                if (result != null)
                {
                    return(RedirectToAction("AllCards"));
                }
                else
                {
                    return(RedirectToAction(nameof(HomeController.Error), "Home"));
                }
            }
            return(RedirectToAction("AllCards"));
        }
        internal void AddCard(CardInstance value, int qty)
        {
            if (value == null)
            {
                return;
            }
            foreach (var ci in CardsCollection.Where(ci => ci.BorderBrush != null))
            {
                ci.BorderBrush = null;
            }
            var card = CardsCollection.Where(ci => ci.CardId == value.CardId).FirstOrDefault();

            if (card != null)
            {
                card.Quantity   += qty; //if already in deck, inc qty
                card.BorderBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 100, 15));
            }
            else
            {
                card             = value;
                card.BorderBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 100, 15));
                card.Quantity    = qty;
                CardsCollection.Add(card);
            }
            if (LimitCardCount)
            {
                trackerFactory.GetService <IDeckService>().EnforceCardLimit(card);
            }
            NewCard = null;
        }
        public void TestDeck_SortCards_ShouldPass()
        {
            var shufledCards = new Queue <SimpleCard>(fullDeck);

            shufledCards.Shuffle();

            var deck = new CardsCollection();

            foreach (var card in shufledCards)
            {
                deck.Add(card);
            }
            System.Console.WriteLine();
            var        sortedDeck = deck.OrderBy(x => x);
            SimpleCard checkCard  = null;

            foreach (var item in sortedDeck)
            {
                checkCard = item as SimpleCard;
                break;
            }
            SimpleCard firstCard = new SimpleCard(CardType.Two, Suit.Clubs);
            bool       areSame   = checkCard.Equals(firstCard);

            Assert.IsTrue(areSame);
        }
        public async Task <CardsCollection> PatchAsync(CardsCollection patchInfo)
        {
            var card = context.Collections.Update(patchInfo);
            await context.SaveChangesAsync();

            return(card.Entity);
        }
        public async Task <CardsCollection> CreateAsync(CardsCollection collectionToAdd)
        {
            await context.Collections.AddAsync(collectionToAdd);

            await context.SaveChangesAsync();

            return(collectionToAdd);
        }
Exemple #10
0
    private static Card GetCloneOfCardFromAvailablePrototypesRandomly()
    {
        Card[] allPrototypes = CardPrototypesAccessor.allCardPrototypes;
        Card[] unlockedCards = CardsCollection.GetUnlockedCardsFrom(allPrototypes);
        int    randomIndex   = Random.Range(0, unlockedCards.Length);

        return(unlockedCards[randomIndex].GetClone());
    }
Exemple #11
0
 private void GiveRewardDeckThenSeeMap(Card[] rewardDeck)
 {
     for (int r = 0; r < rewardDeck.Length; r++)
     {
         CardsCollection.SumToCurrentAmount(rewardDeck[r], 1);
     }
     QuitBattleAndGoToMap();
 }
Exemple #12
0
 public Game()
 {
     currentCard             = 0;
     playDeck                = new Deck(true);
     playDeck.LastCardDrawn += Reshuffle;
     playDeck.Shuffle();
     discardedCards = new CardsCollection();
 }
    public static OneOfEachUnlockedCardInClassDeckBuilder Create(Classes classe)
    {
        Card[] allCardsOfClass    = ClassInfo.GetCardsOfClass(classe);
        Card[] unlockedPrototypes = CardsCollection.GetUnlockedCardsFrom(allCardsOfClass);
        OneOfEachUnlockedCardInClassDeckBuilder builder = new OneOfEachUnlockedCardInClassDeckBuilder(unlockedPrototypes.Length);

        builder.unlockedCardPrototypes = unlockedPrototypes;
        return(builder);
    }
 public bool RemoveCardFromTop()
 {
     if (CardsCollection.Count > 0)
     {
         CardsCollection.RemoveAt(0);
         return(true);
     }
     return(false);
 }
Exemple #15
0
 public PokerHand(HoleCards holeCards, CardsCollection board)
 {
     HoleCards  = holeCards;
     Board      = board;
     _pokerHand = holeCards.ToLong();
     foreach (var card in Board)
     {
         _pokerHand |= Convert.ToInt64(card.AbsoluteValue);
     }
     Kickers = new CardsCollection();
 }
Exemple #16
0
 public Table(int capacity)
 {
     Capacity = capacity;
     Players  = new List <Player>(capacity);
     Seats    = new List <Seat>(capacity);
     for (int i = 0; i < capacity; i++)
     {
         Seats.Add(new Seat(i));
     }
     Board = new CardsCollection(NumberOfBoardCards);
     Turn  = 0;
 }
Exemple #17
0
 public Table(int capacity)
 {
     Capacity = capacity;
     Players = new List<Player>(capacity);
     Seats = new List<Seat>(capacity);
     for (int i = 0; i < capacity; i++)
     {
         Seats.Add(new Seat(i));
     }
     Board = new CardsCollection(NumberOfBoardCards);
     Turn = 0;
 }
Exemple #18
0
 public void Close()
 {
     Dealer.Table = null;
     Dealer.Deck  = null;
     Dealer       = null;
     foreach (var seat in Seats)
     {
         seat.RemovePlayer();
     }
     Players  = new List <Player>(Capacity);
     Board    = new CardsCollection(NumberOfBoardCards);
     IsOpened = false;
 }
        public async Task <CardsCollection> CreateAsync(CardsCollection collectionToAdd)
        {
            var id         = Guid.NewGuid();
            var collection = collectionToAdd;

            collection.Id = id;

            await context.Collections.AddAsync(collection);

            await context.SaveChangesAsync();

            return(collection);
        }
        private bool FieldsAreFilled(CardsCollection collectionToCheck)
        {
            var type = collectionToCheck.GetType();

            foreach (var property in type.GetProperties())
            {
                if (property.Name != "Id" && property.GetValue(collectionToCheck) == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #21
0
    IEnumerator DelayedStart()
    {
        // Wait for the DeckPrototypeFactory to PopulateArrayOfAllCardPrototypes.
        yield return(null);

        cards = CardsCollection.GetClonesOfCardsOnPlayerCollection();

        InitializeSlotsAndRectSize(amountOfSlots: cards.Length);
        PopulateAmountOfEachCard();
        PopulateCardAmountTexts();
        RefreshCardsStats();
        PopulateSlotsWithCards();
        DeactivateBlockedCardsAndResize();
    }
Exemple #22
0
    // TODO: Make DeckBuilder for this
    public static Card[] Get2DifferentRandomUnlockedNotMonsterCards(int deckSize)
    {
        Card[] notMonstersUnlocked = CardsCollection.GetUnlockedCardsFrom(CardPrototypesAccessor.notMonsterPrototypes);
        Card[] cards = new Card[2];

        cards[0] = notMonstersUnlocked[Random.Range(0, notMonstersUnlocked.Length)].GetClone();

        do
        {
            cards[1] = notMonstersUnlocked[Random.Range(0, notMonstersUnlocked.Length)].GetClone();
        } while (cards[0].IsAnotherInstanceOf(cards[1]));

        return(cards);
    }
        public CardsCollection CreateCollection(Guid userId, string collectionName)
        {
            FieldsAreFilled(userId, collectionName);

            var cardCollection = new CardsCollection
            {
                UserId       = userId,
                CreationDate = DateTime.UtcNow,
                Name         = collectionName,
                CardItems    = new List <Guid>()
            };

            return(cardCollection);
        }
        public PlayAction PlayCard(IList <Card> allowedCards, IList <Card> currentTrickCards)
        {
            var sb = new StringBuilder();
            var allowedCardsList = new CardsCollection(allowedCards);

            allowedCardsList.Sort(this.Contract.Type);
            for (int i = 0; i < allowedCardsList.Count; i++)
            {
                sb.AppendFormat("{0}({1}); ", i + 1, allowedCardsList[i]);
            }

            // this.Draw();
            while (true)
            {
                var action = new PlayAction();
                ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3);
                ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2);
                ConsoleHelper.WriteOnPosition(sb.ToString().Trim(), 0, Settings.ConsoleHeight - 2);
                ConsoleHelper.WriteOnPosition("It's your turn! Please select card to play: ", 0, Settings.ConsoleHeight - 3);
                var cardIndexAsString = Console.ReadLine();
                int cardIndex;

                if (int.TryParse(cardIndexAsString, out cardIndex))
                {
                    if (cardIndex > 0 && cardIndex <= allowedCardsList.Count)
                    {
                        var cardToPlay = allowedCardsList[cardIndex - 1];
                        action.Card = cardToPlay;

                        if (this.hand.IsBeloteAllowed(Contract, currentTrickCards, cardToPlay))
                        {
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3);
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2);
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 1);
                            ConsoleHelper.WriteOnPosition("Y(es) / N(o)", 0, Settings.ConsoleHeight - 2);
                            ConsoleHelper.WriteOnPosition("You have belote! Do you want to announce it? Y/N ", 0, Settings.ConsoleHeight - 3);
                            var answer = Console.ReadLine();

                            if (!string.IsNullOrWhiteSpace(answer) && answer.Trim()[0] == 'N')
                            {
                                action.AnnounceBeloteIfAvailable = false;
                            }
                        }

                        this.hand.Remove(cardToPlay);
                        return(action);
                    }
                }
            }
        }
Exemple #25
0
    private void DeactivateBlockedCardsAndResize()
    {
        int deactivatedSlotsAmount = 0;
        int totalAmountOfCards     = amountOfEachCard.Length;

        for (int c = 0; c < totalAmountOfCards; c++)
        {
            if (CardsCollection.IsCardLocked(c))
            {
                slots[c].gameObject.SetActive(false);
                deactivatedSlotsAmount++;
            }
        }
        SetHorizontalSizeOfRect(amountOfSlots: totalAmountOfCards - deactivatedSlotsAmount);
    }
 private void ValidateCollection(CardsCollection collectionToValidate)
 {
     if (!FieldsAreFilled(collectionToValidate))
     {
         throw new AppException("Not enough information");
     }
     if (CheckStringFilled(collectionToValidate.Name))
     {
         throw new AppException(nameof(collectionToValidate.Name) + " is required");
     }
     if (!LengthIsCorrect(collectionToValidate.Name, MinimumNameLength, MaximumNameLength))
     {
         throw new AppException("Collection name length \"" + collectionToValidate.Name + "\" is incorrect");
     }
 }
Exemple #27
0
        public void CardsCollection_ToString()
        {
            var cards = new CardsCollection()
            {
                new Card("Ah"),
                new Card("2s"),
                new Card("7d"),
                new Card("Ts"),
                new Card("Jc")
            };

            Assert.Equal("Ah 2s 7d Ts Jc", cards.ToString());
            cards.Add(new Card("Ac"));
            Assert.Equal("Ah 2s 7d Ts Jc Ac", cards.ToString());
        }
        public async Task <bool> AddCollectionAsync(CardsCollection collectionToAdd)
        {
            ValidateCollection(collectionToAdd);

            try
            {
                await repository.CreateAsync(collectionToAdd);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemple #29
0
        public void CardsCollection_Sort()
        {
            var cards = new CardsCollection()
            {
                new Card("Qd"),
                new Card("Ah"),
                new Card("2s"),
                new Card("7d"),
                new Card("Ts"),
                new Card("Jc")
            };

            cards.Sort();
            Assert.Equal("Ah Qd Jc Ts 7d 2s", cards.ToString());
        }
Exemple #30
0
 private void ValidateCollection(CardsCollection collectionToValidate)
 {
     if (!FieldsAreFilled(collectionToValidate))
     {
         throw new AppException("Недостаточно информации про пользователя");
     }
     if (CheckStringFilled(collectionToValidate.Name))
     {
         throw new AppException(nameof(collectionToValidate.Name) + " не указано");
     }
     if (!LengthIsCorrect(collectionToValidate.Name, MinimumNameLength, MaximumNameLength))
     {
         throw new AppException($"Некорректная длина в \"имени\" коллекциии " +
                                $", должна быть от {MinimumNameLength} до {MaximumNameLength}");
     }
 }
Exemple #31
0
    private static Card[] ReplaceMonsters(Card[] playerDeck)
    {
        Card[] notMonstersUnlocked = CardsCollection.GetUnlockedCardsFrom(CardPrototypesAccessor.notMonsterPrototypes);
        for (int i = 0; i < playerDeck.Length; i++)
        {
            if (playerDeck[i].Classe == Classes.MONSTER)
            {
                Object.Destroy(playerDeck[i].gameObject);

                int randomIndex = UnityEngine.Random.Range(0, notMonstersUnlocked.Length);
                playerDeck[i] = notMonstersUnlocked[randomIndex].GetClone();
            }
        }

        return(playerDeck);
    }
        public DealManager(GameManager game)
        {
            this.game = game;

            this.cardDeck = new Queue<Card>(CardsCollection.FullDeckOfCards);

            this.playerCards = new[] { new Hand(), new Hand(), new Hand(), new Hand() }; // 4 players

            this.southNorthPlayersCardsTaken = new CardsCollection();
            this.eastWestPlayersCardsTaken = new CardsCollection();

            this.southNorthBelotes = 0;
            this.eastWestBelotes = 0;

            this.southNorthTeamTakesLastHand = null;
        }
Exemple #33
0
 public void UpdateTurn()
 {
     Board = new CardsCollection(NumberOfBoardCards);
     Turn++;
 }
 /// <summary>
 /// Returns a CardsCollection collection of cards of type
 /// </summary>
 /// <param name="cardTypeName"></param>
 /// <returns></returns>
 public CardsCollection GetCardsOfType(string cardTypeName)
 {
     var cards = new CardsCollection(MingleProject, _model);
     MingleProject.GetCardsOfType(cardTypeName).ToList().ForEach(c => cards.Add(new Card(c, _model)));
     return cards;
 }
 /// <summary>
 /// Returns a CardsCollection collection for cards for view of name
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public CardsCollection GetView(string name)
 {
     var cards = new CardsCollection(MingleProject, _model);
     MingleProject.GetView(name).ToList().ForEach(c => cards.Add(new Card(c, _model)));
     return cards;
 }
        private PlayAction PlayCard(IPlayer player, Contract contract, IList<Card> currentTrickCards)
        {
            // Prepare played cards and allowed cards
            var currentPlayerCards = this.playerCards[(int)this.game[player]];
            var allowedCards = new CardsCollection(currentPlayerCards.GetAllowedCards(contract, currentTrickCards));

            // Play card
            var playAction = player.PlayCard(allowedCards.ToList(), currentTrickCards.ToList());

            // Check for invalid card
            if (!allowedCards.Contains(playAction.Card))
            {
                throw new InvalidPlayerActionException(player, string.Format("Invalid card: {0}", playAction.Card));
            }

            // Save belote to team points
            playAction.Belote = false;
            if (playAction.AnnounceBeloteIfAvailable && currentPlayerCards.IsBeloteAllowed(contract, currentTrickCards, playAction.Card))
            {
                switch (this.game[player])
                {
                    case PlayerPosition.South:
                        this.southNorthBelotes++;
                        break;
                    case PlayerPosition.East:
                        this.eastWestBelotes++;
                        break;
                    case PlayerPosition.North:
                        this.southNorthBelotes++;
                        break;
                    case PlayerPosition.West:
                        this.eastWestBelotes++;
                        break;
                }

                playAction.Belote = true;
            }

            // Remove played card from the players cards
            this.playerCards[(int)this.game[player]].Remove(playAction.Card);
            return playAction;
        }
        public PlayAction PlayCard(IList<Card> allowedCards, IList<Card> currentTrickCards)
        {
            var sb = new StringBuilder();
            var allowedCardsList = new CardsCollection(allowedCards);
            allowedCardsList.Sort(this.Contract.Type);
            for (int i = 0; i < allowedCardsList.Count; i++)
            {
                sb.AppendFormat("{0}({1}); ", i + 1, allowedCardsList[i]);
            }

            // this.Draw();
            while (true)
            {
                var action = new PlayAction();
                ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3);
                ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2);
                ConsoleHelper.WriteOnPosition(sb.ToString().Trim(), 0, Settings.ConsoleHeight - 2);
                ConsoleHelper.WriteOnPosition("It's your turn! Please select card to play: ", 0, Settings.ConsoleHeight - 3);
                var cardIndexAsString = Console.ReadLine();
                int cardIndex;

                if (int.TryParse(cardIndexAsString, out cardIndex))
                {
                    if (cardIndex > 0 && cardIndex <= allowedCardsList.Count)
                    {
                        var cardToPlay = allowedCardsList[cardIndex - 1];
                        action.Card = cardToPlay;

                        if (this.hand.IsBeloteAllowed(Contract, currentTrickCards, cardToPlay))
                        {
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3);
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2);
                            ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 1);
                            ConsoleHelper.WriteOnPosition("Y(es) / N(o)", 0, Settings.ConsoleHeight - 2);
                            ConsoleHelper.WriteOnPosition("You have belote! Do you want to announce it? Y/N ", 0, Settings.ConsoleHeight - 3);
                            var answer = Console.ReadLine();

                            if (!string.IsNullOrWhiteSpace(answer) && answer.Trim()[0] == 'N')
                            {
                                action.AnnounceBeloteIfAvailable = false;
                            }
                        }

                        this.hand.Remove(cardToPlay);
                        return action;
                    }
                }
            }
        }
 public void TestInitialize()
 {
     fullDeck = CardsCollection.FullDeckOfCards;
 }
 /// <summary>
 /// Wraps MingleProject.GetCards(filters)
 /// </summary>
 /// <param name="filters"></param>
 /// <returns></returns>
 public CardsCollection GetCards(Collection<string> filters)
 {
     var cards = new CardsCollection(_project, _model);
     _project.GetCards(filters).ToList().ForEach(c => cards.Add(new Card(c, _model)));
     return cards;
 }
 /// <summary>
 /// Creates an belot combination of cards
 /// </summary>
 /// <param name="cards">cards that the combination consists of</param>
 /// <param name="points">point evaluation of the combination</param>
 public BelotCombination( CardsCollection cards, int points )
     : base(cards, points)
 {
     this.IsCounted = true;
 }
Exemple #41
0
 public void Close()
 {
     Dealer.Table = null;
     Dealer.Deck = null;
     Dealer = null;
     foreach (var seat in Seats)
     {
         seat.RemovePlayer();
     }
     Players = new List<Player>(Capacity);
     Board = new CardsCollection(NumberOfBoardCards);
     IsOpened = false;
 }
        public void TestDeck_SortCards_ShouldPass()
        {
            var shufledCards = new Queue<SimpleCard>(fullDeck);
            shufledCards.Shuffle();

            var deck = new CardsCollection();
            foreach (var card in shufledCards)
            {
                deck.Add(card);
            }
            System.Console.WriteLine();
            var sortedDeck = deck.OrderBy(x => x);
            SimpleCard checkCard = null;
            foreach (var item in sortedDeck)
            {
                checkCard = item as SimpleCard;
                break;
            }
            SimpleCard firstCard = new SimpleCard(CardType.Two, Suit.Clubs);
            bool areSame = checkCard.Equals(firstCard);

            Assert.IsTrue(areSame);
        }