Exemplo n.º 1
0
        public void Move()
        {
            if (!_heading.IsEmpty)
            {
                int x;
                int y;

                _previousPositions.Put(_position);

                x = _position.X + _heading.X;
                y = _position.Y + _heading.Y;

                if (x < 0 || y < 0 || x > _owner.Size.Width - 1 || y > _owner.Size.Height)
                {
                    if (_owner.Wrap)
                    {
                        if (x < 0)
                        {
                            x = _owner.Size.Width - 1;
                        }
                        else if (x > _owner.Size.Width - 1)
                        {
                            x = 1;
                        }

                        if (y < 0)
                        {
                            y = _owner.Size.Height - 1;
                        }
                        else if (y > _owner.Size.Height - 1)
                        {
                            y = 1;
                        }

                        _position = new Point(x, y);
                    }
                    else
                    {
                        _heading = Compass.GetOpposite(_heading);
                    }
                }
                else
                {
                    _position = new Point(x, y);
                }
            }
        }
Exemplo n.º 2
0
        private void MoveStrand(Strand strand)
        {
            Chemoeffector noxious;

            strand.Move();

            noxious = this.GetClosestRepellor(strand);

            if (noxious != null)
            {
                this.Flee(strand, noxious);
            }
            else
            {
                Chemoeffector food;

                food = this.GetClosestAttractor(strand);

                if (food != null)
                {
                    this.Approach(strand, food);
                }
                else if (strand.PreviousSensor != 0)
                {
                    strand.Heading = Compass.GetOpposite(strand.Heading);
                    this.Tumble(strand);
                    strand.PreviousSensor = 0;
                    this.CheckCollisions(strand);
                }
                else
                {
                    this.Tumble(strand);
                    strand.PreviousSensor = 0;
                    this.CheckCollisions(strand);
                }
            }
        }