예제 #1
0
    /// <summary>
    /// Does a function every frame for x amount of seconds.
    /// </summary>
    protected IEnumerator DoForSeconds(DoFor callback, float time, DoEnd doOnEnd = null)
    {
        doFor += callback;
        float timer = 0.0f;

        if (doOnEnd != null)
        {
            doEnd += doOnEnd;
        }
        while (timer < time)
        {
            if (StateManager.Instance.IsRunning())
            {
                doFor();
                timer += DeltaTime;
            }
            yield return(null);
        }
        if (doEnd != null)
        {
            doEnd();
            doEnd -= doOnEnd;
        }
        doFor -= callback;
    }
예제 #2
0
        /// <summary>
        /// this method starts the life cycle of bunnies
        /// </summary>
        private void RunCycle()
        {
            while (!DoEnd.AreOnlyVampiresleft(_bunnies))//As long as there is at least one regular bunny, the program will keep working.
            {
                Task taskStopper = Times.Stopper();

                taskStopper.Start();

                if (_bunnies.Count > 500)//if the quantity of bunnies is more then 500, they will die by natural causes
                {
                    Logic.KillHalf(_bunnies);
                }

                Logic.KillOldBunnies(_bunnies);
                Logic.DoBite(_bunnies);
                List <Bunny> newBunnies = Logic.GenerateRandomBunnies(_bunnies);

                //adds new bunnies to list

                foreach (Bunny bunny in newBunnies)
                {
                    _bunnies.Add(bunny);
                }

                Logic.AddYearToBunnies(_bunnies);

                Print.PrintBunniesChangesOverTheYear(_bunnies);

                Times.RunTime();

                Print.PrintYearInfo(CUR_YEAR);
                CUR_YEAR++;
            }

            DoEnd.PrintEnd();
        }