Class 用Processing'编写的程序;我什么都不做,但没有错误

Class 用Processing'编写的程序;我什么都不做,但没有错误,class,processing,cellular-automata,Class,Processing,Cellular Automata,对于我的第一个使用类的项目,我决定写“生命的游戏”。 我创建了一个名为cell的类,它的工作是检查附近的单元格是否处于活动状态(变量状态为true),然后决定下一帧单元格是否处于活动状态。 这是我的密码 public cell Cell[][] = new cell[10][10]; public boolean state[][] = new boolean[10][10]; void setup(){ size(200,200); for(int x = 0;x > 10;x++){

对于我的第一个使用类的项目,我决定写“生命的游戏”。 我创建了一个名为cell的类,它的工作是检查附近的单元格是否处于活动状态(变量状态为true),然后决定下一帧单元格是否处于活动状态。 这是我的密码

public cell Cell[][] = new cell[10][10];
public boolean state[][] = new boolean[10][10];
void setup(){
size(200,200);
for(int x = 0;x > 10;x++){
  for(int y = 0; y > 10;y++){
    state[x][y] = false;
  }
}
state[1][1] = true;
state[1][2] = true;
state[2][1] = true;
state[2][2] = true;
for(int x = 0;x > 10;x++){
    for(int y = 0; y > 10;y++){
      Cell[x][y] = new cell(x,y,state[x][y]);
    }
  }
}
void draw(){
for(int x = 0;x > 10;x++){
    for(int y = 0; y > 10;y++){
      Cell[x][y].update();
    }
  }
}
class cell{
  boolean state; int ngbs,posx,posy;
  cell(int gridX,int gridY,boolean State){
    posx = gridX;
    posy = gridY;
    state = State;
  }
  void update(){
    if(Cell[posx-1][posy].state == true){ngbs++;}
    if(Cell[posx+1][posy].state == true){ngbs++;}
    if(Cell[posx][posy-1].state == true){ngbs++;}
    if(Cell[posx][posy+1].state == true){ngbs++;}
    if(Cell[posx+1][posy-1].state == true){ngbs++;}
    if(Cell[posx+1][posy+1].state == true){ngbs++;}
    if(Cell[posx-1][posy+1].state == true){ngbs++;}
    if(Cell[posx-1][posy-1].state == true){ngbs++;}
    if(ngbs == 3){state = true;}
    if((ngbs != 2) && (ngbs != 3)){state = false;fill(0);}
    if(state){fill(255);}else{fill(0);}
    rect(posx*10,posy*10,10,10);
  }
}

查看您的for循环:

for(int x = 0;x > 10;x++){
    for(int y = 0; y > 10;y++){
这两个循环都不会进入

作为旁注,您确实应该使用适当的命名约定:变量以小写字母开头,类以大写字母开头


此外,生命的游戏在“世代”中起作用。你不能一次更新一个单元格,否则它会丢弃该单元格的所有邻居。

关于循环:哦,天哪,我太傻了!关于世代:所以我应该使用两个数组,一个用于检查上一代的邻居。一代人和一代人来设定下一代的状态?附言:我喜欢你个人资料照片的讽刺意味XD@Sipi是的,您需要两个阵列:一个用于当前一代,另一个用于下一代。试试看我在说什么。