Beispiel #1
0
 protected override bool CheckCellForEat(Cell cell)
 {
     for (int i = 0; i < habitat.Length; i++)
     {
         if (cell.Type == habitat[i])
         {
             if (cell.Type == 2)
             {
                 WaterCell waterCell = (WaterCell)cell;
                 if (waterCell.Depth <= MaxDepth)
                 {
                     return(true);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
        public static Cell[,] CreateCell(int n, int m)
        {
            Cell[,] cell = new Cell[n + 2, m + 2];
            int    typeOfCell, food, depth;
            Random rand = new Random();

            for (int i = 0; i < n + 2; i++)
            {
                for (int j = 0; j < m + 2; j++)
                {
                    if (i == 0 || j == 0 || i == n + 1 || j == m + 1)
                    {
                        cell[i, j] = new BorderCell(i, j);
                    }
                    else
                    {
                        typeOfCell = rand.Next(0, 3);
                        switch (typeOfCell)
                        {
                        case 0:
                            food       = rand.Next(0, 50);
                            cell[i, j] = new LandCell(i, j, food);
                            break;

                        case 1:
                            food       = rand.Next(0, 50);
                            cell[i, j] = new ForestCell(i, j, food);
                            break;

                        case 2:
                            food       = rand.Next(0, 50);
                            depth      = rand.Next(1, 100);
                            cell[i, j] = new WaterCell(i, j, food, depth);
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    if (cell[i, j].Type != cell[i + 1, j].Type && cell[i, j].Type != cell[i, j + 1].Type && cell[i, j].Type != cell[i - 1, j].Type && cell[i, j].Type != cell[i, j - 1].Type)
                    {
                        typeOfCell = cell[i, j].Type;
                        if (cell[i + 1, j].Type != 3)
                        {
                            typeOfCell = cell[i + 1, j].Type;
                        }
                        else if (cell[i - 1, j].Type != 3)
                        {
                            typeOfCell = cell[i - 1, j].Type;
                        }

                        switch (typeOfCell)
                        {
                        case 0:
                            food       = rand.Next(0, 50);
                            cell[i, j] = new LandCell(i, j, food);
                            break;

                        case 1:
                            food       = rand.Next(0, 50);
                            cell[i, j] = new ForestCell(i, j, food);
                            break;

                        case 2:
                            food       = rand.Next(0, 50);
                            depth      = rand.Next(1, 100);
                            cell[i, j] = new WaterCell(i, j, food, depth);
                            break;
                        }
                    }
                }
            }
            return(cell);
        }