Exemplo n.º 1
0
        public void Escape(AquariumObject Hunter)
        {
            Pathfinder pathfinder = new Pathfinder(ContainingAquarium.Territory);

            int[,] WaveMap = pathfinder.GetWavemap(Hunter.X, Hunter.Y);
            int xMax = 0, yMax = 0, MaxWave = 0;

            for (int i = 0 > X - 1 ? 0 : X - 1, iMax = X + 1 < xField ? X + 1 : xField - 1; i <= iMax; i++)
            {
                for (int j = 0 > Y - 1 ? 0 : Y - 1, jMax = Y + 1 < yField ? Y + 1 : yField - 1; j <= jMax; j++)
                {
                    if (MaxWave < WaveMap[i, j] && ContainingAquarium.Territory[i, j] == null)
                    {
                        MaxWave = WaveMap[i, j];
                        xMax    = i;
                        yMax    = j;
                    }
                }
            }
            if (MaxWave == 0)
            {
                throw new Exception("Cannot escape death.");
            }
            try
            {
                ContainingAquarium.ObjectIsMovingTo(this, xMax, yMax);
                this.X = xMax;
                this.Y = yMax;
            }
            catch { }
        }
Exemplo n.º 2
0
        public virtual void Mate()
        {
            Fish couple = GetClosestSuitableObject(CanMate) as Fish;

            if (couple == null)
            {
                throw new Exception("Couple not found");
            }
            if (Math.Abs(this.X - couple.X) == 1 && Math.Abs(this.Y - couple.Y) == 1)
            {
                if (Gender == false)
                {
                    Impregnant();
                }
                else
                {
                    couple.Impregnant();
                }
            }
            else
            {
                MakePath(couple.X, couple.Y);
                try
                {
                    ContainingAquarium.ObjectIsMovingTo(this, Path[0].x, Path[0].y);
                    this.X = Path[0].x;
                    this.Y = Path[0].y;
                }
                catch { }
            }
            return;
        }
Exemplo n.º 3
0
        protected override void Eat()
        {
            Seaweed food = GetClosestSuitableObject(CanBeEaten) as Seaweed;

            if (food == null)
            {
                throw new Exception("Food not found");
            }
            if (Math.Abs(this.X - food.X) <= 1 && Math.Abs(this.Y - food.Y) <= 1)
            {
                Satiety += food.Feed(MaxSatiety - Satiety);
            }
            else
            {
                MakePath(food.X, food.Y);
                ContainingAquarium.ObjectIsMovingTo(this, Path[0].x, Path[0].y);
                this.X = Path[0].x; this.Y = Path[0].y;
            }
        }