// Inserts a card into the hand, // returns false if not successful public bool InsertCard(CardScript input, bool discard = true) { if (null != input) { if (myOwningPlayer) EffectScript.AffectsList(input.myInsertEffects, myOwningPlayer.ToMessage()); int cardCount = CountCards(); if (cardCount < myCardCapacity) { input.myHandScript = this; Reanimate(); return true; } else if (discard) { if (myOwningPlayer) EffectScript.AffectsList(input.myRemoveEffects, myOwningPlayer.ToMessage()); } } return false; }
public Term() { myCardScript = null; myUnitScript = null; myPlayerScript = null; myPosition = Vector3.zero; }
// Removes a card from the collection public CardScript remove(CardScript card) { if (cards.Remove (card)) return card; else return null; }
public int getCount(CardScript.CardType type) { int counter = 0; foreach (CardScript card in cards) { if (card.type == type) { counter ++; } } return counter; }
public Term( PlayerScript inPlayerScript, CardScript inCardScript, UnitScript inUnitScript, Vector3 inposition) { myCardScript = inCardScript; myUnitScript = inUnitScript; myPlayerScript = inPlayerScript; myPosition = inposition; }
public void Draw() { if (playerID == gm.GetWhoseTurn()) { int i = _deck.Count-1; GameObject card = _deck[i]; _deck.RemoveAt(i); cardScript = card.GetComponent<CardScript> (); cardScript.is_selected = false; playerScript.drawCard(card); } }
/* Sets the index value and the card type of this card. * If the given card type is CardType.Empty, then the card is not displayed. */ public void reset(int idx, CardScript.CardType t) { card = t; index = idx; if (t == CardScript.CardType.Empty) { // Ignored by Mouse gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); } else { // Default layer gameObject.layer = LayerMask.NameToLayer("UI"); } }
public void Eliminate(CardScript cs) { tc.kings[0].Eliminate(cs.card); cards.Remove(cs); buttons.Remove(cs.GetComponent<Button>()); foreach(Button b in buttons) { b.interactable = false; } Destroy(cs.gameObject); GameManager.PlayScream(); tc.EndTurn(); }
/* Builds a deck given the types and their respective quantities in the array arguments. * NOTE: types and weights MUST be of the same length! * Also, there should be no null values in types and weights should contain no nonpositive values either! */ public DeckManager(CardScript.CardType[] types, int[] weights) { deck = new CardCollection (); // Adds a number of each card type equal to their respective weights for (int idx = 0; idx < types.Length; ++idx) { for (int qty = 0; qty < weights[idx]; ++qty) { deck.add(new CardScript(types[idx])); } } hand = new CardCollection(); discardPile = new CardCollection(); }
// Activates a card public void ActivateCard(CardScript cardScript, Message message) { EffectScript.AffectsList(cardScript.myPlayEffects, message); /*myFrameData.myCardsPlayed++; myTurnData.myFrameData.myCardsPlayed++; myMatchData.myTurnData.myFrameData.myCardsPlayed++; GlobalScript.ourPlayerFrameData.myCardsPlayed++; GlobalScript.ourPlayerTurnData.myFrameData.myCardsPlayed++; GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myCardsPlayed++;*/ switch(cardScript.myType) { case CardScript.Type.Spell: /*myFrameData.mySpellsCast++; myTurnData.myFrameData.mySpellsCast++; myMatchData.myTurnData.myFrameData.mySpellsCast++; GlobalScript.ourPlayerFrameData.mySpellsCast++; GlobalScript.ourPlayerTurnData.myFrameData.mySpellsCast++; GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.mySpellsCast++;*/ break; case CardScript.Type.Item: /*myFrameData.myItemsUsed++; myTurnData.myFrameData.myItemsUsed++; myMatchData.myTurnData.myFrameData.myItemsUsed++; GlobalScript.ourPlayerFrameData.myItemsUsed++; GlobalScript.ourPlayerTurnData.myFrameData.myItemsUsed++; GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myItemsUsed++;*/ break; case CardScript.Type.Unit: /*myFrameData.myUnitsMade++; myTurnData.myFrameData.myUnitsMade++; myMatchData.myTurnData.myFrameData.myUnitsMade++; GlobalScript.ourPlayerFrameData.myUnitsMade++; GlobalScript.ourPlayerTurnData.myFrameData.myUnitsMade++; GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myUnitsMade++;*/ break; } }
/// <summary> /// discards the card associated with the given wave /// </summary> public void discardWave(WaveData toDiscard) { //find the card to discard CardScript card = null; foreach (CardScript c in cards) { if (c != null) { if (c.GetComponent <EnemyCardScript>().wave == toDiscard) { card = c; } } } //and discard it card.SendMessage("Discard"); }
public void OnCardsCollide() { // Move attacking card back to original position CardScript attackCardScript = this.attackingCard.GetComponent <CardScript>(); attackCardScript.MoveBackToOriginalPosition(); // Unselect attacking card this.UnselectPlayerCard(this.attackingCard); // Update health values CardScript defendingCardScript = this.defendingCard.GetComponent <CardScript>(); attackCardScript.LoseHealth(defendingCardScript.AttackValue); defendingCardScript.LoseHealth(attackCardScript.AttackValue); // Shake camera camShakeScript.Shake(); }
void OnCollisionEnter2D(Collision2D other) { if (this.isEnemyPlayer) { // Enemies don't move return; } if (other.gameObject.tag == "Card") { CardScript cardBeingHitScript = other.gameObject.GetComponent <CardScript>(); // Enemy card being hit should be the only one on this layer Assert.IsTrue(cardBeingHitScript.IsEnemyPlayer); // We've hit the enemy this.gameManager.OnCardsCollide(); } }
private void SelectMultipleCards(GameObject inputCard) { CardScript inputCardScript = inputCard.GetComponent <CardScript>(); if (inputCardScript == null || !inputCardScript.container.CompareTag("Foundation")) { throw new System.ArgumentException("inputCard must be a gameObject that contains a CardScript that is from a foundation"); } FoundationScript inputCardFoundation = inputCardScript.container.GetComponent <FoundationScript>(); for (int i = inputCardFoundation.cardList.IndexOf(inputCard); i >= 0; i--) { selectedCards.Add(inputCardFoundation.cardList[i]); inputCardFoundation.cardList[i].GetComponent <CardScript>().SetSelected(true); } StartDragging(); }
public void ShuffleClickableCards() { AllocateCardPosition(); // if none of the cards are clickable, don't bother if (thisAllocatedCardPositionList.Count != 0) { thisHasShuffled = true; foreach (GameObject aCard in thisInstantiatedServedCards) { if (CheckIfClickable(aCard)) { // access card script component for future call CardScript aCardScript = aCard.GetComponent <CardScript>(); // randomly find a position from the allocated card position list Vector3 aRandomlyAssignedPosition = thisAllocatedCardPositionList[Random.Range(0, thisAllocatedCardPositionList.Count)]; //Vector3 aRandomlyAssignedPosition = thisAllocatedCardPositionList[Random.Range(0, thisAllocatedCardPositionList.Count)].position; // remove this one from list to prevent redundant assignment thisAllocatedCardPositionList.Remove(aRandomlyAssignedPosition); // make coroutine work aCardScript.StartLerpToShuffleCoroutine(thisShufflePoint.transform.position, aRandomlyAssignedPosition, thisLerpToShuffleSpeed); } } // empty the list for future use thisAllocatedCardPositionList = new List <Vector3>(); } else { // when the game is over, temporarily exit out of game editor //UnityEditor.EditorApplication.isPlaying = false; thisNpcBehavior.CloseShuffleState(); thisPlayerBehavior.CloseShuffleState(); StartCoroutine(CountDownForResult()); } }
private void TryToSelectCards(RaycastHit2D hit) { if (hit.collider == null) { return; } GameObject hitGameObject = hit.collider.gameObject; if (!hitGameObject.CompareTag("Card")) { if (hitGameObject.CompareTag("Baby")) { baby.GetComponent <SpaceBabyController>().BabyHappyAnim(); } return; } CardScript hitCardScript = hitGameObject.GetComponent <CardScript>(); //if we click a card in the wastepile select it if (hitCardScript.container.CompareTag("Wastepile")) { // all non-top wastepile tokens have their hitboxes disabled //if (hitCardScript.container.GetComponent<WastepileScript>().cardList[0] == hitGameObject) SelectCard(hitGameObject); } //if we click a card in a reactor else if (hitCardScript.container.CompareTag("Reactor") && hitCardScript.container.GetComponent <ReactorScript>().cardList[0] == hitGameObject) { SelectCard(hitGameObject); } //if we click a card in a foundation else if (hitCardScript.container.CompareTag("Foundation")) { //if (!hitCardScript.isHidden()) // hidden cards have their hitboxes disabled SelectMultipleCards(hitGameObject); } }
private void AnimateAndUseCard(Card card) { GameObject toRemove = null; foreach (GameObject cardObject in _cardsOnHand) { CardScript cardScript = cardObject.GetComponent <CardScript>(); if (cardScript.Card == card) { toRemove = cardObject; LeanTween.cancel(cardObject); cardScript.SetFaceForward(); cardScript.UndoDissolve(); cardObject.transform.position = new Vector2(Screen.width / 2, Screen.height / 2); cardObject.transform.eulerAngles = Vector3.zero; cardObject.transform.localScale = new Vector3(0.95f, 0.95f, 0.95f); GameScript.AnimationState = GameScript.GameAnimationState.Animating; LTSeq seq = LeanTween.sequence(); seq.append(LeanTween .scale(cardObject, new Vector3(0.55f, 0.55f, 0.55f), 0.3f) .setEaseInCirc()); seq.append(0.8f); seq.append(() => cardScript.Dissolve(() => { _player.UseCard(card); GameScript.AnimationState = GameScript.GameAnimationState.Idle; Destroy(cardObject); }, 0.3f)); break; } } if (toRemove != null) { _cardsOnHand.Remove(toRemove); } ReArrangeCardsOnHand(0.5f); }
// When over capacity: // returns false // doesn't put the card in deck public bool InsertCard(CardScript input) { if (null != input && Length < myCardCapacity) { input.transform.parent = transform; input.myDeckScript = this; input.myRenderer.enabled = false; input.myBoxCollider.enabled = false; input.myPosition.Animate(Vector3.zero, 2); mySize.Animate(DeckSize(), .2f); return(true); } return(false); }
private void SelectCard(GameObject inputCard) { CardScript inputCardScript = inputCard.GetComponent <CardScript>(); if (inputCardScript == null) { throw new System.ArgumentException("inputCard must be a gameObject that contains a CardScript"); } if (inputCardScript.container.CompareTag("Wastepile")) { inputCardScript.container.GetComponent <WastepileScript>().DraggingCard(inputCard, true); draggingWastepile = true; } selectedCards.Add(inputCard); inputCardScript.SetSelected(true); StartDragging(); }
// When over capacity: // returns false // doesn't put the card in deck public bool InsertCard(CardScript input) { if (null != input && Length < myCardCapacity) { input.transform.parent = transform; input.myDeckScript = this; input.myRenderer.enabled = false; input.myBoxCollider.enabled = false; input.myPosition.Animate(Vector3.zero, 2); mySize.Animate(DeckSize(), .2f); return true; } return false; }
/// <summary> /// 卡牌拖拽到副卡组事件 /// </summary> /// <param name="eventData"></param> void OnDropToDeputyPanel(PointerEventData eventData) { CardScript cardScript = eventData.pointerDrag.GetComponent <CardScript>(); if (cardScript != null && cardScript.IsOwnedCard() && cardScript.transform.parent != deputyPanelTransform) { bool addSucccess = AddCardToCardGroup(CardGroupType.Deputy, cardScript.GetCard()); if (addSucccess) { if (cardScript.transform.parent == mainPanelTransform) { RemoveCardFromCardGroup(CardGroupType.Main, cardScript.GetCard()); } if (cardScript.transform.parent == extraPanelTransform) { RemoveCardFromCardGroup(CardGroupType.Extra, cardScript.GetCard()); } } } }
//Distributing the Card evenly in all selected players void DistributeCard() { int i = 0; // int cardPerPlayer = cardCounts / Game.playerCount; for (int j = 0; j < cardCounts; j++) { deckCards[j].GetComponent <RectTransform>().SetParent(playerDeckMarker[i].transform, false); CardScript cardScript = deckCards[j].GetComponent <CardScript>(); cardScript.tablePanel = deckDetailsList[i].myTablePanel; cardScript.Owner = deckDetailsList[i].gameObject.GetComponent <Player>(); deckDetailsList[i].Cards.Add(deckCards[j]); print(j + " i value " + i); i++; if (i == Game.playerCount) { i = 0; } } }
// CALLED EVERY TICK void Update() { // TOUCH SYSTEM touched = false; if (touch() && !touching) { touching = true; touched = true; // GET INITAL POSITION WHEN FIRST TOUCHING SCREEN originalInputPosition = inputPosition; // GENERATE SUB CARD IF MAIN CARD IS TOUCHED FOR THE FIRST TIME if (!mainCard.createdSubCard && mainCard.canMove) { mainCard.createdSubCard = true; GameObject sub = Instantiate(cardObject, new Vector3(0f, 0f, 5f), Quaternion.identity); sub.name = "Card"; subCard = sub.GetComponent <CardScript>(); subCard.canMove = false; } } else if (!touch() && touching) { touching = false; } // CORRECT POSITION FROM INITAL TOUCH POSITION if (touching) { correctedInputPosition = new Vector2( inputPosition.x - originalInputPosition.x, inputPosition.y - originalInputPosition.y ); } else { correctedInputPosition = Vector2.zero; } }
void trashCard() { GameScript gameScript = FindObjectOfType <Camera>().GetComponent <GameScript>(); trashDeck.Add(gameScript.getCardSelected()); if (gameScript.getCardSelObjName().Contains("Card")) { CardScript cardScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <CardScript>(); if (gameScript.getCardSelObjName().Contains("1")) { DeckScript deckScript = GameObject.Find("P1 Deck").GetComponent <DeckScript>(); deckScript.removeCard(); } else if (gameScript.getCardSelObjName().Contains("2")) { DeckScript deckScript = GameObject.Find("P2 Deck").GetComponent <DeckScript>(); deckScript.removeCard(); } cardScript.setEnabled(false); cardScript.selectCard(); //To unselect it } else if (gameScript.getCardSelObjName().Contains("Trash")) { TrashScript trashScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <TrashScript>(); trashScript.removeCard(); gameScript.setCardSelected(null); gameScript.setCardSelObjName(null); } else if (gameScript.getCardSelObjName().Contains("Main")) { HouseScript houseScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <HouseScript>(); houseScript.removeCard(); gameScript.setCardSelected(null); gameScript.setCardSelObjName(null); } loadCard(); }
bool CheckOnlyOneAce(List <CardScript> selectedCards) { numberOfAces = 0; foreach (CardScript c in selectedCards) { if (c.CardValue == 1 || c.CardValue == 11) { numberOfAces++; AceCardScript = c; } } if (numberOfAces == 1) { SetOneAceValue(AceCardScript, selectedCards); return(true); } else { return(false); } }
/// <summary> /// Deep copies this board state /// </summary> /// <returns>A copy of the board state</returns> public CardScript[][] CopyState(CardScript[][] b = null) { if (b == null) { b = Board.Instance.boardState; } CardScript[][] bc = new CardScript[5][]; for (int i = 0; i < b.Length; i++) { bc[i] = new CardScript[5]; for (int j = 0; j < b[0].Length; j++) { bc[i][j] = b[i][j]; } } //for (int i = 0; i < 3; i++) gemInsts[i].transform.position = board.CellToWorld(Board.IndexToRenderPoint(gemPlaces[i])); return(bc); }
/// <summary> /// discard a random card from the hand. exemption card is safe /// </summary> public void discardRandomCard(CardScript exemption) { //special case: no discardable cards if (discardableCardCount == 0) { return; } CardScript[] discardableCards = cards.Where(c => c != null && c.discardable).ToArray(); //get an array of cards we can actually discard to simplify the rest of this code //special case: only one card if (discardableCards.Length == 1) { if (discardableCards[0] != exemption) { discardableCards[0].SendMessage("Discard"); } return; } //general case: multiple cards CardScript target = null; while (target == null) //loop because we might randomly pick the exempt card { //pick a card int i = Random.Range(0, discardableCards.Length); target = discardableCards[i]; //if we picked the exempt card, reset and try again if (target == exemption) { target = null; continue; } //discard it target.SendMessage("Discard"); } }
void Update() { if (!isLocalPlayer) { return; } if (Input.GetMouseButtonDown(0) && canSelect && Input.mousePosition.x > Screen.width / 6.6f) { if (id < 0) { gameObject.name = "Local Player"; CmdSetUpPlayer(); } RaycastHit myHet = new RaycastHit(); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out myHet)) { //print (myHet.collider.transform.parent.gameObject.name); CardScript myCardS = myHet.collider.gameObject.GetComponentInParent <CardScript> (); if (myCardS != null) { if (!isPowerUp) { canSelect = false; CmdSelectCard(myCardS.gameObject, true, gameObject); } else { CmdSetPowerUpSelect(myCardS.gameObject); //print ("Set power up select " + myCardS.gameObject); } //if(rotatedCards[1] != null) } } } }
private void OnCardAddedToHand(Card card, bool isDrawn) { if (!_isMe) { return; } if (card.Player != _player) { return; } ClassEntry cardEntry = _cardMap.GetEntryByKey(card.ID); if (cardEntry != null) { GameObject cardInstance = Instantiate(cardEntry.data.prefab, _gameCanvas.transform); CardScript cardScript = cardInstance.GetComponent <CardScript>(); cardScript.Ready(this, card); cardInstance.transform.position = _deckObject.transform.position; cardInstance.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); float delay = 0.5f; LeanTween .scale(cardInstance, new Vector3(0.45f, 0.45f, 0.45f), delay) .setDelay(_addToHandDelay) .setOnComplete(() => { _addToHandDelay -= delay; }) .setOnStart(() => { _cardsOnHand.Add(cardInstance); ReArrangeCardsOnHand(delay); cardScript.FlipCard(true); }); _addToHandDelay += delay; } }
/// <summary> /// When a card is selected by the player /// </summary> /// <param name="card">The card that was selected</param> public void CardSelected(CardScript card) { switch (_state) { case SelectionState.PickingFirst: // display the first card, and move to next state SetCard_(card, 0); // call again to update sprite image _players[_activePlayerIndex].ActivePlayer(true, 1); _state = SelectionState.PickingSecond; break; case SelectionState.PickingSecond: // display the second card, and move to next state SetCard_(card, 1); _state = SelectionState.Resetting; // swap the cards back, or remove them StartCoroutine(Reset()); break; } }
public void gameBegin() { CardScript.resetValidFlippedCardCount(); // Zera lista de cartas viradas pairs = 0; // registro de pares é zerado sort(); updateAlertTestCanvas(false, ""); transform.position = Vector3.zero; // certifica que o DECK esteja na posição visível à câmera if (isFirstTurn && presentationMode - 1 < 0 && (isGamePresentationOn || GameManager.Instance.IsMenuPresent)) { gameIntroDirector.time = 0; if (gameIntroDirector.state != PlayState.Playing) { gameIntroDirector.Play(); } } else { hud.resetDefaultPosition(); updateScore(); // reinicia placares gameStart(); } }
public void UpdateDisplay() { drawCardText.text = drawContainment.childCount.ToString(); discardCardText.text = discardContainment.childCount.ToString(); for (int i = 0; i < cardHolder.childCount; i++) { //check if cards in hand can be played //chanes colour of stamina cost. CardScript c = cardHolder.transform.GetChild(i).GetComponent <CardScript>(); if (canUseC(c)) { c.cardStaminaText.color = Color.cyan; } else { c.cardStaminaText.color = Color.red; } } }
protected bool CheckIfShuffleCompleted() { bool theBoolForAll = true; foreach (GameObject aCard in thisInstantiatedServedCards) { if (CheckIfClickable(aCard)) { CardScript aCardScript = aCard.GetComponent <CardScript>(); if (!aCardScript.GetIfShuffleComplete()) { theBoolForAll = false; } } } if (theBoolForAll) { return(true); } return(false); }
public void OnPointerUp(PointerEventData eventData) { PointerEventData pointer = new PointerEventData(EventSystem.current); pointer.position = Input.mousePosition; List <RaycastResult> raycastResults = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, raycastResults); CardScript slot = null; foreach (RaycastResult result in raycastResults) { if (result.gameObject.GetComponent <CardScript>() != null) { slot = result.gameObject.GetComponent <CardScript>(); } } isGrabbed = false; if (!EventSystem.current.IsPointerOverGameObject()) { image.rectTransform.anchoredPosition = prevPos; } else if (slot != null && slot.card == null) { slot.collection.AddAtIndex(card, slot.index); collection.RemoveAtIndex(index); } image.rectTransform.anchoredPosition = prevPos; //image.rectTransform.anchoredPosition = transform.parent.GetComponent<RectTransform>().anchoredPosition; image.raycastTarget = true; }
public void showCard(int index) { actions++; // INICIO EXAMEN // if (index == newIndex2Card) // si la carta pulsada coincide con el indice que hemos dicho que es la segunda carta { index = newIndexLastCard; // muestra la ultima carta de la segunda fila } totalValue += cards[index].value; //añade el value de la carta mostrada a una variable para mostrarla luego // FIN EXAMEN // cards[index].show(true); if (revealedCard != null) // si no tenemos carta mostrada { if (revealedCard.value == cards[index].value) // si el valor de la carta ya mostrada coincide con la ultima carta mostrada { pairs++; cards[index].foundPair(); revealedCard.foundPair(); revealedCard = null; } else // si no son iguales, las tapamos. { revealedCard.show(false); cards[index].show(false); revealedCard = null; } } else { revealedCard = cards[index]; //establecer carta mostrada } updateInfo(); checkWinCondition(); }
private void OnMouseDrag() { if (!HandScript.Instance.IsTurn()) { Vector3 temp = Input.mousePosition; temp.z = 1.3f; transform.position = Camera.main.ScreenToWorldPoint(temp); RaycastHit hit; if (Physics.Raycast(transform.position, new Vector3(0, 0, 10), out hit, 1f)) { if (hit.transform.gameObject.GetComponent <CardScript>()) { tempCard = hit.transform.gameObject.GetComponent <CardScript>(); switchable = true; } } else { tempCard = null; switchable = false; } } }
IEnumerator HideCardsAndUnlockDelay(float delay, params CardScript[] cards) { yield return(new WaitForSeconds(delay)); foreach (CardScript c in cards) { if (c != null) { c.flipCard(false, true); } } lastCardChoosed = null; // não é mais necessária essa referência // chance de REVIRAVOLTA se haver UMA vida e ZERO pares formados if (lives == 1 && pairs == 0) { // com apenas uma vida restante StartCoroutine("TurnaroundChance"); } else { Invoke("unlockClick", 0.5f); } }
///////////////////////////////// /// <summary> /// Updates the AI of gems for both sides /// </summary> /// <param name="b">The board state</param> /// <returns></returns> public int[] UpdateGems(CardScript[][] b) { int[] score = { 0, 0 }; for (int i = 1; i < 4; i++) { for (int j = 1; j < 4; j++) { if (Board.Instance.CardOnGem(i, j, b)) { CardScript gemCard = Board.Instance.CardOnGem(i, j, b); if (gemCard.isPlayerCard) { score[0]++; } else { score[1]++; } } } } return(score); }
/// <summary> /// Initializes the game board /// </summary> private void Init() { //Only need grid if not real grid board = GetComponent <Grid>(); gemInsts = new List <GameObject>(); boardState = new CardScript[5][]; for (int i = 0; i < 5; i++) { boardState[i] = new CardScript[5]; for (int j = 0; j < 5; j++) { boardState[i][j] = null; } } gemPlaces = new List <Vector3Int>(); //set gem places for (int i = 0; i < 3; i++) { Vector3Int gemSpot = Vector3Int.zero; do { gemSpot.x = Random.Range(1, 4); gemSpot.y = Random.Range(1, 4); } while (gemPlaces.Contains(gemSpot)); gemPlaces.Add(gemSpot); //Instantiate gems if not copy GameObject g = Instantiate(gem, board.CellToWorld(Board.IndexToRenderPoint(gemPlaces[i])), Quaternion.identity); gemInsts.Add(g); } string ret = "[" + gemPlaces[0] + ", " + gemPlaces[1] + ", " + gemPlaces[2] + "]"; print(ret); }
/* * Objective: This function will discover which of the two cards on the game screen have been flipped to show the * card face, by accessing the "isFlipped" boolean varaibel that each card has in its script. */ private void FindFlippedCards() { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; foreach (GameObject obj in instanciatedCards) { CardScript cs = obj.GetComponent <CardScript>(); if (cs.isFlipped) { if (flippedCard1 == null) { flippedCard1 = obj; } else { flippedCard2 = obj; } } } EvaluateFlippedCards(); }
/// <summary> /// Checks if two cards can match together. /// </summary> /// <param name="card1"></param> /// <param name="card2"></param> /// <param name="checkIsTop">To check if the card is at the top of it's container. /// Currently, everything but foundation cards can have this be false</param> /// <returns></returns> public static bool CanMatch(CardScript card1, CardScript card2, bool checkIsTop = true) { // checks if the cards are at the top of their containers if (checkIsTop && (!IsAtContainerTop(card1) || !IsAtContainerTop(card2))) { return(false); } if (card1.cardNum != card2.cardNum) { return(false); } if ((card1.cardSuit.Equals("hearts") && card2.cardSuit.Equals("diamonds")) || (card1.cardSuit.Equals("diamonds") && card2.cardSuit.Equals("hearts")) || (card1.cardSuit.Equals("spades") && card2.cardSuit.Equals("clubs")) || (card1.cardSuit.Equals("clubs") && card2.cardSuit.Equals("spades"))) { return(true); } //otherwise not a match return(false); }
// Use this for initialization void Start() { card_image = new CardScript(CardScript.CardType.Empty); GetComponent<SpriteRenderer>().sprite = SpriteManagerScript.card_by_type(card_image.type); }
/* Places the Unit that is associated with the given card at the given x and y coordinates. */ private bool placeUnitWithCard(CardScript card, int x, int y) { // Player must have enough currency to place the Unit if (card != null && getPlayer().getCurrency() >= card.cost) { int idx = currentHand().getCards().IndexOf(focusedCard); if (idx == -1) { Debug.Log("Invalid card index!\n"); } else if (placeUnit((UnitScript.Types)((int)card.type), x, y) != null) { // play a sound when the card is used if (coin_sounds.Length > 0) { int sound = UnityEngine.Random.Range(0, coin_sounds.Length); GetComponent<AudioSource>().PlayOneShot(coin_sounds[sound]); } // use the card hand_display[idx].reset(-1, CardScript.CardType.Empty); getPlayer().changeCurrency(-card.cost); return true; } } return false; }
// Adds a card to the collection public void add(CardScript card) { cards.Add (card); }
//initialize deck void Awake() { gm = (GameManager)GameObject.Find("GameManager").GetComponent("GameManager"); //grab playerHand's Handscript component cardScript = cardObject.GetComponent<CardScript> (); playerScript = playerHand.GetComponent<HandScript> (); GameObject temp; for (int i=0; i<20; i++) { //instantiate a card object and give it its unique properties temp = (GameObject)Instantiate(cardObject); //set cardObject's texture Texture img = (Texture)Resources.Load("CardBack"); temp.GetComponent<Renderer>().material.mainTexture = img; cardScript.setCard(cardCategories[i], cardTypes[i]); _deck.Add (temp); } //shuffle the deck Shuffle (); oldPos = this.transform.position; if (this.name.Equals("P1Deck")) { playerID = 1; } else if (this.name.Equals("P2Deck")) { playerID = 2; } }
/* Returns a card sprite based on the type given. */ public static Sprite card_by_type(CardScript.CardType type) { switch (type) { case CardScript.CardType.HumanInfantry: return human_infantry_card; case CardScript.CardType.HumanTank: return human_tank_card; case CardScript.CardType.HumanExo: return human_exo_card; case CardScript.CardType.HumanArtillery: return human_artillery_card; case CardScript.CardType.AlienInfantry: return alien_infantry_card; case CardScript.CardType.AlienTank: return alien_tank_card; case CardScript.CardType.AlienElite: return alien_elite_card; case CardScript.CardType.AlienArtillery: return alien_artillery_card; case CardScript.CardType.Currency1: return bronze_card; case CardScript.CardType.Currency2: return silver_card; case CardScript.CardType.Currency3: return gold_card; default: return empty_card; } }
/* Evaluates the card at the given index in the hand being clicked. * Sets focusedCard if the cards is not a currenct card. * Returns true if the card was currency, false otherwise. */ public bool cardClicked(int idx) { if (paused) { // cards are unresponsive when the game is paused return false; } CardScript c = currentHand().getCards()[idx]; if (focusedUnit != null) { Map.unit_move_range(focusedUnit, false); Map.hex_of(focusedUnit).setFocus(false); focusedUnit = null; } // Determine if the card is currency and if so add to the player's currency and return true if (c.type == CardScript.CardType.Currency1) { getPlayer().changeCurrency(1); return true; } else if (c.type == CardScript.CardType.Currency2) { getPlayer().changeCurrency(5); return true; } else if (c.type == CardScript.CardType.Currency3) { getPlayer().changeCurrency(10); return true; } else { // card is not currency focusedCard = c; } return false; }
public Quaternion CardRotation(CardScript input) { return CardRotation(Find(input), CountCards()); }
public void addEffects(CardScript effectCard) { playerEffects.Add(effectCard); }
public Vector3 CardPosition(CardScript input) { return CardPosition(Find(input), CountCards()); }
/* Determines the action to take if a hex is clicked. */ public void hexClicked(HexScript hex) { if (!paused) { if (focusedUnit != null) { moveCurrentUnit(hex); // A space must be adjacent to the current Player's base and not a water tile } else if ( focusedCard != null && hex.getType() != HexScript.HexEnum.water && adjacent_to_base(hex) && placeUnitWithCard(focusedCard, (int)hex.position.x, (int)hex.position.y) ) { // Attempt to place the unit of the focusedCard focusedCard = null; } } }
/* Creates a card based on the given type. */ public CardScript(CardScript.CardType t) { type = t; cost = setCost(t); }
public void buyCard(CardScript.CardType type) { CardScript temp = new CardScript(type); int cost = temp.cost; if (turn == 1) { if (cost <= Player1.getCurrency()) { Player1.changeCurrency(-cost); getPlayer().getDeck().discardPile.add (new CardScript(type)); } } if (turn == 2) { if (cost <= Player2.getCurrency()) { Player2.changeCurrency(-cost); getPlayer().getDeck().discardPile.add(new CardScript(type)); } } }
int Find(CardScript cardScript) { for(int i = 0; i < myCards.Length; i++) { if(myCards[i] == cardScript) { return i; } } return -1; }
/* Removes a number of cards of the given type equal to or less than quantity from the discard pile. * Keep in mind that if there exists less cards in the discard pile than quantity the cards will * still be removed!! */ public int removeCardsFromDiscard(CardScript.CardType toRemove, int quantity) { List<CardScript> discard = discardPile.getCards(); int left = quantity; // Attempt to remove the number of cards equal to quantity for (int idx = 0; idx < discardPile.getSize();) { // Exit after removing the quantity of a card type if (left <= 0) { break; } else if (discard[idx].type.CompareTo(toRemove) == 0) { discard.RemoveAt(idx); --left; } else { ++idx; } } return quantity - left; }
public CardScript RemoveCard(CardScript input, bool discard = false) { if (input.transform.IsChildOf(transform)) { input.myHandScript = null; Reanimate(); if (discard) { EffectScript.AffectsList(input.myRemoveEffects, myOwningPlayer.ToMessage()); } return input; } return null; }