Пример #1
0
        /// <summary>
        /// Moves one bee at the free place. 
        /// </summary>
        /// <param name="bee">Bee to move. If equals null random bee will be moved.</param>
        private void MoveOneBee(Bee bee = null)
        {
            if (!_bees.Any())
                return;
            else
            {
                if (bee == null)
                    bee =_bees.Keys.ToList()[_random.Next(_bees.Count)]; // Select random bee

                Point newLocation = FindNonOverlappingPoint(bee.Size);
                bee.Location = newLocation; // Actualize bee object
                _bees[bee] = newLocation; // Actualize bee dictionary
                OnBeeMoved(new BeeMovedEventArgs(bee, newLocation.X, newLocation.Y));
            }
        }
Пример #2
0
 public BeeMovedEventArgs(Bee beeThatMoved, double x, double y)
 {
     BeeThatMoved = beeThatMoved;
     X = x;
     Y = y;
 }
Пример #3
0
        /// <summary>
        /// Create from 5 to 15 bees if there isn't any on the play area. If bees are on the play area they 
        /// will be moved to new locations.
        /// </summary>
        private void CreateBees()
        {
            if (PlayAreaSize.IsEmpty) // Check if area is empty
                return;
            else
            {
                if (_bees.Count > 0) // Check if there is any bee
                    foreach (Bee bee in _bees.Keys)
                    {
                        MoveOneBee(bee);
                    }
                else
                {
                    int beesAmount = _random.Next(5, 16);
                    Bee newBee = null;

                    for (int i = 0; i < beesAmount; i++)
                    {
                        var beeSize = new Size(_random.Next(40, 151), _random.Next(40, 151));
                        var beeLocation = FindNonOverlappingPoint(beeSize);
                        newBee = new Bee(beeLocation, beeSize);

                        _bees.Add(newBee,beeLocation);
                        OnBeeMoved(new BeeMovedEventArgs(newBee, beeLocation.X, beeLocation.Y));
                    }
                }
            }
        }