Exemple #1
0
        protected void AimlessMove()
        {
            var value = Ground.Rnd.Next(4);
            int x = 0, y = 0;

            switch (value)
            {
            case 0:
                x++;
                break;

            case 1:
                x--;
                break;

            case 2:
                y++;
                break;

            case 3:
                y--;
                break;
            }

            if (!Ground.CheckTheEnd(X, Y, x, y))
            {
                return;
            }
            X += x;
            Y += y;
            Ground.Field[X, Y].Objects.Add(this);
            Ground.Field[X - x, Y - y].Objects.Remove(this);
            Starve++;
            WantChild++;
        }
Exemple #2
0
        private void GoToNeighboringHouse()
        {
            int newX = GoToX(NeighboringHouse), newY = GoToY(NeighboringHouse);

            if (X == NeighboringHouse.X && Y == NeighboringHouse.Y)
            {
                var newHouse = new Point
                {
                    X = Ground.Rnd.Next(-RadiusForHouse, RadiusForHouse), Y = Ground.Rnd.Next(-RadiusForHouse, RadiusForHouse)
                };
                if (Ground.CheckTheEnd(X, Y, newHouse.X, newHouse.Y) &&
                    !Ground.Field[X + newHouse.X, Y + newHouse.Y].Objects.Any(x => x is House))
                {
                    MyHouse        = new House(Ground, X + newHouse.X, Y + newHouse.Y, this);
                    Couple.MyHouse = MyHouse;
                    Ground.Field[X + newHouse.X, Y + newHouse.Y].Objects.Add(MyHouse);
                    Ground.Houses.Add(MyHouse);
                }
            }
            else
            {
                Ground.Field[newX, newY].Objects.Add(this);
                Ground.Field[X, Y].Objects.Remove(this);
                X = newX;
                Y = newY;
                Starve++;
                WantChild++;
            }
        }
Exemple #3
0
        protected override void Search <TSimulationObject>(SearchTargetType type)
        {
            if (!Ground.CheckTheEnd(X, Y, Radius, Radius) || !Ground.CheckTheEnd(X, Y, -Radius, -Radius))
            {
                return;
            }
            for (var x = X - Radius; x < X + Radius; x++)
            {
                for (var y = Y - Radius; y < Y + Radius; y++)
                {
                    if (!Ground.Field[x, y].Objects.Any())
                    {
                        continue;
                    }
                    foreach (var i in Ground.Field[x, y].Objects)
                    {
                        switch (type)
                        {
                        case SearchTargetType.Couple:
                            if (i is TSimulationObject)
                            {
                                var aim = i as Human;
                                if (aim != null && GenderThis != aim.GenderThis)
                                {
                                    Couple     = aim;
                                    aim.Couple = this;
                                    return;
                                }
                            }

                            break;

                        case SearchTargetType.Food:
                            if (i is TSimulationObject && i != this)
                            {
                                AimFood = i as Creature;
                                return;
                            }

                            break;

                        case SearchTargetType.House:
                            if (i is TSimulationObject)
                            {
                                NeighboringHouse = i as House;
                                return;
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void Grow()
        {
            var newGrass = new Point();

            if (Ground.Rnd.Next(250) != 0)
            {
                return;
            }
            for (var i = 0; i < GrassEveryTick;)
            {
                newGrass.X = Ground.Rnd.Next(-Radius, Radius);
                newGrass.Y = Ground.Rnd.Next(-Radius, Radius);
                if (Ground.CheckTheEnd(X, Y, newGrass.X, newGrass.Y) &&
                    !Ground.Field[X + newGrass.X, Y + newGrass.Y].Objects.Any(x => x is Grass))
                {
                    int newX = X + newGrass.X, newY = Y + newGrass.Y;
                    CreateGrass(newX, newY);
                    i++;
                }
            }
        }