Esempio n. 1
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;
        }
Esempio n. 2
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 { }
        }
Esempio n. 3
0
        protected override void GiveBirth()
        {
            Point place = GetFreePlace(X, Y);

            ContainingAquarium.ObjectCreatingIn(new HerbivoreFish(ContainingAquarium, place.x, place.y, (new Random()).Next(2) == 1, 0, 100), place.x, place.y);
            CurrentPregnancy = 0;
            return;
        }
Esempio n. 4
0
 protected void Expand()
 {
     AquariumObject[,] territory = ContainingAquarium.Territory;
     try
     {
         Point place = GetFreePlace(X, Y);
         ContainingAquarium.ObjectCreatingIn(new Seaweed(ContainingAquarium, place.x, place.y, 0), place.x, place.y);
     }
     catch { }
     finally
     {
         CurrentPeriodOfGrowth = 0;
     }
 }
Esempio n. 5
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;
            }
        }