Exemple #1
0
        public async Task DrawCardAsync()
        {
            if (HasPlayedCard())
            {
                await UIPlatform.ShowMessageAsync("Sorry, you must choose to either play the cards or put them back before drawing another card");

                return;
            }
            bool wasEnd = DeckPile !.IsEndOfDeck();

            if (wasEnd)
            {
                var thisCol = _model !.Discard !.DiscardList();
                if (_model.Discard.PileEmpty() == false)
                {
                    thisCol.Add(_model.Discard.GetCardInfo());
                }
                if (_model.CurrentPile !.PileEmpty() == false)
                {
                    thisCol.Add(_model.CurrentPile.GetCardInfo());
                }
                _model.CurrentPile.ClearCards();
                _model.Discard.ClearCards();
                _model.DeckPile.OriginalList(thisCol);
            }
            var thisCard = _model !.DeckPile.DrawCard();

            if (_model.CurrentPile !.PileEmpty())
            {
                _model.CurrentPile.AddCard(thisCard);
            }
        public override bool CanAddCard(int pile, SolitaireCard thisCard)
        {
            if (GlobalClass.MainModel !.DeckPile !.IsEndOfDeck() && pile > 1)
            {
                return(base.CanAddCard(pile, thisCard));
            }
            if (GlobalClass.MainModel !.DeckPile.IsEndOfDeck())
            {
                return(CanBuildFromKing(pile, thisCard));
            }
            if (GlobalClass.MainModel !.WastePiles1 !.OneSelected() == -1)
            {
                throw new BasicBlankException($"No card selected for placing to {pile}");
            }
            if (GlobalClass.MainModel !.WastePiles1.OneSelected() <= 3)
            {
                if (pile > 1)
                {
                    return(base.CanAddCard(pile, thisCard));
                }
                return(CanBuildFromKing(pile, thisCard));
            }
            int oldPile = GlobalClass.MainModel !.WastePiles1.OneSelected() - 4;

            if (oldPile != pile)
            {
                return(false);
            }
            if (pile > 1)
            {
                return(base.CanAddCard(pile, thisCard));
            }
            return(CanBuildFromKing(pile, thisCard));
        }
Exemple #3
0
        public PokerMainViewModel(IEventAggregator aggregator,
                                  CommandContainer commandContainer,
                                  IGamePackageResolver resolver
                                  )
        {
            GlobalClass.PokerList.Clear(); //can't be brand new  that could cause the connection to break too.
            _aggregator      = aggregator; //this time no new game.  just close out when you are done now.
            Round            = 1;
            CommandContainer = commandContainer;
            CommandContainer.ExecutingChanged += CommandContainer_ExecutingChanged; //hopefully no problem (?)
            DeckPile = resolver.ReplaceObject <DeckObservablePile <PokerCardInfo> >();
            DeckPile.DeckClickedAsync += DeckPile_DeckClickedAsync;
            DeckPile.NeverAutoDisable  = true;
            DeckPile.SendEnableProcesses(this, () =>
            {
                return(!IsRoundOver);
            });

            Bet1 = new NumberPicker(commandContainer, resolver);
            Bet1.SendEnableProcesses(this, () =>
            {
                return(!BetPlaced);
            });
            Bet1.LoadNumberList(new CustomBasicList <int>()
            {
                5, 10, 25
            });
            Bet1.SelectNumberValue(5); //something else has to set to large (?)
            Bet1.ChangedNumberValueAsync += Bet1_ChangedNumberValueAsync;

            _mainGame = resolver.ReplaceObject <PokerMainGameClass>(); //hopefully this works.  means you have to really rethink.
        }
Exemple #4
0
        /// <summary>
        /// Removes the given card from the deck.
        /// </summary>
        /// <param name="c">The card to remove.</param>
        /// <param name="num">The number of the card to remove. If the number is negative then all copies of the provided card will be removed.</param>
        /// <param name="from">Subpiles of the deck that the cards are allowed to be withdrawn from. If more than one is specified then cards will be removed starting from the missing pile, then the discard pile, then the draw pile (assuming the associated pile is allowed).</param>
        /// <returns>Returns the number of cards actually removed from the deck.</returns>
        public uint RemoveCard(Card c, int num = 1, DeckPile from = DeckPile.ALL_PILES)
        {
            if (num < 0)
            {
                num = deck.Count;
            }

            uint ret = 0;

            if ((from & DeckPile.MISSING_PILE) == DeckPile.MISSING_PILE)
            {
                while (ret < num)
                {
                    if (missing_cards.Remove(c))
                    {
                        deck.Remove(c);                         // We found the card in a subpile so it must be in the deck
                        ret++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if ((from & DeckPile.DISCARD_PILE) == DeckPile.DISCARD_PILE)
            {
                while (ret < num)
                {
                    if (discard_pile.Remove(c))
                    {
                        deck.Remove(c);
                        ret++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if ((from & DeckPile.DRAW_PILE) == DeckPile.DRAW_PILE)
            {
                while (ret < num)
                {
                    if (draw_pile.Remove(c))
                    {
                        deck.Remove(c);
                        ret++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(ret);
        }
Exemple #5
0
        /// <summary>
        /// Adds the given cards to the deck.
        /// </summary>
        /// <param name="c">The cards to add.</param>
        /// <param name="from">Subpiles of the deck that the cards are allowed to be added to. If more than one is specified then piles have priority as follows: draw pile then the discard pile. Cards can not be added to the missing pile and if specified it will be ignored.</param>
        public void AddCards(IList <Card> c, DeckPile to = DeckPile.DRAW_PILE)
        {
            foreach (Card card in c)
            {
                AddCard(card, to);
            }

            return;
        }
Exemple #6
0
        /// <summary>
        /// Temporarily stores the card, adds it to the discard pile, removes the real card object from the deck pile and
        /// returns the card
        /// </summary>
        /// <returns></returns>
        public T DrawNextCard()
        {
            T card = DeckPile[Count - 1];

            DiscardPile.Add(card);
            DeckPile.RemoveAt(Count - 1);

            if (Count == 0)
            {
                ReShuffleDeck();
            }
            return(card);
        }
        /// <summary>
        /// Creates 52 cards times the parameter "decks" and adds them into a deck (list)
        /// </summary>
        /// <param name="decks"></param>
        public void InitDeck(int decks)
        {
            DeckPile.Clear();
            DiscardPile.Clear();
            cardList.Clear();

            for (int countDecks = 0; countDecks < decks; countDecks++)
            {
                for (int index = 0; index < PlayingCards.Count; index++)
                {
                    cardList.Add(new Card(values[index], images[index]));
                }
            }
            AddCards(cardList);
        }
Exemple #8
0
        /// <summary>
        /// Removes the given cards from the deck.
        /// </summary>
        /// <param name="c">The cards to remove.</param>
        /// <param name="num">The numbers of the cards to remove. If a number is negative then all copies of the appropriate card will be removed.</param>
        /// <param name="from">Subpiles of the deck that the cards are allowed to be withdrawn from. If more than one is specified then cards will be removed starting from the missing pile, then the discard pile, then the draw pile (assuming the associated pile is allowed).</param>
        /// <returns>Returns the number of cards actually removed from the deck for each card.</returns>
        /// <exception cref="ArgumentException">Thrown if the length of card list and number list are different.</exception>
        public IList <uint> RemoveCards(IList <Card> c, IList <int> num, DeckPile from = DeckPile.ALL_PILES)
        {
            if (c.Count != num.Count)
            {
                throw new ArgumentException("List lengths not equal.");
            }

            List <uint> ret = new List <uint>(num.Count);

            for (int i = 0; i < c.Count; i++)
            {
                ret.Add(RemoveCard(c[i], num[i], from));
            }

            return(ret);
        }
Exemple #9
0
        }                                                            // See lambda expressions

        /// <summary>
        /// Adds the given card to the deck.
        /// </summary>
        /// <param name="c">The card to add.</param>
        /// <param name="from">Subpiles of the deck that the cards are allowed to be added to. If more than one is specified then piles have priority as follows: draw pile then the discard pile. Cards can not be added to the missing pile and if specified it will be ignored.</param>
        public void AddCard(Card c, DeckPile to = DeckPile.DRAW_PILE)
        {
            if ((to & DeckPile.DRAW_PILE) == DeckPile.DRAW_PILE)            // Bitwise operations have low priority
            {
                draw_pile.Add(c.Clone());
            }
            else if ((to & DeckPile.DISCARD_PILE) == DeckPile.DISCARD_PILE)
            {
                discard_pile.Add(c.Clone());
            }
            else
            {
                return;                 // We need to skip the deck add
            }
            deck.Add(c.Clone());
            return;
        }
Exemple #10
0
        public HeapSolitaireMainViewModel(IEventAggregator aggregator,
                                          CommandContainer commandContainer,
                                          IGamePackageResolver resolver
                                          )
        {
            _aggregator      = aggregator;
            CommandContainer = commandContainer;
            CommandContainer.ExecutingChanged += CommandContainer_ExecutingChanged; //hopefully no problem (?)
            DeckPile = resolver.ReplaceObject <DeckObservablePile <HeapSolitaireCardInfo> >();
            DeckPile.DeckClickedAsync += DeckPile_DeckClickedAsync;
            DeckPile.NeverAutoDisable  = true;
            _aggregator.Subscribe(this);
            DeckPile.SendEnableProcesses(this, () =>
            {
                return(false);
            });
            _mainGame = resolver.ReplaceObject <HeapSolitaireMainGameClass>(); //hopefully this works.  means you have to really rethink.

            Waste1 = new WastePiles(CommandContainer, _aggregator, _mainGame);
            Waste1.PileClickedAsync += Waste1_PileClickedAsync;
            Main1 = new MainPiles(CommandContainer, _aggregator, _mainGame);
            Main1.PileClickedAsync += Main1_PileClickedAsync;
        }
Exemple #11
0
        public PyramidSolitaireMainViewModel(IEventAggregator aggregator,
                                             CommandContainer commandContainer,
                                             IGamePackageResolver resolver
                                             )
        {
            _aggregator      = aggregator;
            CommandContainer = commandContainer;
            CommandContainer.ExecutingChanged += CommandContainer_ExecutingChanged; //hopefully no problem (?)
            DeckPile = resolver.ReplaceObject <DeckObservablePile <SolitaireCard> >();
            DeckPile.DeckClickedAsync += DeckPile_DeckClickedAsync;
            DeckPile.NeverAutoDisable  = true;
            aggregator.Subscribe(this);
            DeckPile.SendEnableProcesses(this, () =>
            {
                if (_mainGame.GameGoing == false)
                {
                    return(false);
                }
                return(true);                                                     //if other logic is needed for deck, put here.
            });
            _mainGame = resolver.ReplaceObject <PyramidSolitaireMainGameClass>(); //hopefully this works.  means you have to really rethink.

            CurrentPile = new PileObservable <SolitaireCard>(_aggregator, commandContainer);
            CurrentPile.SendEnableProcesses(this, () => CurrentPile.PileEmpty() == false);
            CurrentPile.Text              = "Current";
            CurrentPile.CurrentOnly       = true;
            CurrentPile.PileClickedAsync += CurrentPile_PileClickedAsync;
            Discard = new PileObservable <SolitaireCard>(_aggregator, CommandContainer);
            Discard.SendEnableProcesses(this, () => Discard.PileEmpty() == false);
            Discard.Text              = "Discard";
            Discard.PileClickedAsync += Discard_PileClickedAsync;
            PlayList1 = new PlayList(CommandContainer, aggregator);
            PlayList1.SendEnableProcesses(this, () => PlayList1.HasChosenCards());
            PlayList1.Visible = true;
            GameBoard1        = new TriangleBoard(this, CommandContainer, resolver, _mainGame);
        }
Exemple #12
0
 /// <summary>
 /// Reshuffle all the cards into the deck
 /// </summary>
 public void ReShuffleDeck()
 {
     DeckPile.AddRange(DiscardPile);
     DiscardPile.Clear();
     ShuffleDeck();
 }
Exemple #13
0
 /// <summary>
 /// Add cards to the deck
 /// </summary>
 /// <param name="cardList"></param>
 public void AddCards(List <T> cardList)
 {
     DeckPile.AddRange(cardList);
 }