public void MoveCardToStack(CardMoveToStackEventArgs e) { if (cardModels.Contains(e.cardModel) && CardMoveToStackEvent != null) { CardMoveToStackEvent(this, e); } }
public void finishedMovingToStack(CardMoveToStackEventArgs e) { if (cardModels.Contains(e.cardModel)) { e.cardStack.Insert(Pop(e.indexFrom), e.indexTo); } }
void CardClicker_CardClicked(object sender, CardEventArgs e) { switch (playerClickState) { case GameState.None: return; case GameState.Ready: if (deck.HasCard(e.cardModel)) { stagedCard = e.cardModel; deck.StageCard(e.cardModel, turnMarker.transform.position, true); playerClickState = GameState.Staged; // if (!playersCardsHidden) { // playersCardsHidden = true; // player.flipCards(new RangeInt(0, 2), false); // } } return; case GameState.Staged: if (stagedCard != null && e.cardModel != stagedCard) { Vector3 discardPosition = discard.GetComponent <CardStackView>().start; if (deck.HasCard(e.cardModel)) // discard { deck.MoveCardToStack( new CardMoveToStackEventArgs(e.cardModel, discard, discardPosition, false, -1, -1) ); stagedCard = null; playerClickState = GameState.None; } else if (player.HasCard(e.cardModel)) // card swap { int indexOfCardClicked = player.IndexOf(e.cardModel); CardStackView stackView = player.GetComponent <CardStackView>(); Vector3 cardClickedPosition = stackView.CardPositionForIndex(indexOfCardClicked); CardMoveToStackEventArgs playerArgs = new CardMoveToStackEventArgs( e.cardModel, discard, discardPosition, false, indexOfCardClicked, -1 ); CardMoveToStackEventArgs deckArgs = new CardMoveToStackEventArgs( stagedCard, player, cardClickedPosition, false, -1, indexOfCardClicked ); //player.MoveCardToStack(playerArgs); // discard clicked card and flip deck.MoveCardToStack(deckArgs); // add staged card to user stack stagedCard = null; playerClickState = GameState.None; } } return; } }
void CardMover_MovedCardToStack(object sender, CardMoveToStackEventArgs e) { cardStack.finishedMovingToStack(e); CardMover cardMover = sender as CardMover; if (cardMover != null) { cardMover.CardMoveToStackEvent -= CardMover_MovedCardToStack; } }
void CardStack_MoveCardToStack(object sender, CardMoveToStackEventArgs e) { if (cards.ContainsKey(e.cardModel.cardIndex)) { CardMover cardMover = cards[e.cardModel.cardIndex].GetComponent <CardMover>(); cardMover.CardMoveToStackEvent += CardMover_MovedCardToStack; cardMover.MoveCardToStack(e); if (e.flip) { CardFlipper cardFlipper = cards[e.cardModel.cardIndex].GetComponent <CardFlipper>(); cardFlipper.FlipCard(e.cardModel); } } }
IEnumerator Move(Vector3 moveToPosition) { float time = 0f; Vector3 startPosition = transform.position; float journeyLength = Vector3.Distance(startPosition, moveToPosition); while (time <= duration) { time = time + Time.deltaTime / duration; float distCovered = journeyLength * time; transform.position = Vector3.Lerp(startPosition, moveToPosition, distCovered); yield return(new WaitForFixedUpdate()); } if (e != null && CardMoveToStackEvent != null) { CardMoveToStackEvent(this, e); e = null; } }
public void MoveCardToStack(CardMoveToStackEventArgs e) { this.e = e; StartCoroutine(Move(e.position)); }