Esempio n. 1
0
 public Predator(Predator source)
     : this(source._offset, source._ocean,
            source._timeToReproduce, source._timeToEat)
 {
 }
Esempio n. 2
0
        public override Cell Reproduce(Coordinate anOffset)
        {
            Predator temp = new Predator(anOffset, _ocean);

            return(temp);
        }
Esempio n. 3
0
        private static void InitInhabitance(Ocean ocean, Images image)
        {
            int count;

            switch (image)
            {
            case Images.Obstacle:
                count = ocean.NumObstecles;
                break;

            case Images.Predators:
                count = ocean.NumPredators;
                break;

            case Images.Prey:
                count = ocean.NumPrey;
                break;

            default:
                count = 0;
                break;
            }

            for (int i = 0; i < count; i++)
            {
                bool res = false;

                do
                {
                    Coordinate coord = new Coordinate()
                    {
                        X = random.Next(0, ocean.NumCols),
                        Y = random.Next(0, ocean.NumRows)
                    };

                    res = ocean.IsBoundedCoordinate(coord) && ocean.IsEmptyCoordinate(coord);

                    if (res)
                    {
                        Cell newCell = null;

                        switch (image)
                        {
                        case Images.Obstacle:
                            newCell = new Obstacle(coord, ocean);
                            break;

                        case Images.Predators:
                            newCell = new Predator(coord, ocean);
                            break;

                        case Images.Prey:
                            newCell = new Prey(coord, ocean);
                            break;

                        default:
                            count = 0;
                            break;
                        }

                        ocean.AddCell(newCell);
                    }
                } while (!res);
            }
        }