private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         PopulateControls();
         return;
     }
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         if (e.OldItems.Count != 1)
         {
             throw new BasicBlankException("Only One Item Can Be Removed");
         }
         var thisCard     = e.OldItems[0] as HeapSolitaireCardInfo;
         var thisGraphics = FindControl(thisCard);
         _thisGrid !.Children.Remove(thisGraphics);
         if (_cardList !.Count > 0)
         {
             _currentCard            = _cardList.Last();
             _currentCard.IsSelected = true;
             return;
         }
         _thisGrid.Children.Clear();
     }
 }
Exemple #2
0
        private int WhoWonTrick(DeckObservableDict <SkuckCardGameCardInformation> thisCol)
        {
            if (thisCol.Count != 2)
            {
                throw new BasicBlankException("The trick list must have 2 cards");
            }
            var leadCard  = thisCol.First();
            int begins    = leadCard.Player;
            var otherCard = thisCol.Last();

            if (otherCard.Suit == SaveRoot !.TrumpSuit && leadCard.Suit != SaveRoot.TrumpSuit && CanConsiderTrump(otherCard) == true)
            {
                return(WhoTurn);
            }
            if (leadCard.Suit == SaveRoot.TrumpSuit && otherCard.Suit != SaveRoot.TrumpSuit && CanConsiderTrump(otherCard) == true)
            {
                return(begins);
            }
            if (leadCard.Suit == otherCard.Suit)
            {
                if (otherCard.Value > leadCard.Value)
                {
                    return(WhoTurn);
                }
            }
            return(begins);
        }
        private int WhoWonTrick(DeckObservableDict <RoundsCardGameCardInformation> thisCol)
        {
            var leadCard    = thisCol.First();
            var thisCard    = thisCol.Last();
            var tempCard    = _model !.Pile1 !.GetCardInfo();
            var trumpSuit   = tempCard.Suit;
            var trumpNumber = tempCard.Value;

            if (thisCard.Value == trumpNumber)
            {
                return(WhoTurn);
            }
            if (leadCard.Value == trumpNumber)
            {
                return(leadCard.Player);
            }
            if (thisCard.Suit == trumpSuit && thisCard.Suit != leadCard.Suit)
            {
                return(WhoTurn);
            }
            if (leadCard.Suit == trumpSuit && thisCard.Suit != leadCard.Suit)
            {
                return(leadCard.Player);
            }
            if (thisCard.Suit == leadCard.Suit)
            {
                if (thisCard.Value > leadCard.Value)
                {
                    return(WhoTurn);
                }
            }
            return(leadCard.Player);
        }
        private void ResetCards(bool wasUpdate)
        {
            var thisCard = GetCard(0);

            thisCard.BindingContext   = null;
            thisCard.BindingContext   = _cardList.First();
            thisCard.CommandParameter = _cardList.First();
            if (wasUpdate == false)
            {
                thisCard.IsUnknown = true;
            }
            thisCard = GetCard(1);
            thisCard.BindingContext = null;
            thisCard.BindingContext = _cardList.Last();
            if (wasUpdate == false)
            {
                thisCard.IsUnknown = true; // maybe had to do manually
            }
            thisCard.CommandParameter = _cardList.Last();
        }
Exemple #5
0
 private void RecalculatePositioning()
 {
     if (_objectList == null)
     {
         return;
     }
     foreach (var thisObject in _objectList)
     {
         var thisDeck = FindControl(thisObject);
         if (thisDeck != null)
         {
             if (thisObject.Equals(_objectList.Last()) == false)
             {
                 CalculateMargins(thisDeck);
             }
             else
             {
                 thisDeck.Margin = new Thickness(6, 0, 6, 0);
             }
         }
     }
 }
