예제 #1
0
파일: Map.cs 프로젝트: Sewil/ATeam-DDO
        public static Map Load(string chart)
        {
            var map = new Map();

            int index = 0;
            for (int y = 0; y < HEIGHT; y++) {
                for (int x = 0; x < WIDTH; x++) {
                    char c = chart[index++];
                    CellType cellType;
                    if (c == '.') {
                        cellType = CellType.Ground;
                    } else if (c == '#') {
                        cellType = CellType.Forest;
                    } else {
                        throw new ArgumentException($"Char '{c}' not valid. Map needs to be empty.");
                    }

                    Cell cell = new Cell(y, x, cellType);

                    map.Cells[y, x] = cell;
                }
            }

            return map;
        }
예제 #2
0
파일: Map.cs 프로젝트: Sewil/ATeam-DDO
 Cell[,] DoSimulationStep()
 {
     var newCells = new Cell[HEIGHT, WIDTH];
     for (int y = 0; y < HEIGHT; y++) {
         for (int x = 0; x < WIDTH; x++) {
             int neighbours = CountForestNeighbors(y, x);
             bool borderCell = y == 0 || y == HEIGHT - 1 || x == 0 || x == WIDTH - 1;
             if (borderCell || neighbours > 4) {
                 newCells[y, x] = new Cell(y, x, CellType.Forest);
             } else if (neighbours <= 4) {
                 newCells[y, x] = new Cell(y, x, CellType.Ground);
             }
         }
     }
     return newCells;
 }