public void RemoveCard(UniqueDisplayCard card) { Image elementToRemove = this.FindName(card.Id) as Image; game_canvas.Children.Remove(elementToRemove); UnregisterElementCanvasPosition(elementToRemove); }
private void OnCardPointerExited(UniqueDisplayCard card) { if (_isInInteractiveState && _curInteractiveCards.Contains(card)) { var curPosIndex = _displayCards.FindIndex(displayCard => displayCard.Equals(card)); _canvasFacade.UpdateCard(card, _curPositions[curPosIndex]); } }
private void OnCardClicked(UniqueDisplayCard clickedCard) { if (_isInInteractiveState && _curInteractiveCards.Contains(clickedCard)) { _curCardClickedHandler(clickedCard); EndInteractiveSession(); } }
private Image CreateCardImage(UniqueDisplayCard card) { var bitmapImage = RetrieveCardBitmap(card.DisplayKey); var image = new Image(); image.Source = bitmapImage; image.Name = card.Id; return(image); }
private bool FlipImpl(UniqueDisplayCard card) { if (card != null) { card.IsFaceUp = !card.IsFaceUp; _canvasFacade.UpdateCard(card); } return(false); }
public void Add(Core.Card card, bool isCardFaceUp = false) { UniqueDisplayCard displayCard = new UniqueDisplayCard(card, isCardFaceUp); var nextOpenPositionInfo = NextOpenPositions(1)[0]; OnPreCardsAddition(new List <UniqueDisplayCard> { displayCard }); _displayCards.Add(displayCard); _canvasFacade.AddCard(displayCard, nextOpenPositionInfo.Item1 /*pos*/, OrientationDegress, nextOpenPositionInfo.Item2 /*zIndex*/); }
/*************************** ICanvasFacade implementation *******************************/ public void AddCard(UniqueDisplayCard card, NormalizedPosition canvasPositon, double orientationDegrees, int zIndex) { Image image = CreateCardImage(card); SetUiElementNormalizedCanvasPosition(image, canvasPositon, true, _cardBitmapSize); SetCardImageAngle(image, orientationDegrees); Canvas.SetZIndex(image, zIndex); image.PointerReleased += (sender, args) => FireCardClickedEvent(card); image.PointerEntered += (sender, args) => FireCardPointerEnteredEvent(card); image.PointerExited += (sender, args) => FireCardPointerExitedEvent(card); game_canvas.Children.Add(image); }
// removes the first card in _cards matching the card param // animates removal public bool Remove(Core.Card card) { UniqueDisplayCard cardToRemove = GetDisplayCardFromCoreCard(card); if (cardToRemove != null) { _displayCards.Remove(cardToRemove); _canvasFacade.RemoveCard(cardToRemove); OnPostCardsRemoval(); return(true); } return(false); }
public void UpdateCard ( UniqueDisplayCard cardToUpdate, NormalizedPosition canvasPositon = null, double?orientationDegrees = null, int?zIndex = null, bool?dimmed = null ) { // check if the card bitmap needs an update Image imageToUpdate = this.FindName(cardToUpdate.Id) as Image; var originalBitmapFilepath = (imageToUpdate.Source as BitmapImage).UriSource.AbsolutePath; // if the original element already contains the updated bitmap, no change is needed, otherwise, replace the bitmap if (!originalBitmapFilepath.Contains(cardToUpdate.DisplayKey)) { var bitmapImage = RetrieveCardBitmap(cardToUpdate.DisplayKey); imageToUpdate.Source = bitmapImage; } // update the position if provided if (canvasPositon != null) { // update position. if already equal, this is a noop SetUiElementNormalizedCanvasPosition(imageToUpdate, canvasPositon, true); } // update the orientnation if provided if (orientationDegrees.HasValue) { // update the orientation. if already equal, this is a noop SetCardImageAngle(imageToUpdate, orientationDegrees.Value); } if (zIndex.HasValue) { Canvas.SetZIndex(imageToUpdate, zIndex.Value); } if (dimmed.HasValue) { imageToUpdate.Opacity = dimmed.Value ? 0.5 : 1.0; } }
private void OnCardPointerEntered(UniqueDisplayCard card) { if (_isInInteractiveState && _curInteractiveCards.Contains(card)) { var curPosIndex = _displayCards.FindIndex(displayCard => displayCard.Equals(card)); var curPos = _curPositions[curPosIndex]; if (OrientationAxis == Axis.X) { double offsetY = _orientation == Common.Orientation.DEGREES_0 ? -2 : 2; _canvasFacade.UpdateCard(card, new NormalizedPosition(curPos.NormalizedX, curPos.NormalizedY + offsetY)); } else { double offsetX = _orientation == Common.Orientation.DEGREES_90 ? 1 : 1; _canvasFacade.UpdateCard(card, new NormalizedPosition(curPos.NormalizedX + offsetX, curPos.NormalizedY)); } } }
// transfers the first card in _cards matching the cardName param public bool Transfer(Core.Card card, CardGroup destinationGroup, AnimationBehavior animationBehavior) { UniqueDisplayCard cardToTransfer = GetDisplayCardFromCoreCard(card); if (cardToTransfer != null) { var nextOpenPositionInfo = destinationGroup.NextOpenPositions(1)[0]; var destinationPoint = nextOpenPositionInfo.Item1; var newZIndex = nextOpenPositionInfo.Item2; this._displayCards.Remove(cardToTransfer); this.OnPostCardsRemoval(); // resolve rotations so that the animation terminates at the angle of the destination group // rotations are rounded up so that the card is flush with the destination double resolvedRotations = ResolveRotations(destinationGroup, animationBehavior); var transferAnimRequest = new NamedAnimationRequest() { Destination = destinationPoint, Duration = animationBehavior.Duration, Delay = animationBehavior.Delay, Rotations = resolvedRotations, TargetElementName = cardToTransfer.Id }; _canvasFacade.QueueAnimationRequest(transferAnimRequest); destinationGroup.OnPreCardsAddition(new List <UniqueDisplayCard> { cardToTransfer }); destinationGroup._displayCards.Add(cardToTransfer); // finish transfer to destination group by updating the card to have the correct zIndex as determined by its destination group _canvasFacade.UpdateCard(cardToTransfer, zIndex: newZIndex); return(true); } return(false); }
private void FireCardPointerExitedEvent(UniqueDisplayCard card) => CardPointerExited?.Invoke(card);
private void FireCardClickedEvent(UniqueDisplayCard card) => CardClicked?.Invoke(card);
// flips a card in place to either face up or face down public bool Flip(Core.Card card) { UniqueDisplayCard cardToFlip = GetDisplayCardFromCoreCard(card); return(FlipImpl(cardToFlip)); }