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(PileInfoCP singlePile, SolitairePilesCP main) { MouseUp += SinglePileUI_MouseUp; _mainMod = main; _thisMod = singlePile; _thisMod.PropertyChanged += PropertyChanged; _cardList = singlePile.CardList; _cardList.CollectionChanged += CollectionChanged; Background = Brushes.Transparent; //this was required too. _thisGrid = new Grid(); Content = _thisGrid; var tempCard = GetNewCard(new SolitaireCard()); _widthUsed = tempCard.ObjectSize.Width; //needs this so we know. PopulateControls(); }
public void Init(HeapSolitaireMainViewModel thisMod, BasicPileInfo <HeapSolitaireCardInfo> thisPile) { _mainMod = thisMod.Waste1; _privateMod = thisPile; _cardList = _privateMod.ObjectList; var tempDeck = GetNewCard(new HeapSolitaireCardInfo()); _pixels = (int)tempDeck.ObjectSize.Width / 4; _cardList.CollectionChanged += CollectionChanged; Background = Brushes.Transparent; //learned from old version of belegured castle that if not set to transparent, clicking does not work. MouseUp += SinglePileUI_MouseUp; _privateMod.PropertyChanged += PropertyChanged; _thisGrid = new Grid(); Content = _thisGrid; PopulateControls(); }
public void UpdateList(PlayerBoardObservable <TR> thisMod) { _thisMod = thisMod; _cardList !.CollectionChanged -= CardList_CollectionChanged; _cardList = thisMod.CardList; _cardList.CollectionChanged += CardList_CollectionChanged; if (thisMod.Game == PlayerBoardObservable <TR> .EnumGameList.None) { throw new BasicBlankException("Must choose Skuck or Horseshoes"); } if (_cardList.Count == 0) { throw new BasicBlankException("Must have cardlist already"); } PopulateControls(); }
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. }
public void LoadList(GameBoardObservable <CA> mod, string tagUsed) { _tagUsed = tagUsed; _thisMod = mod; BindingContext = _thisMod; _objectList = _thisMod.ObjectList; _objectList.CollectionChanged += ObjectList_CollectionChanged; Grid firstGrid = new Grid(); if (_thisMod.HasFrame == true) { firstGrid.Children.Add(ThisDraw); } _mainGrid = new Grid(); _mainGrid.ColumnSpacing = 0; _mainGrid.RowSpacing = 0; firstGrid.Children.Add(_mainGrid); var firstCard = new CA(); // for size if (firstCard.DefaultSize.Height == 0 || firstCard.DefaultSize.Width == 0) { throw new BasicBlankException("The width and height must be greater than 0 when initializging hand wpf"); } IGamePackageResolver thisR = (IGamePackageResolver)cons !; IProportionImage thisI = thisR.Resolve <IProportionImage>(tagUsed); _sizeUsed = firstCard.DefaultSize.GetSizeUsed(thisI.Proportion); SetBinding(TextProperty, new Binding(nameof(GameBoardObservable <CA> .Text))); SetBinding(IsEnabledProperty, new Binding(nameof(GameBoardObservable <CA> .IsEnabled))); SetBinding(IsVisibleProperty, new Binding(nameof(GameBoardObservable <CA> .Visible))); SetUpGrid(); var tempWidth = _sizeUsed.Width * _thisMod.Columns; var tempHeight = _sizeUsed.Height * _thisMod.Rows; if (_thisMod.HasFrame == true) { SetUpMarginsOnParentControl(_mainGrid); } float tops = (float)_mainGrid.Margin.Top + (float)_mainGrid.Margin.Bottom; float lefts = (float)_mainGrid.Margin.Left + (float)_mainGrid.Margin.Right; HeightRequest = tempHeight + tops; WidthRequest = tempWidth + lefts; PopulateList(); Content = firstGrid; }
public void LoadControls(FluxxGameContainer gameContainer) { Text = "Rule Information"; _ruleList = gameContainer.SaveRoot !.RuleList; _ruleList.CollectionChanged += RuleListChange; _stack = new StackPanel(); Grid grid = new Grid(); Width = 200; SKRect rect = ThisFrame.GetControlArea(); SetUpMarginsOnParentControl(_stack, rect); //i think. grid.Children.Add(ThisDraw); grid.Children.Add(_stack); Content = grid; LoadRules(); }
public DeckObservableDict <MilkRunCardInformation> GetPileCardList() { DeckObservableDict <MilkRunCardInformation> output = new DeckObservableDict <MilkRunCardInformation>(); int x; MilkRunCardInformation thisCard; for (x = 1; x <= 2; x++) { if (StrawberryPiles !.HasCard(x) == true) { thisCard = StrawberryPiles.GetLastCard(x); output.Add(thisCard); } if (ChocolatePiles !.HasCard(x) == true) { thisCard = ChocolatePiles.GetLastCard(x); output.Add(thisCard); } } return(output); }
public void LoadList(SE thisSet, string tagUsed) { ScrollView thisScroll = new ScrollView(); thisScroll.Orientation = ScrollOrientation.Vertical; _tagUsed = tagUsed; _thisMod = thisSet; _thisStack = new StackLayout(); _objectList = thisSet.HandList; Grid grid = new Grid(); grid.Children.Add(_thisStack); _drawControl = new SKCanvasView(); grid.Children.Add(_drawControl); _drawControl.EnableTouchEvents = true; _drawControl.Touch += DrawControlTouch; _objectList.CollectionChanged += ObjectList_CollectionChanged; thisScroll.Content = grid; Content = thisScroll; PopulateList(); }
public void Init(ScoreHandCP mod) { _tempMod = mod; _cardList = _tempMod.CardList; _cardList.CollectionChanged += CollectionChanged; _thisGrid = new Grid(); Text = _tempMod.Text; // i think Grid parentGrid = new Grid(); parentGrid.Children.Add(ThisDraw); parentGrid.Children.Add(_thisGrid); SetUpMarginsOnParentControl(_thisGrid); _thisGrid.Margin = new Thickness(_thisGrid.Margin.Left, _thisGrid.Margin.Top + 8, _thisGrid.Margin.Right, _thisGrid.Margin.Bottom); // not sure why did not work well this time (?) AddAutoColumns(_thisGrid, 3); AddAutoRows(_thisGrid, 2); HorizontalOptions = LayoutOptions.Fill; //i think Content = parentGrid; if (_cardList.Count > 0) { PopulateList(); } }
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); }
public void Init(HeapSolitaireMainViewModel thisMod, BasicPileInfo <HeapSolitaireCardInfo> thisPile) { _mainMod = thisMod.Waste1; _privateMod = thisPile; _cardList = _privateMod.ObjectList; var tempDeck = GetNewCard(new HeapSolitaireCardInfo()); _pixels = (int)tempDeck.ObjectSize.Width / 4; _cardList.CollectionChanged += CollectionChanged; _canvas = new SKCanvasView(); _canvas.EnableTouchEvents = true; _canvas.Touch += Touch; Grid grid = new Grid(); _privateMod.PropertyChanged += TempPropertyChanged; _thisGrid = new Grid(); _thisGrid.InputTransparent = true; grid.Children.Add(_thisGrid); grid.Children.Add(_canvas); Content = grid; PopulateControls(); }
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); }
public void Init(RackoMainViewModel viewModel, RackoVMData model, RackoGameContainer gameContainer) { gameContainer.SingleInfo = gameContainer !.PlayerList !.GetSelf(); _cardList = gameContainer.SingleInfo.MainHandList; _thisCommand = viewModel.GetBasicGameCommand(nameof(RackoMainViewModel.PlayOnPileAsync)); Grid mainGrid = new Grid(); _thisStack = new StackLayout(); Text = "Your Card List"; var thisRect = ThisFrame.GetControlArea(); _thisStack.Margin = new Thickness(thisRect.Left + 3, thisRect.Top + 10, 3, 3); if (gameContainer.SingleInfo.MainHandList.Count != 10) { throw new BasicBlankException("Must have 10 cards before i can init. Rethink now."); } _thisCommand !.CanExecuteChanged += ThisCommand_CanExecuteChanged; _cardList.CollectionChanged += CardList_CollectionChanged; PopulateControls(gameContainer); mainGrid.Children.Add(ThisDraw); mainGrid.Children.Add(_thisStack); Content = mainGrid; }
public void Init(PileInfoCP singlePile, SolitairePilesCP main) { Grid otherGrid = new Grid(); _mainMod = main; _thisMod = singlePile; //hopefully property change just works right (?) _thisMod.PropertyChanged += SinglePileUI_PropertyChanged; _cardList = singlePile.CardList; _cardList.CollectionChanged += CollectionChanged; _thisGrid = new Grid(); _thisGrid.InputTransparent = true; otherGrid.Children.Add(_thisGrid); _thisControl = new SKCanvasView(); _thisControl.EnableTouchEvents = true; _thisControl.Touch += TouchEvent; otherGrid.Children.Add(_thisControl); Content = otherGrid; var tempCard = GetNewCard(new SolitaireCard()); _widthUsed = tempCard.ObjectSize.Width; //needs this so we know. PopulateControls(); }
//public void Dispose() //{ // _thisStack.Children.Clear(); //} public void Init(bool NeedsPopulating) { if (ThisPile == null) { throw new BasicBlankException("Must send in the pile being used for this"); } if (MainMod == null) { throw new BasicBlankException("There was no main viewmodel sent for this"); } _cardList = ThisPile.CardList; BindingContext = ThisPile; VerticalOptions = LayoutOptions.StartAndExpand; // had to actually expand. _thisStack.IsKlondike = MainMod.IsKlondike; // needed this as well. _cardList.CollectionChanged += CardList_CollectionChanged; Grid thisGrid = new Grid(); thisGrid.Children.Add(_thisStack); RowClickerXF thisBlank = new RowClickerXF(); thisBlank.Command = MainMod.ColumnCommand; thisBlank.CommandParameter = ThisPile; //hopefully this simple (?) thisBlank.HorizontalOptions = LayoutOptions.Fill; thisBlank.VerticalOptions = LayoutOptions.Fill; thisGrid.Children.Add(thisBlank); //another choice is to let the events handle the populating. _thisScroll = new ScrollView(); _thisScroll.Orientation = ScrollOrientation.Vertical; _thisScroll.InputTransparent = true; _thisScroll.Content = thisGrid; if (NeedsPopulating) { PopulateList(); } Content = _thisScroll; SetBinding(IsSelectedProperty, new Binding(nameof(PileInfoCP.IsSelected))); }
public void LoadList(ScatteringPiecesObservable <CA, LI> mod, string tagUsed) { EventAggregator thisE = Resolve <EventAggregator>(); thisE.Subscribe(this); SetBinding(TextProperty, new Binding(nameof(ScatteringPiecesObservable <CA, LI> .TextToAppear))); SetBinding(IsEnabledProperty, new Binding(nameof(ScatteringPiecesObservable <CA, LI> .IsEnabled))); _thisMod = mod; BindingContext = _thisMod; // so it can do the text and isenabled. _tagUsed = tagUsed; _objectList = mod.RemainingList; _objectList.CollectionChanged += ObjectList_CollectionChanged; _thisCanvas = new AbsoluteLayout(); _thisCanvas.GestureRecognizers.Add(new TapGestureRecognizer()); TapGestureRecognizer tap = (TapGestureRecognizer)_thisCanvas.GestureRecognizers.Single(); tap.NumberOfTapsRequired = 1; tap.Command = _thisMod.BoardCommand; _thisCanvas.HeightRequest = _thisMod.MaxSize.Height; _thisCanvas.WidthRequest = _thisMod.MaxSize.Width; Grid firstGrid = new Grid(); firstGrid.Children.Add(ThisDraw); ScrollView thisScroll = new ScrollView(); thisScroll.Orientation = ScrollOrientation.Both; thisScroll.Content = _thisCanvas; firstGrid.Children.Add(thisScroll); var thisRect = ThisFrame.GetControlArea(); thisScroll.Margin = new Thickness(thisRect.Left + 3, thisRect.Top + 3, 3, 5); // try this way. PopulateCards(); Content = firstGrid; }
public void LoadList(GameBoardObservable <CA> mod, string tagUsed) { _tagUsed = tagUsed; _thisMod = mod; DataContext = _thisMod; _objectList = _thisMod.ObjectList; _objectList.CollectionChanged += ObjectList_CollectionChanged; Grid firstGrid = new Grid(); if (_thisMod.HasFrame == true) { firstGrid.Children.Add(ThisDraw); } _mainGrid = new Grid(); firstGrid.Children.Add(_mainGrid); var firstCard = new CA(); // for size if (firstCard.DefaultSize.Height == 0 || firstCard.DefaultSize.Width == 0) { throw new BasicBlankException("The width and height must be greater than 0 when initializging hand wpf"); } IGamePackageResolver thisR = (IGamePackageResolver)cons !; IProportionImage thisI = thisR.Resolve <IProportionImage>(tagUsed); _sizeUsed = firstCard.DefaultSize.GetSizeUsed(thisI.Proportion); SetUpGrid(); PopulateList(); SetBinding(TextProperty, nameof(GameBoardObservable <CA> .Text)); SetBinding(IsEnabledProperty, nameof(GameBoardObservable <CA> .IsEnabled)); SetBinding(VisibilityProperty, GetVisibleBinding(nameof(GameBoardObservable <CA> .Visible))); if (_thisMod.HasFrame == true) { var thisRect = ThisFrame.GetControlArea(); _mainGrid.Margin = new Thickness(thisRect.Left + 3, thisRect.Top + 3, 3, 5); // try this way. } Content = firstGrid; }
protected void GetFirstPieces(int howMany, out DeckObservableDict <D> thisList) { if (ObjectList !.Count == 0) { throw new Exception("There must be at least one piece in order to get the first pieces"); } thisList = new DeckObservableDict <D>(); //i think. if (RemainingList.Count < howMany) { throw new Exception("There are only " + RemainingList.Count + " but was trying to get " + howMany + " pieces"); } ICustomBasicList <D> newList; newList = RemainingList.GetRandomList(true, howMany); if (RemainingList.Count == 0) { throw new Exception("Can't have 0 pieces remaining after getting random list"); } foreach (var thisCard in newList) { thisCard.IsUnknown = false; } thisList.ReplaceRange(newList); }
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; }
public DeckObservableDict <SkipboCardInformation> CardsFromPile(int pile) { var output = new DeckObservableDict <SkipboCardInformation>(); var thisPile = PileList ![pile];
public void LoadList(HandObservable <CA> thisMod, string tagUsed) { CA firstCard; _tagUsed = tagUsed; BindingContext = thisMod; SetBinding(TextProperty, new Binding(nameof(HandObservable <CA> .Text))); SetBinding(IsEnabledProperty, new Binding(nameof(HandObservable <CA> .IsEnabled))); _thisMod = thisMod; if (_alreadyLoaded == true) { throw new BasicBlankException("Needs some rethinking because i intended to load once"); } if (_thisMod.HandList.Count == 0) { firstCard = new CA(); } else { firstCard = _thisMod.HandList.First(); } if (firstCard.DefaultSize.Height == 0 || firstCard.DefaultSize.Width == 0) { throw new BasicBlankException("The width and height must be greater than 0 when initializging hand wpf"); } IGamePackageResolver thisR = (IGamePackageResolver)cons !; IProportionImage thisI = thisR.Resolve <IProportionImage>(tagUsed); _sizeUsed = firstCard.DefaultSize.GetSizeUsed(thisI.Proportion); ObjectList = _thisMod.HandList; ObjectList.CollectionChanged += ObjectList_CollectionChanged; ThisScroll = new ScrollView(); if (HasAngles == false) { _thisStack = new GameOverlapLayout <CA, GC>(_sizeUsed); _thisStack.Spacing = 0; } else { _otherStack = new StackLayout(); _otherStack.Spacing = 0; } SetBinding(MaximumCardsProperty, new Binding(nameof(HandObservable <CA> .Maximum))); PositionMainControls(); PopulateList(); SetVisibleConverter(); _thisGrid.Children.Add(ThisDraw); ThisScroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Default; ThisScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Default; //try this too. if (HasAngles == false) { ThisScroll.Content = _thisStack; } else { ThisScroll.Content = _otherStack; } var thisRect = ThisFrame.GetControlArea(); if (HasAngles == false) { ThisScroll.Margin = new Thickness(thisRect.Left - 1, thisRect.Top - 1, 0, 3); // try this way. } else { ThisScroll.Margin = new Thickness(thisRect.Left - 1, thisRect.Top - 1, 3, 3); } _thisGrid.Children.Add(ThisScroll); RecalulateFrames(); _drawControl = new SKCanvasView(); _drawControl.EnableTouchEvents = true; _drawControl.Touch += DrawControlTouch; _thisGrid.Children.Add(_drawControl); Content = _thisGrid; _alreadyLoaded = true; }
public DeckRegularDict <MexicanDomino> GetTrainList(DeckObservableDict <MexicanDomino> piecesCollection, int givenNumber) { DeckRegularDict <MexicanDomino> output; Dictionary <int, MexicanDomino> matchingPieces = new Dictionary <int, MexicanDomino>(); List <int> Positions = new List <int>(); DeckObservableDict <MexicanDomino> TempList = new DeckObservableDict <MexicanDomino>(); foreach (var currentPiece in piecesCollection) { TempList.Add(currentPiece); } bool anyPieceMatch = false; int count = 1; DateTime newTime; newTime = DateTime.Now.AddSeconds(5); foreach (var currentPiece in piecesCollection) { if ((currentPiece.CurrentFirst == givenNumber) | (currentPiece.CurrentSecond == givenNumber)) { MexicanDomino newPiece = new MexicanDomino(); newPiece.CurrentFirst = currentPiece.CurrentFirst; newPiece.CurrentSecond = currentPiece.CurrentSecond; newPiece.Deck = currentPiece.Deck; newPiece.CurrentFirst = currentPiece.CurrentFirst; newPiece.Keeps = currentPiece.Keeps; newPiece.CurrentSecond = currentPiece.CurrentSecond; newPiece.Status = currentPiece.Status; newPiece.Train = currentPiece.Train; Positions.Add(count); matchingPieces.Add(count, newPiece); anyPieceMatch = true; } count += 1; } if (anyPieceMatch == false) { return(new DeckRegularDict <MexicanDomino>()); } CustomBasicList <CustomBasicList <MexicanDomino> > allTrains = new CustomBasicList <CustomBasicList <MexicanDomino> >(); count = 1; // Searching for Trains foreach (var currentPiece in matchingPieces.Values) { // Searching for Train CustomBasicList <MexicanDomino> train = new CustomBasicList <MexicanDomino>(); if (currentPiece.CurrentFirst != givenNumber) { ReplacePieceFirstSecond(currentPiece); } train.Add(currentPiece); // All Pieces Clone with Removing the first matched var allPieces = CloneList(TempList); allPieces.RemoveAt(Positions[count - 1] - 1); // 0 based int i = 1; MexicanDomino trainEnd = currentPiece; CustomBasicList <CustomBasicList <MexicanDomino> > trainPieceList = new CustomBasicList <CustomBasicList <MexicanDomino> >(); CustomBasicList <CustomBasicList <MexicanDomino> > trainSecondList = new CustomBasicList <CustomBasicList <MexicanDomino> >(); CustomBasicList <MexicanDomino> trainDominoList = new CustomBasicList <MexicanDomino>(); CustomBasicList <int> trainIndexList = new CustomBasicList <int>(); while (i <= allPieces.Count) { MexicanDomino piece; piece = allPieces[i - 1]; // because 0 based if (piece.CurrentFirst == trainEnd.CurrentSecond) { trainPieceList.Add(CloneList(allPieces)); trainSecondList.Add(CloneList(train)); trainDominoList.Add(CloneDominoPiece(trainEnd)); train.Add(piece); allPieces.RemoveAt(i - 1); // 0 based trainEnd = piece; i = 1; } else if (piece.CurrentSecond == trainEnd.CurrentSecond) { trainPieceList.Add(CloneList(allPieces)); trainSecondList.Add(CloneList(train)); trainDominoList.Add(CloneDominoPiece(trainEnd)); trainIndexList.Add(i + 1); ReplacePieceFirstSecond(piece); train.Add(piece); allPieces.RemoveAt(i - 1); // 0 based trainEnd = piece; i = 1; } else { if (i < allPieces.Count) { i += 1; } else if ((trainPieceList.Count > 0) & (i >= allPieces.Count) & trainIndexList.Count > 0) { allTrains.Add(CloneList(train)); if (allPieces.Count == 0) { throw new BasicBlankException("allpieces has nothing left"); } allPieces = trainPieceList.First(); trainPieceList.RemoveAt(0); if (trainSecondList.Count == 0) { throw new BasicBlankException("trainsecondlist has nothing left"); } train = trainSecondList.First(); trainSecondList.RemoveAt(0); if (trainDominoList.Count == 0) { throw new BasicBlankException("traindominolist has nothing left"); } trainEnd = trainDominoList.First(); trainDominoList.RemoveAt(0); if (trainIndexList.Count == 0) { i++; } else { i = trainIndexList.First(); trainIndexList.RemoveAt(0); } } else { // Saves the current list allTrains.Add(CloneList(train)); // No more List possible break; } if (DateTime.Now > newTime) { // MsgBox("taking too long") break; } } } if (train.Count > 0) { allTrains.Add(CloneList(train)); } if (DateTime.Now > newTime) { break; } count += 1; } int j = 1; int piecesCount = 0; bool multiplePiecesCount = false; CustomBasicList <int> piecesPositions = new CustomBasicList <int>(); while (j <= allTrains.Count) { CustomBasicList <MexicanDomino> currentTrain; currentTrain = allTrains[j - 1]; // 0 based if (currentTrain.Count > piecesCount) { piecesCount = currentTrain.Count; multiplePiecesCount = false; piecesPositions.Clear(); piecesPositions.Add(j); } else if (currentTrain.Count == piecesCount) { multiplePiecesCount = true; piecesPositions.Add(j); } j += 1; } CustomBasicList <MexicanDomino> tempCol; if (!multiplePiecesCount) { tempCol = allTrains[piecesPositions[0] - 1]; // try 0 based here output = new DeckRegularDict <MexicanDomino>(); MexicanDomino newDomino; foreach (var thisDomino in tempCol) { newDomino = piecesCollection.GetSpecificItem(thisDomino.Deck); newDomino.CurrentFirst = thisDomino.CurrentFirst; newDomino.CurrentSecond = thisDomino.CurrentSecond; piecesCollection.RemoveObjectByDeck(newDomino.Deck); // try this way output.Add(newDomino); } return(output); } else { int points; int bestPoints = 0; int bestPosition = 0; var loopTo = piecesPositions.Count - 1; for (points = 0; points <= loopTo; points++) { int totalPoints = 0; CustomBasicList <MexicanDomino> currentTrain = allTrains[piecesPositions[points] - 1]; // 0 based foreach (var piece in currentTrain) { totalPoints += piece.Points; } if (totalPoints > bestPoints) { bestPosition = points; } } tempCol = allTrains[piecesPositions[bestPosition] - 1]; // 0 based output = new DeckRegularDict <MexicanDomino>(); MexicanDomino NewDomino; foreach (var ThisDomino in tempCol) { NewDomino = piecesCollection.GetSpecificItem(ThisDomino.Deck); NewDomino.CurrentFirst = ThisDomino.CurrentFirst; NewDomino.CurrentSecond = ThisDomino.CurrentSecond; piecesCollection.RemoveSpecificItem(NewDomino); // try this way output.Add(NewDomino); } return(output); } }