Example #1
0
        public Ground(int row, int col)
        {
            Row = row;
            Col = col;
            AmountHerbivorous = 1500;
            AmountPredator    = 1500;
            AmountOmnivorous  = 1500;
            AmountHuman       = 750;
            Field             = new Square[Row, Col];
            AmountGrass       = 1251;
            AmountHouses      = 250;

            Predators = new List <Mob <IPredatorFood> >();

            Herbivorouses = new List <Mob <IHerbivorousFood> >();

            Omnivorouses = new List <Mob <IOmnivorousFood> >();

            Humans = new List <Human>();

            AllGrass = new List <Grass>();

            Houses = new List <House>();

            for (var x = 0; x < Col; x++)
            {
                for (var y = 0; y < Row; y++)
                {
                    Field[x, y] = new Square();
                }
            }

            for (var i = 0; i < AmountHerbivorous; i++)
            {
                int randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                Mob <IHerbivorousFood> cr;
                if (i < AmountHerbivorous / 3)
                {
                    cr = new Deer(this, randX, randY);
                }
                else if (i < (AmountHerbivorous / 3) * 2)
                {
                    cr = new Sheep(this, randX, randY);
                }
                else
                {
                    cr = new Rabbit(this, randX, randY);
                }
                Herbivorouses.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }

            for (var i = 0; i < AmountPredator; i++)
            {
                int randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                Mob <IPredatorFood> cr;
                if (i < AmountHerbivorous / 3)
                {
                    cr = new Cat(this, randX, randY);
                }
                else if (i < (AmountHerbivorous / 3) * 2)
                {
                    cr = new Wolverine(this, randX, randY);
                }
                else
                {
                    cr = new Wolf(this, randX, randY);
                }
                Predators.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }

            for (var i = 0; i < AmountOmnivorous; i++)
            {
                int randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                Mob <IOmnivorousFood> cr;
                if (i < AmountOmnivorous / 3)
                {
                    cr = new Bear(this, randX, randY);
                }
                else if (i < (AmountOmnivorous / 3) * 2)
                {
                    cr = new Dog(this, randX, randY);
                }
                else
                {
                    cr = new Hedgehog(this, randX, randY);
                }
                Omnivorouses.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }
            for (var i = 0; i < AmountHuman; i++)
            {
                int randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                var cr = new Human(this, randX, randY);
                Humans.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }

            for (var i = 0; i < AmountHouses; i++)
            {
                int randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                var cr = new House(this, randX, randY);
                Houses.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }

            for (var i = 0; i < AmountGrass; i++)
            {
                int   randX = Rnd.Next(1000), randY = Rnd.Next(1000);
                Grass cr;
                if (i < AmountGrass / 3)
                {
                    cr = new Oats(this, randX, randY);
                }
                else if (i < (AmountGrass / 3) * 2)
                {
                    cr = new Carrot(this, randX, randY);
                }
                else
                {
                    cr = new GreenGrass(this, randX, randY);
                }
                AllGrass.Add(cr);
                Field[randX, randY].Objects.Add(cr);
            }
        }
Example #2
0
        private void InitializeUnits()
        {
            AbstractUnit.GlobalMap = this;

            for (int i = 0; i < _numOfUnits;)
            {
                int newX = Rand.Next(Height);
                int newY = Rand.Next(Width);


                AbstractUnit newOne = new BearUnit(newX, newY);

                var type = Rand.Next(4);

                switch (type)
                {
                case 0: newOne = new BearUnit(newX, newY);
                    break;

                case 1: newOne = new Hedgehog(newX, newY);
                    break;

                case 2: newOne = new Pig(newX, newY);
                    break;

                case 3: newOne = new Human(newX, newY);
                    break;
                }

                Field[newX, newY].Entity.Add(newOne);

                Entity.Add(newOne);
                ChangedCell.Add(Field[newX, newY]);

                i++;
            }

            for (int i = 0; i < _numOfUnits;)
            {
                int newX = Rand.Next(Height);
                int newY = Rand.Next(Width);

                if (Field[newX, newY].Entity.FirstOrDefault() == null)
                {
                    AbstractUnit newOne = new Deer(newX, newY);

                    var type = Rand.Next(3);

                    switch (type)
                    {
                    case 0: newOne = new Deer(newX, newY);
                        break;

                    case 1: newOne = new Rabbit(newX, newY);
                        break;

                    case 2: newOne = new Rat(newX, newY);
                        break;
                    }

                    Field[newX, newY].Entity.Add(newOne);

                    Entity.Add(newOne);
                    ChangedCell.Add(Field[newX, newY]);

                    i++;
                }
            }

            for (int i = 0; i < _numOfUnits;)
            {
                int newX = Rand.Next(Height);
                int newY = Rand.Next(Width);

                if (Field[newX, newY].Entity.FirstOrDefault() == null)
                {
                    AbstractUnit newOne = new Fox(newX, newY);

                    var type = Rand.Next(3);

                    switch (type)
                    {
                    case 0: newOne = new Fox(newX, newY);
                        break;

                    case 1: newOne = new Wolf(newX, newY);
                        break;

                    case 2: newOne = new Wolverine(newX, newY);
                        break;
                    }

                    Field[newX, newY].Entity.Add(newOne);

                    Entity.Add(newOne);
                    ChangedCell.Add(Field[newX, newY]);

                    i++;
                }
            }
        }