public List <CardFlipOut> hand; // the cards in this player's hand // Add a card to the hand public CardFlipOut AddCard(CardFlipOut eCB) { if (hand == null) { hand = new List <CardFlipOut>(); } // add the card to the hand hand.Add(eCB); /* * can use this for the score method * // sort the cards by rank using LINQ if this is a human * if (type == PlayerType.human) * { * CardFlipOut[] cards = hand.ToArray(); * * // this is the LINQ call * cards = cards.OrderBy(cd => cd.rank).ToArray(); * * hand = new List<CardFlipOut>(cards); * * // the LINQ operations can be a slow, but since we're only doing it once every round, it's not an issue * } */ eCB.SetSortingLayerName("10"); eCB.eventualSortLayer = handSlotDef.layerName; FanHand(); return(eCB); }
public void DrawFirstTarget() { // flip up the first card from the dP CardFlipOut tCB = MoveToTarget(Draw()); // set the CardFlipOut to call cbcallback on this FlipOut when it's done tCB.reportFinishTo = this.gameObject; }
// this makes a new card the target public CardFlipOut MoveToDiscard(CardFlipOut tCB) { tCB.state = CBState.discard; discardPile.Add(tCB); tCB.SetSortingLayerName(layout.discardPile.layerName); tCB.SetSortOrder(discardPile.Count * 4); tCB.transform.localPosition = layout.discardPile.pos + Vector3.back / 2; return(tCB); }
// remove a card from the hand public CardFlipOut RemoveCard(CardFlipOut cb) { // if hand is null or doesnt contain cb, return null if (hand == null || !hand.Contains(cb)) { return(null); } hand.Remove(cb); FanHand(); return(cb); }
// method veries that the card chosen can be played on the dP public bool ValidPlay(CardFlipOut cb) { // its valid if the rank is the same if (cb.rank == targetCard.rank) { return(true); } // its valid if the suit is the same if (cb.suit == targetCard.suit) { return(true); } // if neither return(false); }
// this makes a new card the target public CardFlipOut MoveToTarget(CardFlipOut tCB) { tCB.timeStart = 0; tCB.MoveTo(layout.discardPile.pos + Vector3.back); tCB.state = CBState.toTarget; tCB.faceUp = true; tCB.SetSortingLayerName("10"); tCB.eventualSortLayer = layout.target.layerName; if (targetCard != null) { MoveToDiscard(targetCard); } targetCard = tCB; return(tCB); }
public void CardClicked(CardFlipOut tCB) { if (CURRENT_PLAYER.type != PlayerType.human) { return; } if (phase == TurnPhase.waiting) { return; } switch (tCB.state) { case CBState.drawpile: // draw the top card CardFlipOut cb = CURRENT_PLAYER.AddCard(Draw()); cb.callbackPlayer = CURRENT_PLAYER; Utils.tr("FlipOut: CardClicked()", "Draw", cb.name); phase = TurnPhase.waiting; break; case CBState.hand: // check to see whether the card is valid if (ValidPlay(tCB)) { CURRENT_PLAYER.RemoveCard(tCB); MoveToTarget(tCB); tCB.callbackPlayer = CURRENT_PLAYER; Utils.tr("FlipOut:CardClicked()", "Play", tCB.name, targetCard.name + " is target"); phase = TurnPhase.waiting; } else { // ignore but report when tried Utils.tr("FlipOut.CardClicked()", "Attempted to Play", tCB.name, targetCard.name + " is target"); } break; } }
// the draw function will pull asingle card from the drawPile and return it public CardFlipOut Draw() { CardFlipOut cd = drawPile[0]; if (drawPile.Count == 0) { ArrangeDrawPile(); // show the cards moving to drawPile float t = Time.time; foreach (CardFlipOut tCB in drawPile) { tCB.transform.localPosition = layout.discardPile.pos; tCB.callbackPlayer = null; tCB.MoveTo(layout.drawPile.pos); tCB.timeStart = t; t += 0.02f; tCB.state = CBState.toDrawpile; tCB.eventualSortLayer = "0"; } } drawPile.RemoveAt(0); return(cd); }
// this callback is used by the last card to be dealt at the beginning public void CBCallback(CardFlipOut cb) { Utils.tr("FlipOut: CBCallback()", cb.name); StartGame(); }
public void CBCallback(CardFlipOut tCB) { Utils.tr("Player.CBCallback()", tCB.name, "Player " + playerNum); FlipOut.S.PassTurn(); }