예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            AquariumObject ToInsert;

            switch (comboBox1.SelectedItem.ToString())
            {
            case "Rock":
                ToInsert = new Rock(HereWeGo, selectedX, selectedY);
                break;

            case "Seaweed":
                ToInsert = new Seaweed(HereWeGo, selectedX, selectedY, (int)FoodField.Value);
                break;

            case "Herbivore":
                ToInsert = new HerbivoreFish(HereWeGo, selectedX, selectedY, GenderField.SelectedItem.ToString() == "Male" ? true : false, (int)AgeField.Value, (int)SatietyField.Value, (int)FoodField.Value, (int)PregnancyField.Value);
                break;

            case "Predator":
                ToInsert = new PredatorFish(HereWeGo, selectedX, selectedY, GenderField.SelectedItem.ToString() == "Male" ? true : false, (int)AgeField.Value, (int)SatietyField.Value, (int)PregnancyField.Value);
                break;

            default:
                ToInsert = null;
                break;
            }
            HereWeGo.Territory[selectedX, selectedY] = ToInsert;
            DrawAquarium(HereWeGo, tableLayoutPanel1);
        }
예제 #2
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;
            }
        }
예제 #3
0
 public HerbivoreFish(Aquarium containingAquarium, int x, int y, bool gender, int age, int satiety, int food = 5, int pregnancyTime = 0) : base(containingAquarium, x, y, gender, age, satiety, pregnancyTime)
 {
     Food    = food;
     CanMate = new Func <AquariumObject, bool>((AquariumObject obj) =>
     {
         Fish found = obj as HerbivoreFish;
         if (found != null && (GetType() == obj.GetType()) && found.Age >= AdulthoodBound && found.Gender != this.Gender && found.CurrentPregnancy == 0)
         {
             return(true);
         }
         return(false);
     });
     CanBeEaten = new Func <AquariumObject, bool>((AquariumObject obj) =>
     {
         Seaweed found = obj as Seaweed;
         if (found != null)
         {
             return(true);
         }
         return(false);
     });
 }