Exemple #6
0
        private void PopulateControls()
        {
            _thisGrid !.ColumnDefinitions.Clear();
            _thisGrid.Children.Clear();
            if (_cardList !.Count == 0)
            {
                return;
            }
            var pixels = _widthUsed / 4;
            int totals = _cardList.Count + 3;

            totals.Times(x => AddPixelColumn(_thisGrid, (int)pixels));
            int y, m;

            if (_isReversed)
            {
                y = _cardList.Count;
                //d = -1;
                m = 0;
            }
            else
            {
                y = 0;
                //d = 1;
                m = _cardList.Count;
            }
            _cardList.ForEach(thisCard =>
            {
                var thisGraphics = GetNewCard(thisCard);
                AddControlToGrid(_thisGrid, thisGraphics, 0, y);
                Grid.SetColumnSpan(thisGraphics, 4);
                if (_isReversed)
                {
                    y--;
                }
                else
                {
                    y++;
                }
            });
            if (_isReversed)
            {
                _currentCard = _cardList.Last();
            }
            else
            {
                _currentCard = _cardList.First();
            }
            _currentCard.IsSelected = _thisMod !.IsSelected;
        }
        public void Init(BasicTrickAreaObservable <SU, TC> thisMod, string tagUsed)
        {
            if (thisMod.CardList.Count != 2)
            {
                throw new BasicBlankException("Only 2 are supported for 2 player trick taking games.  Otherwise, try using another trick taking control");
            }
            BindingContext = thisMod;
            _thisMod       = thisMod;
            _cardList      = thisMod.CardList;
            _cardList.CollectionChanged += CardList_CollectionChanged;
            float startTop;
            float firstLeft;

            startTop  = 3;
            firstLeft = 3;
            float cardTop;

            cardTop = 33; // if changing, will be here
            var thisLabel = GetLabel("Your Card Played");

            _thisCanvas.Children.Add(thisLabel);
            var thisRect = new Rectangle(firstLeft, firstLeft, thisLabel.WidthRequest, thisLabel.HeightRequest);

            AbsoluteLayout.SetLayoutBounds(thisLabel, thisRect);
            GW      thisCard = new GW();
            Binding thisBind = new Binding(nameof(BasicTrickAreaObservable <SU, TC> .CardSingleClickCommand));

            thisBind.Source = thisMod;                                      // has to be that one
            thisCard.SetBinding(GraphicsCommand.CommandProperty, thisBind); //i think
            thisCard.SendSize(tagUsed, _cardList.First());                  //hopefully this simple.
            thisCard.CommandParameter = _cardList.First();                  // this needs to be the parameter.
            _thisCanvas.Children.Add(thisCard);
            thisRect = new Rectangle(10, cardTop, thisCard.ObjectSize.Width, thisCard.ObjectSize.Height);
            AbsoluteLayout.SetLayoutBounds(thisCard, thisRect);
            thisLabel = GetLabel("Opponent Card Played");
            _thisCanvas.Children.Add(thisLabel);
            thisRect = new Rectangle(150, startTop, thisLabel.WidthRequest, thisLabel.HeightRequest);
            AbsoluteLayout.SetLayoutBounds(thisLabel, thisRect);
            thisCard = new GW();
            thisCard.SendSize(tagUsed, _cardList.Last()); //hopefully this simple.
            _thisCanvas.Children.Add(thisCard);
            thisRect = new Rectangle(170, cardTop, thisCard.ObjectSize.Width, thisCard.ObjectSize.Height);
            AbsoluteLayout.SetLayoutBounds(thisCard, thisRect);
            Binding FinalBind = new Binding(nameof(BasicTrickAreaObservable <SU, TC> .Visible));

            SetBinding(IsVisibleProperty, FinalBind);
            Content = _thisCanvas; // this is the content for this page.
        }
        public void Init(BasicTrickAreaObservable <SU, TC> thisMod, string tagUsed)
        {
            if (thisMod.CardList.Count != 2)
            {
                throw new BasicBlankException("Only 2 are supported for 2 player trick taking games.  Otherwise, try using another trick taking control");
            }
            DataContext = thisMod;
            _thisMod    = thisMod;
            _cardList   = thisMod.CardList;
            _cardList.CollectionChanged += CardList_CollectionChanged;
            float startTop;
            float firstLeft;

            startTop  = 3;
            firstLeft = 3;
            float cardTop;

            cardTop = 33; // if changing, will be here
            var thisLabel = GetLabel("Your Card Played");

            _thisCanvas.Children.Add(thisLabel);
            Canvas.SetLeft(thisLabel, firstLeft);
            Canvas.SetTop(thisLabel, startTop);
            GW      thisCard = new GW();
            Binding thisBind = new Binding(nameof(BasicTrickAreaObservable <SU, TC> .CardSingleClickCommand));

            thisBind.Source = thisMod;                                                    // has to be that one
            thisCard.SetBinding(BaseDeckGraphicsWPF <TC, GC> .CommandProperty, thisBind); //i think
            thisCard.SendSize(tagUsed, _cardList.First());                                //hopefully this simple.
            thisCard.CommandParameter = _cardList.First();                                // this needs to be the parameter.
            _thisCanvas.Children.Add(thisCard);
            Canvas.SetTop(thisCard, cardTop);
            Canvas.SetLeft(thisCard, 10); // its manually done.
            thisLabel = GetLabel("Opponent Card Played");
            _thisCanvas.Children.Add(thisLabel);
            Canvas.SetLeft(thisLabel, 250); // try 150.  can always adjust as needed
            Canvas.SetTop(thisLabel, startTop);
            thisCard = new GW();
            thisCard.SendSize(tagUsed, _cardList.Last()); //hopefully this simple.
            _thisCanvas.Children.Add(thisCard);
            Canvas.SetTop(thisCard, cardTop);
            Canvas.SetLeft(thisCard, 270);
            Binding FinalBind = GetVisibleBinding(nameof(BasicTrickAreaObservable <SU, TC> .Visible)); //hopefully no problem (?)

            SetBinding(VisibilityProperty, FinalBind);
            Content = _thisCanvas; // this is the content for this page.
        }
