Beispiel #1
0
 public void RemoveAIBirdAndCalculateTheNewBestBirdsDna(BirdEvolutionAI birdEvolutionAIToRemove)
 {
     // INSERTING THE BIRDS DNA TO THE CHOOSEN DNA'S ARRAY IF IT IS THE BEST BIRD VIA FITNESS FUNCTION
     // now looping the best birds array and comparing to check if we need to switch with some bird
     if (choosedBirdsDNAPool.Count < 2)
     {
         choosedBirdsDNAPool.Add(new Tuple <float, BirdDNA>(birdEvolutionAIToRemove.Fitness(), birdEvolutionAIToRemove.Dna));
     }
     else
     {
         for (int bestBirdIndex = 0; bestBirdIndex < 2; bestBirdIndex++)
         {
             if (birdEvolutionAIToRemove.Fitness() > choosedBirdsDNAPool[bestBirdIndex].val1)
             {
                 choosedBirdsDNAPool[bestBirdIndex] = new Tuple <float, BirdDNA>(birdEvolutionAIToRemove.Fitness(), birdEvolutionAIToRemove.Dna);
                 break;
             }
         }
     }
 }
Beispiel #2
0
    public void Kill()
    {
        // TODO CHANGE THIS CHECK OF WHO IS THE WINNER

        // just in case we have a player component
        BirdPlayer playerComponent = this.GetComponent <BirdPlayer>();

        //// if player is alive and
        //if (GameManager.instance.amountOfBirdsAlive == 1)
        //{

        //    // if we are the last bird alive we should check if we are player or AI

        //    if (GameManager.instance.amountOfBirdsAlive == 1)
        //    {
        //        if (this.GetComponent<BirdPlayer>())
        //        {
        //            ScoreManager.AddPointToPlayer();
        //        }
        //        else
        //        {
        //            ScoreManager.AddPointToAI();
        //        }
        //    }
        //}
        GameManager.instance.DecCurrentlyAliveBirdsCounterAndCheckForEndRound();

        // checking if we our an evolutional AI Bird, if we are then call its kill function as well
        BirdEvolutionAI birdEvoAI = this.GetComponent <BirdEvolutionAI>();

        if (birdEvoAI)
        {
            birdEvoAI.KillEvolutionAIBird();
        }

        // removing this gameobject to the camera to stop following it
        CameraFollow.targets.Remove(this.gameObject);

        // instantiating the death explosion effect
        Instantiate(deathParticleSystem, transform.position, transform.rotation);
        // destory this bird gameobject
        Destroy(this.gameObject);

        // checking victory
        // if the player dies that show end game UI and add score to AI
        if (playerComponent)
        {
            ScoreManager.AddPointToAI();
            GameManager.instance.PauseGame();
            playerComponent.whoWinnerPanelToEnable.SetActive(true);
            playerComponent.whoWinnerText.text = "The Bot defeated You!";
        }
        else
        {
            // we are here if we have 2 birds on screen and one of them is the player
            if (GameManager.instance.amountOfBirdsAlive == 1)
            {
                ScoreManager.AddPointToPlayer();
                GameManager.instance.PauseGame();
                BirdPlayer.singelton.whoWinnerPanelToEnable.SetActive(true);
                BirdPlayer.singelton.whoWinnerText.text = "You have defeated the Bot!";
            }
        }
    }