コード例 #1
0
ファイル: CP2AI.cs プロジェクト: ambimental/CIS_411-EoE_Unity
    // Use this for initialization
    void Start()
    {
        scriptInstance = ScriptableObject.CreateInstance("CardRetrievalFromDeck");       //so you can use the script
        holder         = ScriptableObject.FindObjectOfType <CardRetrievalFromDeck>();    //access to script
        changePlayer   = GameObject.Find("Main Camera").GetComponent <HideShowBoards>(); //to change players
        cameraHolder   = GameObject.Find("Main Camera");                                 //sets the object to the main camera to add and destroy gameobjects

        if (GameManager.Instance.round == 1)                                             //will only happen in the first round
        {
            for (int i = 0; i < 5; i++)
            {
                holder.drawCP2Deck(); //adds the cards to the computers hand

                //draws a card and puts it into the hand
                cardParent            = GameObject.Find("Computer Two Board/CP2Hand").transform;
                holder.cardNameHolder = "back_of_card";
                generateCardObject();
                holder.setSpriteCP1(sr); //generating the card object to be placed into the panel
            }
        }

        StartCoroutine("computerPerforms");
    }
コード例 #2
0
ファイル: CP2AI.cs プロジェクト: ambimental/CIS_411-EoE_Unity
    //where teh card things will take place
    IEnumerator computerPerforms()
    {
        if (GameManager.Instance.getCP2TotalRegions() < 5)       //will determine how many cards they draw based on regions
        {
            holder.drawCP2Deck();                                //draws a card every roun
        }
        else if (GameManager.Instance.getCP2TotalRegions() < 10) //2 cards drawn
        {
            int count = 0;

            while (count < 2)
            {
                holder.drawCP2Deck();
                count++;
            }
        }
        else if (GameManager.Instance.getCP2TotalRegions() < 15) //3 cards drawn
        {
            int count = 0;

            while (count < 3)
            {
                holder.drawCP2Deck();
                count++;
            }
        }
        else if (GameManager.Instance.getCP2TotalRegions() < 20) //4 cards drawn
        {
            int count = 0;

            while (count < 4)
            {
                holder.drawCP2Deck();
                count++;
            }
        }

        //draws a card and puts it into the hand
        cardParent            = GameObject.Find("Computer Two Board/CP2Hand").transform;
        holder.cardNameHolder = "back_of_card";
        generateCardObject();
        holder.setSpriteCP1(sr); //generating the card object to be placed into the panel

        //add the check for more than 5 regions so that extra draws can be done

        //this is where the requirements will be checked
        for (int z = GameManager.Instance.HandCP2.Count - 1; z > -1; z--) //done this way to avoid exception
        {
            for (int i = 0; i < 20; i++)
            {
                yield return(null);
            }

            if (GameManager.Instance.HandCP2[z].ReqID.Count != 0)
            {
                cardReqs = GameObject.Find("Main Camera").GetComponent <RequirementsCP2>();

                if (cardReqs.requirementCheck(GameManager.Instance.HandCP2[z])) //determines if they work or not
                {
                    requirementsWork = true;
                }
                else
                {
                    requirementsWork = false;
                }
            }
            else
            {
                requirementsWork = true; //allows it to be played
            }

            if (requirementsWork == true)
            {
                if (GameManager.Instance.HandCP2[z].CardType == "Region") //puts the card into the region placement
                {
                    cardParent            = GameObject.Find("Computer Two Board/Region Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.RegionPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //checks the region type and changes the variable accordingly
                    if (GameManager.Instance.HandCP2[z].CardName.Contains("Arid"))
                    {
                        GameManager.Instance.cp2AridCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Forest"))
                    {
                        GameManager.Instance.cp2ForestCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Grasslands"))
                    {
                        GameManager.Instance.cp2GrasslandsCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Running-Water"))
                    {
                        GameManager.Instance.cp2RunningWaterCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Salt-Water"))
                    {
                        GameManager.Instance.cp2SaltWaterCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Standing-Water"))
                    {
                        GameManager.Instance.cp2StandingWaterCount++;
                    }
                    else if (GameManager.Instance.HandCP2[z].CardName.Contains("Sub-Zero"))
                    {
                        GameManager.Instance.cp2SubZeroCount++;
                    }

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.RegionPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.RegionPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.RegionPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.RegionPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.RegionPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Condition") //puts the card into the condition card
                {
                    cardParent            = GameObject.Find("Computer Two Board/Condition Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.ConditionPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.ConditionPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.ConditionPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.ConditionPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.ConditionPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.ConditionPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Plant") //puts the card into the plant type
                {
                    cardParent            = GameObject.Find("Computer Two Board/Plant Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.PlantPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions\

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.PlantPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.PlantPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.PlantPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.PlantPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.PlantPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    //to avoid a null exception error
                    if (GameManager.Instance.HandCP2.Count > 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Invertebrate") //puts the card into the invertebrate pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Invertebrate Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.InvertebratePlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.InvertebratePlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.InvertebratePlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.InvertebratePlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.InvertebratePlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.InvertebratePlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    //to avoid null exception error
                    if (GameManager.Instance.HandCP2.Count != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Animal") //puts the cards into the animal pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Animal Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.AnimalPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.AnimalPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.AnimalPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.AnimalPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.AnimalPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.AnimalPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Special Region") //puts the card into the special region pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Special Region Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.SpecialRegionPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.SpecialRegionPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.SpecialRegionPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.SpecialRegionPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.SpecialRegionPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.SpecialRegionPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Multi-Player") //puts the card into the multiplayer pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Multiplayer Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.MultiPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.MultiPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.MultiPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.MultiPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.MultiPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.MultiPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Microbe") //puts the card into the microbe pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Microbe Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.MicrobePlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checked and completed

                    /*for (int j = 0; j < GameManager.Instance.MicrobePlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.MicrobePlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.MicrobePlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.MicrobePlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.MicrobePlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
                else if (GameManager.Instance.HandCP2[z].CardType == "Fungi") //puts the card into the fungi pile
                {
                    cardParent            = GameObject.Find("Computer Two Board/Fungi Card Placement").transform;
                    holder.cardNameHolder = GameManager.Instance.HandCP2[z].CardName;
                    generateCardObject();
                    holder.setSpriteCP2(sr); //generating the card object to be placed into the panel

                    GameManager.Instance.changeComputerTwoScore(GameManager.Instance.HandCP2[z].PointValue);

                    GameManager.Instance.FungiPlacementCP2.Add(GameManager.Instance.HandCP2[z]); //adds it to the regions

                    //actions are checkd and completed

                    /*for (int j = 0; j < GameManager.Instance.FungiPlacementCP2.Count; j++) //gets length of array
                     * {
                     *  if (GameManager.Instance.HandCP2[z].CardName == GameManager.Instance.FungiPlacementCP2[j].CardName)
                     *  {
                     *      if (GameManager.Instance.FungiPlacementCP2[j].ActionID.Count != 0) //only goes in if there are action
                     *      {
                     *          cardAction = GameObject.Find("Main Camera").GetComponent<ActionsCP2>(); //gets the script
                     *          Debug.Log(GameManager.Instance.FungiPlacementCP2[j].CardName);
                     *          cardAction.checkAction(GameManager.Instance.FungiPlacementCP2[j]); //executes cards actions
                     *      }
                     *      else
                     *      {
                     *          break; //just gets out of the loop and continues
                     *      }
                     *  }
                     * }*/

                    GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[z]);

                    cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

                    if (cardParent.childCount != 0)
                    {
                        Destroy(cardParent.GetChild(0).gameObject);
                    }
                }
            }
        }

        if (GameManager.Instance.HandCP2.Count != 0) //if there is a card left in the hand, it will discad the fits one
        {
            cardParent            = GameObject.Find("Computer Two Board/Discard Pile Placement").transform;
            holder.cardNameHolder = GameManager.Instance.HandCP2[0].CardName;
            generateDiscardObject();
            holder.setSpriteCP2(sr);

            GameManager.Instance.DiscardPlacementCP2.Add(GameManager.Instance.HandCP2[0]);
            GameManager.Instance.HandCP2.Remove(GameManager.Instance.HandCP2[0]);

            cardParent = GameObject.Find("Computer Two Board/CP2Hand").transform;

            if (cardParent.childCount != 0)
            {
                Destroy(cardParent.GetChild(0).gameObject);
            }

            for (int i = 0; i < 20; i++)
            {
                yield return(null);
            }

            nextPlayer();

            cameraHolder.AddComponent <CP3AI>();                 //adds the script to the main camera so that the actions take place

            Object.Destroy(cameraHolder.GetComponent <CP2AI>()); //destryos the cp1 script
        }
        else //if there are no cards left in the hand, will just automatically go to the next player
        {
            for (int i = 0; i < 20; i++)
            {
                yield return(null);
            }

            nextPlayer();

            cameraHolder.AddComponent <CP3AI>();                 //adds the script to the main camera so that the actions take place

            Object.Destroy(cameraHolder.GetComponent <CP2AI>()); //destryos the cp1 script
        }
    }