Ejemplo n.º 1
0
        public Prey(Coordinate aCoord, Ocean ocean = null, int timeToReproduce = Constant.TIME_TO_REPRODUCE)
            : base(aCoord, ocean)
        {
            TimeToReproduce      = timeToReproduce;
            _initTimeToReproduce = _timeToReproduce;

            _image = Images.Prey;
        }
Ejemplo n.º 2
0
        public Predator(Coordinate coord, Ocean ocean = null,
                        int timeToReproduce           = Constant.TIME_TO_REPRODUCE,
                        int timeToEat = Constant.TIME_TO_EAT)
            : base(coord, ocean, timeToReproduce)
        {
            TimeToEat      = timeToEat;
            _initTimeToEat = _timeToEat;

            _image = Images.Predators;
        }
Ejemplo n.º 3
0
 public void Clean(Ocean ocean)
 {
     for (ushort i = 0; i < ocean.NumRows; i++)
     {
         for (ushort j = 0; j < ocean.NumCols; j++)
         {
             Console.SetCursorPosition(j, i);
             Console.Write(' ');
         }
     }
 }
Ejemplo n.º 4
0
        public static Ocean CreateOcean(int rows, int cols, int preys, int predators, int obstacle, int iteration)
        {
            random = new Random();
            Verification(ref rows, ref cols, ref preys, ref predators, ref obstacle, ref iteration);

            Ocean ocean = new Ocean(rows, cols, preys, predators, obstacle, iteration);

            InitInhabitance(ocean, Images.Obstacle);
            InitInhabitance(ocean, Images.Predators);
            InitInhabitance(ocean, Images.Prey);

            return(ocean);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            OceanUI oceanUI = new OceanUI();
            Ocean   ocean   = OceanTest.CreateOcean(20, 20, 20, 20, 10, 100);

            while (ocean.Run())
            {
                oceanUI.DisplayCells(ocean);



                Thread.Sleep(2000);
            }

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public static Ocean CreateOcean(int rows, int cols)
        {
            random = new Random();
            Verification(ref rows, ref cols);

            int preys     = random.Next(1, Constant.MaxPreys);
            int predators = random.Next(1, Constant.MaxPredators);
            int obstacle  = random.Next(0, Constant.MaxObstacle);
            int iteration = random.Next(Constant.MinIteration, Constant.MaxIteration);

            Ocean ocean = new Ocean(rows, cols, preys, predators, obstacle, iteration);

            InitInhabitance(ocean, Images.Obstacle);
            InitInhabitance(ocean, Images.Predators);
            InitInhabitance(ocean, Images.Prey);

            return(ocean);
        }
Ejemplo n.º 7
0
        public static Ocean CreateOcean()     //рандомное наполнение океана
        {
            random = new Random();

            int rows      = random.Next(1, Constant.MaxRows);
            int cols      = random.Next(1, Constant.MaxCols);
            int preys     = random.Next(1, Constant.MaxPreys);
            int predators = random.Next(1, Constant.MaxPredators);
            int obstacle  = random.Next(0, Constant.MaxObstacle);
            int iteration = random.Next(Constant.MinIteration, Constant.MaxIteration);

            Ocean ocean = new Ocean(rows, cols, preys, predators, obstacle, iteration);

            InitInhabitance(ocean, Images.Obstacle);
            InitInhabitance(ocean, Images.Predators);
            InitInhabitance(ocean, Images.Prey);

            return(ocean);
        }
Ejemplo n.º 8
0
        public void DisplayCells(Ocean ocean)
        {
            Clean(ocean);
            Console.CursorVisible = false;

            for (ushort i = 0; i < ocean.NumRows; i++)
            {
                for (ushort j = 0; j < ocean.NumCols; j++)
                {
                    if (ocean[i, j] != null)
                    {
                        Console.SetCursorPosition(j, i);

                        Console.ForegroundColor = ConsoleColor.Green;

                        Console.Write(ocean[i, j]);
                    }
                }
            }

            Console.WriteLine();
            Console.ResetColor();
        }
Ejemplo n.º 9
0
 public Cell(Coordinate coord, Ocean ocean)
     : this(coord)
 {
     _ocean = ocean;
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
 public Obstacle(Coordinate coord, Ocean ocean = null)
     : base(coord, ocean)
 {
     _image = Images.Obstacle;
 }