private void init() { // Fill grid content for (int _x = 0; _x < gridSize_x; _x++) for (int _y = 0; _y < gridSize_y; _y++) grid[_x, _y] = new Tree(Tree.ASH, _x, _y); for (int _x = 1; _x < gridSize_x - 1; _x++) for (int _y = 1; _y < gridSize_y - 1; _y++) grid[_x, _y] = new Tree(Tree.NORMAL, _x, _y); // Choose a random tree to burn r = new Random(); var x = r.Next(1, gridSize_x); var y = r.Next(1, gridSize_y); burn(x, y); printImage(); }
private void burn(int x, int y) { var selectedTree = grid[x, y]; selectedTree.state = Tree.BURNING; var adjacentTrees = new Tree[] { grid[x + 1, y], grid[x - 1, y], grid[x, y + 1], grid[x, y - 1] }; foreach (var tree in adjacentTrees) if (tree.state == Tree.NORMAL) if (r.NextDouble() <= p) tree.state = Tree.BURNING; selectedTree.state = Tree.ASH; }