Exemple #1
0
        public void Initialize(int prey, int predators, int obstacles)
        {
            int[] entities = RandomGenerator.GenerateIntUniqueSeries(0, _rows * _columns, prey + predators + obstacles);


            int startIndex = entities.Length - 1;
            int stopIndex  = predators + obstacles;
            int col;
            int row;

            for (int i = startIndex; i >= stopIndex; i--)
            {
                IndexToCoordinate(entities[i], out col, out row);
                _cells[col, row] =
                    new Fish(
                        ocean: this,
                        pos: new Coordinate()
                {
                    X = col, Y = row
                },
                        curTimeToReproduce: RandomGenerator.GetIntRandom(1, DefaulConst.FISH_TIME_TO_REPRODUCE + 1),
                        timeToReproduce: DefaulConst.FISH_TIME_TO_REPRODUCE);
            }

            startIndex = stopIndex - 1;
            stopIndex  = obstacles + predators / 2;   // хищники

            for (int i = startIndex; i >= stopIndex; i--)
            {
                IndexToCoordinate(entities[i], out col, out row);
                _cells[col, row] =
                    new Shark(
                        ocean: this,
                        pos: new Coordinate()
                {
                    X = col, Y = row
                },
                        curTimeToReproduce: RandomGenerator.GetIntRandom(1, DefaulConst.SHARK_TIME_TO_REPRODUCE + 1),
                        curTimeToFeed: RandomGenerator.GetIntRandom(1, DefaulConst.SHARK_TIME_TO_FEED + 1),
                        timeToReproduce: DefaulConst.SHARK_TIME_TO_REPRODUCE,
                        timeToFeed: DefaulConst.SHARK_TIME_TO_FEED);
            }

            startIndex = stopIndex - 1;
            stopIndex  = obstacles;

            for (int i = startIndex; i >= stopIndex; i--)
            {
                IndexToCoordinate(entities[i], out col, out row);
                _cells[col, row] =
                    new Tuna(
                        ocean: this,
                        pos: new Coordinate()
                {
                    X = col, Y = row
                },
                        curTimeToReproduce: RandomGenerator.GetIntRandom(1, DefaulConst.TUNA_TIME_TO_REPRODUCE + 1),
                        curTimeToFeed: RandomGenerator.GetIntRandom(1, DefaulConst.TUNA_TIME_TO_FEED + 1),
                        timeToReproduce: DefaulConst.TUNA_TIME_TO_REPRODUCE,
                        timeToFeed: DefaulConst.TUNA_TIME_TO_FEED);
            }



            startIndex = stopIndex - 1;
            stopIndex  = 0;

            for (int i = startIndex; i >= stopIndex; i--)
            {
                IndexToCoordinate(entities[i], out col, out row);
                _cells[col, row] = new Obstacle(new Coordinate()
                {
                    X = col, Y = row
                });
            }
        }
Exemple #2
0
 public Tuna(Tuna sh)
     : base(sh)
 {
     _kind = ESpecies.Tuna;
 }