Пример #1
0
        public bool RemoveAgent(IAgentFlockable agent)
        {
            // find the index of the agent in the flock
            int agentIndex = -1;

            for (int i = 0; i < flockMembers; i++)
            {
                if (agents[i] == agent)
                {
                    agentIndex = i;
                    break;
                }
            }

            // the agent is not part of the flock
            if (agentIndex == -1)
            {
                return(false);
            }

            // shift the other agents' indices down
            for (int i = agentIndex; i < flockMembers - 1; i++)
            {
                agents[i] = agents[i + 1];
            }

            flockMembers--;
            return(true);
        }
        public bool AddAgent(IAgentFlockable agent)
        {
            // no more room in the flock
            if (flockMembers >= agents.Length)
                return false;

            // agent was added
            agents[flockMembers++] = agent;
            return true;
        }
Пример #3
0
        public bool AddAgent(IAgentFlockable agent)
        {
            // no more room in the flock
            if (flockMembers >= agents.Length)
            {
                return(false);
            }

            // agent was added
            agents[flockMembers++] = agent;
            return(true);
        }
        public bool RemoveAgent(IAgentFlockable agent)
        {
            // find the index of the agent in the flock
            int agentIndex = -1;
            for (int i = 0; i < flockMembers; i++)
            {
                if (agents[i] == agent) 
                {
                    agentIndex = i;
                    break;
                }
            }

            // the agent is not part of the flock
            if (agentIndex == -1)
                return false;

            // shift the other agents' indices down
            for (int i = agentIndex; i < flockMembers - 1; i++)
                agents[i] = agents[i + 1];

            flockMembers--;
            return true;
        }