Exemple #9
0
 public void RemoveFromPile()
 {
     if (CurrentCard.Deck == 0)
     {
         throw new BasicBlankException("Cannot remove from discard because there are no cards to remove");
     }
     if (_objectList.Count == 0)
     {
         _previousNum = 0;
         CurrentCard  = new D();
         _thisE.NewCardMessage(EnumNewCardCategories.Discard);
         return;
     }
     CurrentCard = _objectList.Last();
     _objectList.RemoveLastItem();
     _previousNum = _objectList.Count;
 }
        private int WhoWonTrick(DeckObservableDict <GermanWhistCardInformation> thisCol)
        {
            GermanWhistCardInformation leadCard = thisCol.First();
            var thisCard = thisCol.Last();

            if (thisCard.Suit == SaveRoot !.TrumpSuit && leadCard.Suit != SaveRoot.TrumpSuit)
            {
                return(WhoTurn);
            }
            if (leadCard.Suit == SaveRoot.TrumpSuit && thisCard.Suit != SaveRoot.TrumpSuit)
            {
                return(leadCard.Player);
            }
            if (thisCard.Suit == leadCard.Suit)
            {
                if (thisCard.Value > leadCard.Value)
                {
                    return(WhoTurn);
                }
            }
            return(leadCard.Player);
        }
