예제 #1
0
파일: Grid.cs 프로젝트: calberto66/.NET
        //create a grid of cells
        public void generateCells(int seed)
        {
            squares = new Rectangle[gridRows, gridColumns]; //create a grid of rectangles
            Random r = new Random(seed);
            int move;
            for (int i = 0; i < gridRows; i++)
            {
                for (int j = 0; j < gridColumns; j++)
                {
                    //provides a random number between 0 and 7
                    move = r.Next(numStates);
                    //creates a new cell with the state number
                    cells[i, j] = new Cell(move, palette[move]);
                    cells[i, j].setStates();
                }
            }

        }
예제 #2
0
파일: Grid.cs 프로젝트: calberto66/.NET
        //calculate the orthogonal rule for the next generation
        public void orthogonal()
        {
            //create a blank grid of cells
            Cell[,] nextCells = new Cell[gridRows, gridColumns];

            //loop through each cell
            for (int i = 0; i < gridRows; i++)
            {
                for (int j = 0; j < gridColumns; j++)
                {
                    //method passes in the orthogonal neighbours 
                    //to the current cell and returns a new state
                    State state = calculateCell(cells[i, j],
                                                cells[i, getLeft(j)],
                                                cells[i, getRight(j)],
                                                cells[getTop(i), j],
                                                cells[getBottom(i), j]);
                    //create a new cell with the state and color
                    nextCells[i, j] = new Cell(state, this.palette[(int)state]);
                    nextCells[i, j].setStates();
                }
            }
            cells = nextCells; //update the cells to the new generation                         
        }
예제 #3
0
파일: Grid.cs 프로젝트: calberto66/.NET
 //calculates the state of the cell of the next generation
 private State calculateCell(Cell current, Cell one, Cell two, Cell three, Cell four)
 {
     State s = new State(); //create a blank state
     //if any of the cell's four neighbours
     //has the next state of the current cell
     if (current.getNext == one.getState || current.getNext == two.getState ||
         current.getNext == three.getState || current.getNext == four.getState)
     {
         s = current.getNext;
     }
     else
     {
         s = current.getState;
     }
     return s;
 }