Exemple #1
0
    //Made this its own class so that we could use a for loop to draw 5 cards
    public void DrawCard()
    {
        //looping through each deck in play
        foreach (Deck deck in GameManager.Instance.Decks)
        {
            //finding the correct deck to be used
            if (deck.DeckId == GameManager.Instance.deckPicked)
            {
                //checking to make sure there are cards left in the deck
                if (deck.Cards.Count != 0)
                {
                    //retrieving the object created in the form of the "instance" earlier
                    holder = ScriptableObject.FindObjectOfType <CardRetrievalFromDeck>();
                    //calling  the object's CardDrawRandomizer function, which selects a random card from the deck
                    holder.CardDrawRandomizer();
                    //calling this script's generateCardObject function,  which creates an object to represent the card
                    generateCardObject();
                    //calling the script object's setSprite function, which passes in the SpriteRenderer, and sets it's sprite to the corresponding card chosen in CardDrawRandomizer
                    holder.setSprite(sr);

                    if (deck.Cards.Count == 0)
                    {
                        //calling this script's changeDeck function, which replaces the deck with an out of cards image
                        changeDeck();
                    }
                }
                else
                {
                }
            }
        }
    }
    //will be called to perform the actions of the card
    public void performAction()
    {
        GameManager.Instance.cardInfoPanel.SetActive(false);

        cardObject = GameManager.Instance.DraggedCard;

        //CHECKS FOR THE HUMAN ACTIONS
        for (int j = 0; j < GameManager.Instance.HumanPlacement.Count; j++) //gets length of array
        {
            if (cardObject.name == GameManager.Instance.HumanPlacement[j].CardName)
            {
                if (GameManager.Instance.HumanPlacement[j].ActionID.Count != 0)           //only goes in if there are action
                {
                    cardAction = GameObject.Find("Main Camera").GetComponent <Actions>(); //gets the script
                    cardAction.checkAction(GameManager.Instance.HumanPlacement[j]);       //executes cards actions

                    //WHERE THE HUMAN CARD SHOULD BE REMOVED AND PUT INTO THE DISCARD PILE
                    humanCard = GameManager.Instance.HumanPlacement[j];   //sets the human card to this
                    GameManager.Instance.DiscardPlacement.Add(humanCard); //adds this to the discard placementlist

                    Destroy(cardObject);

                    cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Discard Pile Placement").transform; //sets the card parent
                    holder.cardNameHolder = humanCard.CardName;                                                                                 //card name needed to get card image
                    generateCardObject();
                    holder.setSprite(sr);

                    GameManager.Instance.HumanPlacement.RemoveAt(j); //removes the card from the array list
                }
                else
                {
                    break; //just gets out of the loop and continues
                }
            }
        }

        //CHECKS FOR THE MULTIPLYER ACTIONS
        for (int j = 0; j < GameManager.Instance.MultiPlacement.Count; j++) //gets length of array
        {
            if (cardObject.name == GameManager.Instance.MultiPlacement[j].CardName)
            {
                if (GameManager.Instance.MultiPlacement[j].ActionID.Count != 0)           //only goes in if there are action
                {
                    cardAction = GameObject.Find("Main Camera").GetComponent <Actions>(); //gets the script
                    cardAction.checkAction(GameManager.Instance.MultiPlacement[j]);       //executes cards actions

                    //WHERE THE Multiplayer CARD SHOULD BE REMOVED AND PUT INTO THE DISCARD PILE
                    multiCard = GameManager.Instance.MultiPlacement[j];   //sets the human card to this
                    GameManager.Instance.DiscardPlacement.Add(multiCard); //adds this to the discard placementlist

                    Destroy(cardObject);

                    cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Discard Pile Placement").transform; //sets the card parent
                    holder.cardNameHolder = multiCard.CardName;                                                                                 //card name needed to get card image
                    generateCardObject();
                    holder.setSprite(sr);

                    GameManager.Instance.MultiPlacement.RemoveAt(j); //removes the card from the array list
                }
                else
                {
                    break; //just gets out of the loop and continues
                }
            }
        }
    }
    //whenever the user clicks down on the object then this function of selecting the card will occur
    private void OnMouseDown()
    {
        //GOES THROUGH THE DECK, GETS THE SELECTED CARD, REMOVES IT FROM THE DECK, ADDS IT TO THE CORRECT PILE, DISPLAYS CARD
        foreach (Deck deck in GameManager.Instance.Decks)
        {
            if (deck.DeckId == GameManager.Instance.deckPicked) //makes sure we are in the right deck
            {
                for (int i = 0; i < deck.Cards.Count; i++)
                {
                    if (this.gameObject.name == deck.Cards[i].CardName) //makes sure the card in the deck mtches the selected one
                    {
                        selectedCard = deck.Cards[i];                   //sets the card to the card object for easier use
                        int changeScore = 0;

                        //checks the card type to maek sure which pile it is in
                        if (deck.Cards[i].CardType == "Animal")
                        {
                            Debug.Log(selectedCard.CardName);
                            GameManager.Instance.AnimalPlacement.Add(deck.Cards[i]);                                                                   //adds it to the placement

                            cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Animal Card Placement").transform; //gets the variable that was set in the actions
                            holder.cardNameHolder = deck.Cards[i].CardName;                                                                            //card name needed to get card image
                            generateCardObject();
                            holder.setSprite(sr);

                            changeScore = deck.Cards[i].PointValue;

                            deck.Cards.Remove(deck.Cards[i]); //removes it from the deck
                        }
                        else if (deck.Cards[i].CardType == "Plant")
                        {
                            Debug.Log(selectedCard.CardName);
                            GameManager.Instance.PlantPlacement.Add(deck.Cards[i]); //adds it to placement

                            cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Plant Card Placement").transform;
                            holder.cardNameHolder = deck.Cards[i].CardName; //card name needed to get card image
                            generateCardObject();
                            holder.setSprite(sr);

                            changeScore = deck.Cards[i].PointValue;

                            deck.Cards.Remove(deck.Cards[i]); //removes it from the deck
                        }
                        else if (deck.Cards[i].CardType == "Condition")
                        {
                            Debug.Log(selectedCard.CardName);
                            GameManager.Instance.ConditionPlacement.Add(deck.Cards[i]); //adds it to the placement

                            cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Condition Card Placement").transform;
                            holder.cardNameHolder = deck.Cards[i].CardName; //card name needed to get card image
                            generateCardObject();
                            holder.setSprite(sr);

                            changeScore = deck.Cards[i].PointValue;

                            deck.Cards.Remove(deck.Cards[i]); //removes it from the deck
                        }
                        else if (deck.Cards[i].CardType == "Invertebrate")
                        {
                            Debug.Log(selectedCard.CardName);
                            GameManager.Instance.ConditionPlacement.Add(deck.Cards[i]); //adds it to the placement

                            cardParent            = GameObject.Find("Game Board Container/Player Board/Board/Player/Invertebrate Card Placement").transform;
                            holder.cardNameHolder = deck.Cards[i].CardName; //card name needed to get card image
                            generateCardObject();
                            holder.setSprite(sr);

                            changeScore = deck.Cards[i].PointValue;

                            deck.Cards.Remove(deck.Cards[i]); //removes it from the deck
                        }

                        //to clear the lists that are used
                        GameManager.Instance.DeckSelectionList.Clear();
                        GameManager.Instance.DiscardSelectionList.Clear();

                        //have to clear out the panels that contain the deck and discard piles to ensure there are no problems whenver another card needs to access them
                        cardParent = GameObject.Find("DeckShow").transform; //gets the deckshow parent set to an object
                        int deckShowCount = cardParent.childCount;          //gets the number of cards in the panel

                        for (int j = deckShowCount - 1; j >= 0; j--)        //to go through the panel cards
                        {
                            //goes through the panel and destroys every card in the panel
                            UnityEngine.Object.Destroy(cardParent.GetChild(j).gameObject);
                        }

                        cardParent = GameObject.Find("DiscardShow").transform; //gets the deckshow parent set to an object
                        int discardShowCount = cardParent.childCount;          //gets the number of cards in the panel

                        for (int j = discardShowCount - 1; j >= 0; j--)        //to go through the panel cards
                        {
                            //goes through the panel and destroys every card in the panel
                            UnityEngine.Object.Destroy(cardParent.GetChild(j).gameObject);
                        }

                        GameManager.Instance.playerCanvas.alpha          = 1f;
                        GameManager.Instance.playerCanvas.blocksRaycasts = true;
                        GameManager.Instance.playerCanvas.interactable   = true;
                        GameManager.Instance.playerView.SetActive(true);     //sets the view as active
                        showBoard.hideDeckDiscard();                         //goes back to the player

                        GameManager.Instance.changePlayerScore(changeScore); //changes the score
                    }
                }
            }
        }
    }