Пример #1
0
        /// <summary>
        /// Eat
        /// </summary>
        /// <param name="da">Doodle agent</param>
        /// <param name="newLine">Line</param>
        /// <param name="newColumn">Column</param>
        public void Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            // Get ant
            AntAgent ant = (AntAgent)Map[newLine, newColumn].AgentInCell;

            // Delete game object
            Map[newLine, newColumn].SetState(null);
            // Remove agent
            _environment.Remove(ant);
            // Move doodlebug to the new location
            Move(da, newLine, newColumn);
        }
Пример #2
0
        /// <summary>
        /// Try to eat
        /// </summary>
        /// <returns>True is the action is valid</returns>
        private bool TryToEat()
        {
            List <Tuple <int, int> > positions = new List <Tuple <int, int> >();

            for (int i = 0; i < 4; i++)
            {
                if (_world.ValidMovement(this, (Direction)i, CellState.Ant, out int newLine, out int newColumn))
                {
                    positions.Add(new Tuple <int, int>(newLine, newColumn));
                }
            }

            if (positions.Count == 0)
            {
                return(false);
            }

            int      r   = Settings.Rand.Next(positions.Count);
            AntAgent ant = _world.Eat(this, positions[r].Item1, positions[r].Item2);

            Environment.Remove(ant);
            return(true);
        }