Exemplo n.º 1
0
        private bool Collect(CollectBehavior<T> objectWithSmth, Hero hero)
        {
            if (objectWithSmth.CurrentCount <= 0)
                return false;

            int smthToBagCount = objectWithSmth.CurrentCount < objectWithSmth.PerCollectCount
                ? objectWithSmth.CurrentCount
                : objectWithSmth.PerCollectCount;

            var addedToBagCount = 0;

            for (int i = 0; i < smthToBagCount; i++)
            {
                var objToBag = objectWithSmth.GetSmth();
                if (!hero.AddToBag(objToBag))
                    break;
                
                addedToBagCount++;
            }

            var newCurrent = objectWithSmth.CurrentCount - addedToBagCount;

            objectWithSmth.CurrentCount = Math.Max(0, newCurrent);;

            return objectWithSmth.CurrentCount > 0 && addedToBagCount == smthToBagCount && !hero.Bag.IsFull;
        }
Exemplo n.º 2
0
 public ShakingTree(MobileObject mobileObject, Func <CollectBehavior <Berry> > treeBehaviorFunc)
 {
     _mobileObject    = mobileObject;
     _maxRestingTicks = Game.Random.Next(MAX_MAXSHAKINGTICK);
     TreeBehavior     = treeBehaviorFunc();
 }