Exemple #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);
                 }
             }
         }
     }
 }
Exemple #2
0
        // Create a creatute on a planet.
        public static void CreateEntity(EntityType creature, Planet planet)
        {
            switch (creature)
            {
            case EntityType.animal:
                Animal a = new Animal(RandomG.RandomName());
                planet.AddCitizen(a);
                break;

            case EntityType.entity:
                Entity e = new Entity(RandomG.RandomName());
                planet.AddCitizen(e);
                break;

            case EntityType.god:
                God g = new God(RandomG.RandomName());
                planet.AddCitizen(g);
                break;

            case EntityType.human:
                Human h = new Human(RandomG.RandomName());
                planet.AddCitizen(h);
                break;

            case EntityType.unknown:
                Entity u = new Entity(RandomG.RandomName());
                planet.AddCitizen(u);
                break;

            default:
                throw new ArgumentOutOfRangeException("there is no such type of creature");
                break;
            }
        }
Exemple #3
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();
            }
        }
Exemple #4
0
 public AEntity()
 {
     this.Name     = RandomG.RandomName();
     this.Energy   = 10;
     this.Power    = 10;
     this.Size     = 10;
     this.Weight   = 10;
     this.Location = new Point2D();
     this.State    = State.Unknown;
 }
Exemple #5
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)
            }
        }
Exemple #6
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);
     }
 }
Exemple #7
0
 // Sleeping increases animals energy by 100 to 120 points.
 public void Sleep()
 {
     this.State   = State.Sleeping;
     this.Energy += RandomG.RandomNumbers(100, 120);
 }
Exemple #8
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);
 }
Exemple #9
0
 // Eating increases animals weight by 1 to 5 points.
 public void Eat()
 {
     this.State   = State.Eating;
     this.Weight += RandomG.RandomNumbers(1, 5);
 }
Exemple #10
0
 public Point2D()
 {
     this.X = RandomG.RandomNumbers(-100, 100);
     this.Y = RandomG.RandomNumbers(-100, 100);
 }