Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++创建一个森林 是新的C++,我正在尝试创建一个燃烧森林模拟器。我一直在尝试从forest类调用一个函数,但我不知道如何给它一个参数,如果有人能帮我的话,那就太好了。这是我目前拥有的代码 using namespace std; class ForestSetup { private: const char Tree = '^'; const char Fire = '*'; const char emptySpace = '.'; const char forestBorder = '#'; const int fireX = 10; const int fireY = 10; char forest[21][21]; public: void CreateForest() { // this function is to create the forest for (int i = 0; i < 21; i++) // this sets the value of the rows from 0 to 20 { for (int j = 0; j < 21; j++) // this sets the value of the columns from 0 to 20 { if (i == 0 || i == 20) { forest[i][j] = forestBorder; // this creates the north and south of the forest border } else if (j == 0 || j == 20) { forest[i][j] = forestBorder; // this creates the east and the west forest border } else { forest[i][j] = Tree; // this filles the rest of the arrays with trees } } } forest[fireX][fireY] = Fire; // this sets the fire in the middle of the grid } void ShowForest(char grid[21][21]) { for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { cout << grid[i][j]; } cout << endl; } } }; int main(void) { ForestSetup myForest; myForest.ShowForest(); system("Pause"); return 0; }_C++ - Fatal编程技术网

C++创建一个森林 是新的C++,我正在尝试创建一个燃烧森林模拟器。我一直在尝试从forest类调用一个函数,但我不知道如何给它一个参数,如果有人能帮我的话,那就太好了。这是我目前拥有的代码 using namespace std; class ForestSetup { private: const char Tree = '^'; const char Fire = '*'; const char emptySpace = '.'; const char forestBorder = '#'; const int fireX = 10; const int fireY = 10; char forest[21][21]; public: void CreateForest() { // this function is to create the forest for (int i = 0; i < 21; i++) // this sets the value of the rows from 0 to 20 { for (int j = 0; j < 21; j++) // this sets the value of the columns from 0 to 20 { if (i == 0 || i == 20) { forest[i][j] = forestBorder; // this creates the north and south of the forest border } else if (j == 0 || j == 20) { forest[i][j] = forestBorder; // this creates the east and the west forest border } else { forest[i][j] = Tree; // this filles the rest of the arrays with trees } } } forest[fireX][fireY] = Fire; // this sets the fire in the middle of the grid } void ShowForest(char grid[21][21]) { for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { cout << grid[i][j]; } cout << endl; } } }; int main(void) { ForestSetup myForest; myForest.ShowForest(); system("Pause"); return 0; }

C++创建一个森林 是新的C++,我正在尝试创建一个燃烧森林模拟器。我一直在尝试从forest类调用一个函数,但我不知道如何给它一个参数,如果有人能帮我的话,那就太好了。这是我目前拥有的代码 using namespace std; class ForestSetup { private: const char Tree = '^'; const char Fire = '*'; const char emptySpace = '.'; const char forestBorder = '#'; const int fireX = 10; const int fireY = 10; char forest[21][21]; public: void CreateForest() { // this function is to create the forest for (int i = 0; i < 21; i++) // this sets the value of the rows from 0 to 20 { for (int j = 0; j < 21; j++) // this sets the value of the columns from 0 to 20 { if (i == 0 || i == 20) { forest[i][j] = forestBorder; // this creates the north and south of the forest border } else if (j == 0 || j == 20) { forest[i][j] = forestBorder; // this creates the east and the west forest border } else { forest[i][j] = Tree; // this filles the rest of the arrays with trees } } } forest[fireX][fireY] = Fire; // this sets the fire in the middle of the grid } void ShowForest(char grid[21][21]) { for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { cout << grid[i][j]; } cout << endl; } } }; int main(void) { ForestSetup myForest; myForest.ShowForest(); system("Pause"); return 0; },c++,C++,假设你有一个setOnFire函数,它的x和y坐标是你想要点火的地方 public: setOnFire(int x, int y) { // Code to flag that part of the forest on fire } 在你的主要,你会称之为 myForest.setOnFire(5,5); 在ForestSetup类中,您只需要setOnFire5,5 这篇文章可能会有所帮助。只需使用林成员而不是要求网格。void ShowForestchar g

假设你有一个setOnFire函数,它的x和y坐标是你想要点火的地方

public:
  setOnFire(int x, int y)
  {
      // Code to flag that part of the forest on fire
  }
在你的主要,你会称之为

myForest.setOnFire(5,5);
在ForestSetup类中,您只需要setOnFire5,5


这篇文章可能会有所帮助。

只需使用林成员而不是要求网格。void ShowForestchar grid[21][21]可能应该是void ShowForest const,并使用林而不是网格。如果您是新成员,您可能希望获取一个网格。