Exemple #11
0
        private int WhoWonTrick(DeckObservableDict <SixtySix2PlayerCardInformation> thisCol)
        {
            var leadCard = thisCol.First();
            var thisCard = thisCol.Last();

            if (thisCard.Suit == SaveRoot !.TrumpSuit && leadCard.Suit != SaveRoot.TrumpSuit)
            {
                return(WhoTurn);
            }
            if (leadCard.Suit == SaveRoot.TrumpSuit && thisCard.Suit != SaveRoot.TrumpSuit)
            {
                return(leadCard.Player);
            }
            if (thisCard.Suit == leadCard.Suit)
            {
                if (thisCard.PinochleCardValue > leadCard.PinochleCardValue)
                {
                    return(WhoTurn);
                }
            }
            return(leadCard.Player);
        }
        private async void CardList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            //bool wasFirst = true;
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                //object firstCard = e.NewItems[0];

                foreach (var thisItem in e.NewItems)
                {
                    var newCard = thisItem as SolitaireCard;
                    //if (wasFirst)
                    //{
                    //    if (_thisStack.HasCard(newCard!))
                    //    {
                    //        _thisStack.Children.Clear();
                    //    }
                    //    wasFirst = false;
                    //}
                    DeckOfCardsXF <SolitaireCard> thisD = new DeckOfCardsXF <SolitaireCard>();
                    thisD.NeedsExtraSuitForSolitaire = true;
                    thisD.SendSize(ts.TagUsed, newCard !);
                    if (_thisStack.HasCard(newCard !) == false)
                    {
                        _thisStack !.Children.Add(thisD);//hopefully this simple (?)
                    }
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Replace)
            {
                if (e.OldItems.Count == e.NewItems.Count)
                {
                    int x = 0;
                    foreach (var thisItem in e.OldItems)
                    {
                        var oldCard = thisItem as SolitaireCard;
                        var newCard = e.NewItems[x] as SolitaireCard;
                        var thisCon = _thisStack.FindControl(oldCard !);
                        thisCon !.BindingContext = null;    //i think this is needed too
                        thisCon.BindingContext   = newCard; //the upperright is iffy.
                        x++;
                    }
                }
                else
                {
                    throw new BasicBlankException("Not sure when the numbers don't match");
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var thisItem in e.OldItems)
                {
                    var oldCard = thisItem as SolitaireCard;
                    var thisCon = _thisStack.FindControl(oldCard !);
                    _thisStack !.Children.Remove(thisCon !);
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                _thisStack.Children.Clear(); // needs to clear and do nothing else because no cards left
                PopulateList();
            }
            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                if (e.OldStartingIndex == e.NewStartingIndex)
                {
                    RefreshItems();
                }
                else
                {
                    var firstCon = _thisStack !.Children[e.OldStartingIndex];
                    _thisStack.Children.Remove(firstCon);
                    _thisStack.Children.Insert(e.NewStartingIndex, firstCon);
                }
            }
            if (_cardList !.Count == 0)
            {
                return;
            }
            var thisCard = _cardList.Last();
            var finCo    = _thisStack.FindControl(thisCard);

            if (finCo == null)
            {
                return;
            }
            await _thisScroll.ScrollToAsync(finCo, ScrollToPosition.End, false);
        }
        private int WhoWonTrick(DeckObservableDict <HorseshoeCardGameCardInformation> thisCol)
        {
            if (thisCol.Count != 4)
            {
                throw new BasicBlankException("Must have 4 cards for the trick list to see who won");
            }
            var thisCard           = thisCol.First();
            int begins             = thisCard.Player;
            EnumCardValueList nums = thisCard.Value;

            if (thisCol.All(Items => Items.Value == nums))
            {
                return(begins);
            }
            DeckRegularDict <HorseshoeCardGameCardInformation> playerStarted = new DeckRegularDict <HorseshoeCardGameCardInformation>();
            DeckRegularDict <HorseshoeCardGameCardInformation> otherPlayer   = new DeckRegularDict <HorseshoeCardGameCardInformation>();

            playerStarted.Add(thisCol.First());
            playerStarted.Add(thisCol.Last());
            otherPlayer.Add(thisCol[1]);
            otherPlayer.Add(thisCol[2]);
            HorseshoeCardGameCardInformation firstCard  = playerStarted.First();
            HorseshoeCardGameCardInformation secondCard = playerStarted.Last();
            EnumSuitList      whichSuit = firstCard.Suit;
            EnumCardValueList pairAmount;
            EnumCardValueList highestSuitNumber = EnumCardValueList.None;
            int possibleWinPlayer = 0;

            if (firstCard.Value == secondCard.Value)
            {
                pairAmount = firstCard.Value;
            }
            else
            {
                pairAmount = EnumCardValueList.None;
                var card = thisCol.Where(x => x.Suit == whichSuit).OrderByDescending(x => x.Value).Take(1).Single();
                highestSuitNumber = card.Value;
                possibleWinPlayer = card.Player;
                //if (secondCard.Value > firstCard.Value && secondCard.Suit == firstCard.Suit)
                //    highestSuitNumber = secondCard.Value;
                //else if (secondCard.Suit == firstCard.Suit)
                //    highestSuitNumber = firstCard.Value;
            }
            firstCard  = otherPlayer.First();
            secondCard = otherPlayer.Last();
            if (firstCard.Value != secondCard.Value && pairAmount > 0)
            {
                return(begins);
            }
            if (firstCard.Value == secondCard.Value)
            {
                if (firstCard.Value > pairAmount)
                {
                    if (begins == 1)
                    {
                        return(2);
                    }
                    return(1);
                }
            }
            if (pairAmount > 0)
            {
                return(begins);
            }

            if (possibleWinPlayer == 0)
            {
                throw new BasicBlankException("Sombody had to win it");
            }
            return(possibleWinPlayer);
            //if (firstCard.Suit == whichSuit)
            //{
            //    if (firstCard.Value > highestSuitNumber)
            //    {
            //        if (begins == 1)
            //            return 2;
            //        return 1;
            //    }
            //}
            //if (secondCard.Suit == whichSuit)
            //{
            //    if (secondCard.Value > highestSuitNumber)
            //    {
            //        if (begins == 1)
            //            return 2;
            //        return 1;
            //    }
            //}
            //return begins;
        }