// The Draw function will pull a single card from the drawPile and return it public CardLoot Draw() { CardLoot cd = drawPile[0]; // Pull the 0th CardLoot if (drawPile.Count == 0) { // If the drawPile is now empty // We need to shuffle the discards into the drawPile int ndx; while (discardPile.Count > 0) { // Pull a random card from the discard pile ndx = Random.Range(0, discardPile.Count); drawPile.Add(discardPile[ndx]); discardPile.RemoveAt(ndx); } ArrangeDrawPile(); // Show the cards moving to the drawPile float t = Time.time; foreach (CardLoot tCL in drawPile) { tCL.transform.localPosition = layout.discardPile.pos; tCL.callbackPlayer = null; tCL.MoveTo(layout.drawPile.pos); tCL.timeStart = t; t += 0.02f; tCL.state = CLState.toDrawpile; tCL.eventualSortLayer = "0"; } } drawPile.RemoveAt(0); // Then remove it from List<> drawPile return(cd); // And return it }
public List <CardLoot> hand; // The cards in this player's hand // Add a card to the hand public CardLoot AddCard(CardLoot eCL) { if (hand == null) { hand = new List <CardLoot>(); } // Add the card to the hand hand.Add(eCL); //Sort the cards by rank using LINQ if this is a human if (type == PlayerType.human) { CardLoot[] cards = hand.ToArray(); // This is the LINQ call cards = cards.OrderBy(cd => cd.value).ToArray(); hand = new List <CardLoot>(cards); // Note: LINQ operations can be a bit slow (like it could take a // couple of milliseconds), but since we're only doing it once // every round, it isn't a problem. } eCL.SetSortingLayerName("10"); // Sorts the moving card to the top eCL.eventualSortLayer = handSlotDef.layerName; FanHand(); return(eCL); }
public void DrawFirstTarget() { // Flip up the first target card from the DrawPile CardLoot tCL = MoveToTarget(Draw()); // Set the CardLoot to call CLCallback on this Loot when it is done tCL.reportFinishTo = this.gameObject; }
public CardLoot MoveToDiscard(CardLoot tCL) { tCL.state = CLState.discard; discardPile.Add(tCL); tCL.SetSortingLayerName(layout.discardPile.layerName); tCL.SetSortOrder(discardPile.Count * 4); tCL.transform.localPosition = layout.discardPile.pos + Vector3.back / 2; return(tCL); }
// Remove a card from the hand public CardLoot RemoveCard(CardLoot cl) { // If hand is null or doesn't contain cl, return null if (hand == null || !hand.Contains(cl)) { return(null); } hand.Remove(cl); FanHand(); return(cl); }
// ValidPlay verifies that the card chosen can be played in a battle public bool ValidPlay(CardLoot cl) { // It's a valid play if the color is not the same if (cl.color != target.color) { return(true); } // It's a valid play if the if (cl.cardColor == target.cardColor) { return(true); } // Otherwise, return false return(false); }
// This makes a new card the target public CardLoot MoveToTarget(CardLoot tCL) { tCL.timeStart = 0; tCL.MoveTo(layout.discardPile.pos + Vector3.back); tCL.state = CLState.toTarget; tCL.faceUp = true; tCL.SetSortingLayerName("10"); tCL.eventualSortLayer = layout.pirate.layerName; if (target != null) { MoveToDiscard(target); } target = tCL; return(tCL); }
public void CardClicked(CardLoot tCL) { if (CURRENT_PLAYER.type != PlayerType.human) { return; } if (phase == TurnPhase.waiting) { return; } switch (tCL.state) { case CLState.drawpile: // Draw the top card, not necessarily the one clicked. CardLoot cl = CURRENT_PLAYER.AddCard(Draw()); cl.callbackPlayer = CURRENT_PLAYER; Utils.tr("Loot:CardClicked()", "Draw", cl.name); phase = TurnPhase.waiting; break; case CLState.hand: // Check to see whether the card is valid if (ValidPlay(tCL)) { CURRENT_PLAYER.RemoveCard(tCL); MoveToTarget(tCL); tCL.callbackPlayer = CURRENT_PLAYER; Utils.tr("Loot:CardClicked()", "Play", tCL.name, target.name + " is target"); phase = TurnPhase.waiting; } else { // Just ignore it but report what the player tried Utils.tr("Loot:CardClicked()", "Attempted to Play", tCL.name, target.name + " is target"); } break; } }
public void CLCallback(CardLoot tCL) { Utils.tr("Player.CLCallback()", tCL.name, "Player " + playerNum); // The card is done moving, so pass the turn Loot.S.PassTurn(); }
// This callback is used by the last card to be dealt at the beginning public void CLCallback(CardLoot cl) { // You sometimes want to have reporting of method calls like this Utils.tr("Loot:CLCallback()", cl.name); StartGame(); // Start the Game }