示例#1
0
文件: UI.cs 项目: mihzas/Ocean
 public static void DisplayCells(Cell[,] cells)
 {
     for (int i = 0; i < cells.GetLength(0); ++i)
     {
         for (int j = 0; j < cells.GetLength(1); ++j)
         {
             Console.Write("{0}", cells[i, j]);
         }
         Console.WriteLine();
     }
     DisplayBorder(cells.GetLength(1));
 }
示例#2
0
文件: Ocean.cs 项目: mihzas/Ocean
        private Cell Reproduce(Cell cell)
        {
            if (cell is Predator)
                    {
                        _numPredators++;
                        return new Predator(this);
                    }

                    else if (cell is Prey)
                    {
                        _numPreys++;
                        return new Prey(this);
                    }

                    return null;
        }
示例#3
0
文件: Ocean.cs 项目: mihzas/Ocean
 private void AddEmptyCell(Ocean ocean)
 {
     _cell = new Cell[_numRows, _numCols];
     for (int i = 0; i < _numRows; ++i)
     {
         for (int j = 0; j < _numCols; ++j)
         {
             _cell[i, j] = new Cell(this);
         }
     }
 }
示例#4
0
文件: Ocean.cs 项目: mihzas/Ocean
        private void Move(Cell cell, Coordinate from, Coordinate to, bool reproduce)
        {
            if (reproduce)
                    {
                        Cell tempCell = Reproduce(cell);

                        if(tempCell != null)
                        {
                            _cell[to.GetY(), to.GetX()] = _cell[from.GetY(), from.GetX()];
                            _cell[from.GetY(), from.GetX()] = tempCell;
                        }
                    }

                    else
                    {
                        Cell tempCell = _cell[to.GetY(), to.GetX()];
                        _cell[to.GetY(), to.GetX()] = _cell[from.GetY(), from.GetX()];
                        _cell[from.GetY(), from.GetX()] = tempCell;
                    }
        }
示例#5
0
文件: Ocean.cs 项目: mihzas/Ocean
        public bool Moveable(Cell cell, MoveType type, bool isReproduce, Coordinate coord)
        {
            Coordinate tempCoord = null;
                    Cell tempCell = null;

                    switch (type)
                    {
                        case MoveType.Up: tempCoord = Up(coord); break;
                        case MoveType.Right: tempCoord = Right(coord); break;
                        case MoveType.Down: tempCoord = Down(coord); break;
                        case MoveType.Left: tempCoord = Left(coord); break;
                    }

                    _noExit |= (int)type;

                    tempCell = _cell[tempCoord.GetY(), tempCoord.GetX()];

                    if (!(tempCell is Predator) && !(tempCell is Prey) && !(tempCell is Obstacle))
                    {
                        Move(cell, coord, tempCoord, isReproduce);
                        return true;
                    }

                    else if (_noExit == NO_EXIT)
                    {
                        //Move(cell, coord, coord, isReproduce);
                        _noExit = 0;
                        return true;
                    }

                    return false;
        }