예제 #1
0
 protected override double GetAttraction(Creature c)
 {
     // Adults try to kill Creatures
     if (Attack(c))
         return 10;
     return base.GetAttraction(c);
 }
예제 #2
0
        private void Add(Creature c)
        {
            c.ReproduceAction = reproduceAction;

            Creatures.Add(c);
            view1.Children.Add(c);
        }
예제 #3
0
        public Creature(Point3D position, Creature mother, Creature father)
        {
            Mother = mother;
            Father = father;
            Gender = randomizer.Next(2) == 0 ? Gender.Male : Gender.Female;

            Position = position;

            Heading = 0;
            Speed = 0;
            AngularSpeed = 0;
            Acceleration = 0;
            BirthTime = GetRandom(5, 3);
            ChildhoodDuration = GetRandom(20, 10);
            LifeTime = GetRandom(90, 30);
            PrivacyDist = 2.5;
            double bmiMean = 25;
            double maxSpeedMean = 3;
            double heightMean = 1.75;
            if (mother != null)
            {
                heightMean = (Mother.GrownupHeight + Father.GrownupHeight) / 2;
                bmiMean = (Mother.BMI + Father.BMI) / 2;
                maxSpeedMean = (Mother.MaxSpeed + Father.MaxSpeed) / 2;
            }
            BMI = GetRandom(bmiMean, bmiMean / 2);
            GrownupHeight = GetRandom(heightMean, 0.5);
            MaxSpeed = Gender == Gender.Male ? GetRandom(maxSpeedMean + 2, 1) : GetRandom(maxSpeedMean, 1);
            Agility = GetRandom(15, 10);
            Fitness = GetRandom(1, 0.5);
            Energy = 1;

            model = new GeometryModel3D();

            translation = new TranslateTransform3D();
            scale = new ScaleTransform3D();
            var rotationT = new RotateTransform3D();
            rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0);
            rotationT.Rotation = rotation;

            scale.ScaleX = 1;
            scale.ScaleY = 1;
            scale.ScaleZ = 1;

            var tg = new Transform3DGroup();
            tg.Children.Add(scale);
            tg.Children.Add(rotationT);
            tg.Children.Add(translation);
            model.Transform = tg;

            Content = model;
        }
예제 #4
0
        protected virtual double GetAttraction(Creature c)
        {
            // Children stay close to their mother
            if (c == Mother && IsChild() && !Mother.IsDead())
                return 6;

            // Brothers and sisters are close when they are children
            if (Mother != null && Mother == c.Mother && IsChild())
                return 4;

            // They are really scared of predators
            if (GetType() == typeof(Creature) && c.GetType() == typeof(Predator))
                return -10;

            // Children play together
            if (State == CreatureState.Child && c.IsChild())
                return 2;

            // They are not interested in the dead
            if (c.State == CreatureState.Dead)
                return -1;

            // Males are really attracted to reproductive females
            if (Gender == Gender.Male && IsReproductive() && c.Gender == Gender.Female && c.IsReproductive())
                return 8;

            // Scared of other types
            if (GetType() != c.GetType())
            {
                return -5;
            }

            if (Gender == Gender.Female)
            {
                if (c.Gender == Gender.Male)
                    return 2;
                else
                    return 2;
            }
            else
            {
                if (c.Gender == Gender.Male)
                    return -4;
                else
                    if (Loves(c))
                        return 4 * c.Fitness;
            }
            return 0;
        }
예제 #5
0
 private bool IsInFamily(Creature creature)
 {
     if (Mother == null)
         return false;
     if (Mother == creature.Mother)
         return true;
     if (Mother == creature)
         return true;
     if (this == creature.Mother)
         return true;
     return false;
 }
예제 #6
0
 protected virtual void ProximityCheck(Creature c, double distance)
 {
     if (distance < PrivacyDist)
     {
         if (Gender == Gender.Female && IsReproductive()
                 && c.Gender == Gender.Male && c.IsReproductive()
                 && !IsInFamily(c)
                 && GetType() == c.GetType())
         {
             ReproduceAction(this, c);
             LastBabyTime = Age;
             IncubationDuration = 2;
         }
     }
 }
예제 #7
0
 public virtual bool Loves(Creature c)
 {
     return Gender == Gender.Male && c.Gender == Gender.Female && c.IsReproductive();
 }
예제 #8
0
 public virtual bool Attack(Creature c)
 {
     return false;
 }
예제 #9
0
 public override bool Attack(Creature c)
 {
     if (State == CreatureState.Adult && c.GetType() == typeof(Creature) && c.IsAlive())
         return true;
     return base.Attack(c);
 }
예제 #10
0
 protected override void ProximityCheck(Creature creature, double distance)
 {
     base.ProximityCheck(creature, distance);
     if (State == CreatureState.Adult && creature.GetType() == typeof(Creature) && distance < creature.PrivacyDist * 0.7)
         creature.Kill();
 }
예제 #11
0
        public Predator(Point3D position, Creature mother, Creature father)
            : base(position, mother, father)
        {

        }
예제 #12
0
        private void reproduceAction(Creature mother, Creature father)
        {
            Creature c;
            if (mother.GetType() == typeof(Creature))
                c = new Creature(mother.Position, mother, father);
            else
                c = new Predator(mother.Position, mother, father);
            c.ReproduceAction = reproduceAction;

            newCreatures.Add(c);
            view1.Children.Add(c);
        }
예제 #13
0
 private void AddCreature(double x, double y, Gender g)
 {
     var c = new Creature(new Point3D(x, y, 0), null, null);
     c.Gender = g;
     Add(c);
 }
예제 #14
0
 private void view1_MouseDown(object sender, MouseButtonEventArgs e)
 {
     var pt = view1.FindNearestPoint(e.GetPosition(view1));
     if (!pt.HasValue)
         return;
     Creature c;
     if (Keyboard.IsKeyDown(Key.LeftCtrl))
         c = new Predator(new Point3D(pt.Value.X, pt.Value.Y, 0), null, null);
     else
         c = new Creature(new Point3D(pt.Value.X, pt.Value.Y, 0), null, null);
     Add(c);
 }