Beispiel #1
0
 public static void simulateActions()
 {
     for (int i = 0; i < Scene.AllPlanets.Count(); i++)
     {
         for (int m = 0; m < Scene.AllPlanets[i].citizens.Count() - 1; m++)
         {
             if (Scene.AllPlanets[i].citizens[m] != null && Scene.AllPlanets[i].citizens[m + 1] != null)
             {
                 if (Distance(Scene.AllPlanets[i].citizens[m].Location, Scene.AllPlanets[i].citizens[m + 1].Location) <= inRangeOfAttackDistance)
                 {
                     if (RandomG.RandomNumbers(-100, 100) < 0)
                     {
                         Console.WriteLine("{0} attacked {1}", Scene.AllPlanets[i].citizens[m], Scene.AllPlanets[i].citizens[m + 1]);
                         Scene.AllPlanets[i].citizens[m].Attack(Scene.AllPlanets[i].citizens[m + 1]);
                     }
                     else
                     {
                         if (Scene.AllPlanets[i].citizens[m].GetType() == Scene.AllPlanets[i].citizens[m + 1].GetType())
                         {
                             Entity q = new Entity(RandomG.RandomName());
                             mPlayer.AddCitizen(Scene.AllPlanets[i], q);
                             Console.WriteLine("{0} and {1} have baby-{2}", Scene.AllPlanets[i].citizens[m], Scene.AllPlanets[i].citizens[m + 1], q.Name);
                         }
                         else
                         {
                             Console.WriteLine("{0} and {1} tried to have baby but are diferent types", Scene.AllPlanets[i].citizens[m], Scene.AllPlanets[i].citizens[m + 1]);
                         }
                     }
                     Thread.Sleep(5000);
                 }
             }
         }
     }
 }
Beispiel #2
0
        public override void DoAction(AEntity targetEntity)
        {
            double nextNum = RandomG.RandomNumbers(-100, 200);

            if (nextNum < -50)
            {
                this.Attack(targetEntity);
            }
            else if (nextNum >= -50 && nextNum < 50)
            {
                this.Sleeping();
            }
            else if (nextNum >= 50 && nextNum < 100)
            {
                this.SearchingForFood();
            }
            else if (nextNum >= 100 && nextNum < 150)
            {
                this.Move(new Point2D);
            }
            else
            {
                this.Analyze();
            }
        }
Beispiel #3
0
        // Attack an entity and calculate the result of the battle.
        public virtual void Attack(IEntity targetEntity)
        {
            RandomG rand   = new RandomG();
            double  damage = rand.RandomNumbers(10, 20);

            if ((targetEntity.Energy - damage) >= 0)
            {
                targetEntity.Energy -= damage;
                this.State           = State.Attacking;
            }
            else
            {
                killEntity(targetEntity)
            }
        }
Beispiel #4
0
 // Moving every entity to a new random location and then doing a random action.
 public static void Update()
 {
     while (true)
     {
         for (int i = 0; i < Scene.AllPlanets.Count(); i++)
         {
             for (int k = 0; k < Scene.AllPlanets[i].citizens.Count(); k++)
             {
                 if (Scene.AllPlanets[i].citizens[k] != null)
                 {
                     Point2D point = new Point2D(RandomG.RandomNumbers(-100, 100), RandomG.RandomNumbers(-100, 100));
                     Scene.AllPlanets[i].citizens[k].Move(point);
                     Console.WriteLine("Creature {0} is with coordinates {1}", Scene.AllPlanets[i].citizens[k], point);
                 }
             }
         }
         simulateActions();
         Thread.Sleep(8000);
     }
 }
Beispiel #5
0
 // Sleeping increases animals energy by 100 to 120 points.
 public void Sleep()
 {
     this.State   = State.Sleeping;
     this.Energy += RandomG.RandomNumbers(100, 120);
 }
Beispiel #6
0
 // Searching for food decreases animals energy by 0 to 20 points.
 public void SearchingForFood()
 {
     this.State   = State.SearchingForFood;
     this.Energy -= RandomG.RandomNumbers(0, 20);
 }
Beispiel #7
0
 // Eating increases animals weight by 1 to 5 points.
 public void Eat()
 {
     this.State   = State.Eating;
     this.Weight += RandomG.RandomNumbers(1, 5);
 }
Beispiel #8
0
 public Point2D()
 {
     this.X = RandomG.RandomNumbers(-100, 100);
     this.Y = RandomG.RandomNumbers(-100, 100);
 }