bool TryPickupCard(Collider2D c) { if (holding == null && buttonFixedPressed) { CardPickup card = c.GetComponent <CardPickup>(); if (card == null) { return(false); } //Put card into "hand" transform and disable its collider c.transform.SetParent(CardHolder); c.transform.localPosition = Vector3.zero; holding = c.transform; //Collider can stay on if it is used for dropping c.GetComponent <BoxCollider2D>().enabled = false; didActionThisFrame = true; //Set large card to match this one largeCard.SetCard(card.GetCardIndexer().Card, false); largeCard.SetDirection(lineManager.Direction); return(true); } else { return(false); } }
// Use this for initialization void Awake() { manager = GameObject.Find("GameManager").GetComponent <GameManager>(); cardPickup = manager.pickCard; fill = GameObject.Find("HandManager").GetComponent <FillHand>(); golds = GameObject.Find("GoldManager").GetComponent <GoldScript>(); }
bool TryDropCard(Collider2D c) { //Only test for the first collider that player is touching CardDropoff dropOff = c.GetComponent <CardDropoff>(); //Also ignore totally if dropoff already has all of its cards (but don't send card away) if (dropOff == null || dropOff != wordCollider || !dropOff.CanTakeCard()) { return(false); } if (holding && buttonFixedPressed) { //Increment drop counter TotalDrops += 1; //Check if correct card //Unclear if card can be dropped if it's still wrong //To prevent backtracking it could fly back to where it came from CardPickup cardPickup = holding.GetComponent <CardPickup>(); if (!dropOff.IsSolution(cardPickup)) { IncorrectDrops += 1; //Send back to where it came from //Play some kind of negative sound AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_down"), transform.position); cardPickup.GetComponent <BoxCollider2D>().enabled = true; cardPickup.MoveHome(); //Action was completed, no input should have more than one action happen } else { CorrectDrops += 1; //Remove CardPickup monobehaviour //Or set flag to prevent pickup again of card (dropoff may be one way) //Trigger is already disabled dropOff.GiveCard(holding); //Play positive sound AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_up"), transform.position); //Change color of text textColor = CompletionColor; var textMesh = dropOff.UITextMesh; textMesh.color = CompletionSelectionColor; } holding = null; didActionThisFrame = true; return(true); } else { return(false); } }
public void CollectCard(CardPickup pickup) { // Try to put card directly in hand if (!PutCardInHand(pickup.card)) { // Hand full, put in deck deck.Add(pickup.card); } pickup.Pickup(); }
void CreateCardGameElements(List <CardIndexer> phrase) { dropoffs = new List <CardDropoff>(); for (int i = 0; i < phrase.Count; i++) { CardIndexer cardIndexer = phrase[i]; CardData card = cardIndexer.Card; CardPickup cardP = GameObject.Instantiate(CardPickup, PickupParent).GetComponent <CardPickup>(); cardP.transform.position = PickupParent.position; //Pick card based on directionality cardP.SetCard(cardIndexer, Direction); CardDropoff dropoff = GameObject.Instantiate(CardDropOff, DropoffParent).GetComponent <CardDropoff>(); dropoff.transform.position = DropoffParent.position; //From or to length string textCard = Direction == CardManager.Direction.To ? card.To : card.From; string textBlock = Direction == CardManager.Direction.To ? card.From : card.To; //Temp String formatting for capital first letter and period at end if (i == 0) { if (!string.IsNullOrEmpty(textCard)) { textCard = textCard.First().ToString().ToUpper() + textCard.Substring(1); } if (!string.IsNullOrEmpty(textBlock)) { textBlock = textBlock.First().ToString().ToUpper() + textBlock.Substring(1); } } else if (i == phrase.Count - 1) { if (!string.IsNullOrEmpty(textCard)) { textCard += "."; } if (!string.IsNullOrEmpty(textBlock)) { textBlock += "."; } } GameObject uiText = GameObject.Instantiate(TextBlock, BlockUI); uiText.GetComponentInChildren <TextMeshProUGUI>().text = textBlock; dropoff.SetCard(cardIndexer, Direction, uiText); dropoffs.Add(dropoff); } }
public void GiveCard(Transform holding) { //Perform some kind of animation //Make some sort of success sound //Shoot out some sort of particles holding.SetParent(transform); //Make it move back to its home but this time in a new location CardPickup pickup = holding.GetComponent <CardPickup>(); pickup.HomeLocation.position = transform.position + Vector3.down; pickup.MoveHome(); tookCard = true; }
public bool IsSolution(CardPickup pickupCard) { if (!CanTakeCard()) { return(false); } CardData card = cardIndexer.Card; CardData otherCard = pickupCard.GetCardIndexer().Card; if (direction == CardManager.Direction.To) { return(card.To.Equals(otherCard.To)); } else { return(card.From.Equals(otherCard.From)); } }
public void GenerateCards(int min = 1, int max = 3) { // 1-3 cards int numEntities = Random.Range(min, max + 1); GameManager gm = GameManager.singleton; Player player = gm.player; List <CardInfo> prevCards = new List <CardInfo>(); prevCards.Add(prevCard); var prevLocations = new List <Vector3>(); for (int i = 0; i < numEntities; i++) { var location = GetRandomLocation(2, prevLocations); prevLocations.Add(location); CardPickup card = Instantiate(cardPickupRef, location, Quaternion.identity).GetComponent <CardPickup>(); CardInfo newCard; int maxIterations = max * 2; int iteration = 0; do { newCard = CardDatabase.GetCardOfStatTier(player.primaryStats[0], player.primaryStats[1], gm.cardTier); iteration++; } while(prevCards.Contains(newCard) && iteration < maxIterations); prevCards.Add(newCard); prevCard = newCard; card.SetCard(newCard); GameManager.singleton.RegisterEntity(card); } }
public void OnClick() { cardPickup = manager.pickCard; bool canAfford = false; if (manager.turn == 1) { if (cardPickup.cost <= golds.p1g) { canAfford = true; } else { canAfford = false; } } if (manager.turn == 2) { if (cardPickup.cost <= golds.p2g) { canAfford = true; } else { canAfford = false; } } bool validPos = false; Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 2.30f); foreach (Collider col in colliders) { if (col.gameObject.tag.Equals("Hexagon") && col.gameObject.GetComponent <CardPlay>().posession == manager.turn) { validPos = true; } } if (cardPickup.clicked && cardPickup != null && validPos && canAfford) { attack = cardPickup.attack; defense = cardPickup.defense; gameObject.GetComponentsInChildren <TextMesh>()[0].text = attack + ""; gameObject.GetComponentsInChildren <TextMesh>()[1].text = defense + ""; cardPickup.played = true; if (manager.turn == 1) { posession = 1; gameObject.GetComponent <Renderer>().material.color = Color.blue; } else if (manager.turn == 2) { posession = 2; gameObject.GetComponent <Renderer>().material.color = Color.red; } if (manager.turn == 1) { int index = fill.p1Inst.IndexOf(cardPickup.gameObject); fill.p1Hand.RemoveAt(index); } else { int index = fill.p2Inst.IndexOf(cardPickup.gameObject); fill.p2Hand.RemoveAt(index); } if (manager.turn == 1) { golds.spendFromP1(cardPickup.cost); } if (manager.turn == 2) { golds.spendFromP2(cardPickup.cost); } onTurnPlayed = manager.totalTurn; if (cardPickup.hasCharge) { onTurnPlayed--; } cardPickup = null; manager.pickCard = null; fill.RePrint(); } }