示例#1
0
//--------------------------------------------------------------
//updateLife() was used when current cell has neighbors it will set the number of neighors in numItems
//--------------------------------------------------------------
void cells::updateLife(){
	int count;
	for(int i=0;i<pCircle.size();i++){
		count=0;
		for(int j=0;j<pCircle.size();j++){
			if(i!=j){
				if(checkneighbor(i,j)){
					count++;
				}
			}
		}
		pCircle[i]->neighbor=count;
	}
}
示例#2
0
//--------------------------------------------------------------
//updateLife() was used when current cell has neighbors it will set the number of neighors in numItems
//--------------------------------------------------------------
void testApp::updateLife(){
	int count;
	int tempx,tempy;
	int tr,tg,tb;
	for (int i=0; i<windowcol;i++){
		for(int j=0; j<windowrow;j++){
			count=0;

			//check if the neighbor 
			if(checkneighbor(i-2,j-2,i,j)) {
				count++;
			}
			if(checkneighbor(i-1,j-2,i,j)) {
				count++;
			}
			if(checkneighbor(i,j-2,i,j)) {
				count++;
			}
			if(checkneighbor(i+1,j-2,i,j)) {
				count++;
			}
			if(checkneighbor(i+2,j-2,i,j)) {
				count++;
			}
			if(checkneighbor(i-2,j-1,i,j)) {
				count++;
			}		
			if(checkneighbor(i+2,j-1,i,j)) {
				count++;
			}	
			if(checkneighbor(i-2,j,i,j)) {
				count++;
			}	
			if(checkneighbor(i+2,j,i,j)) {
				count++;
			}
			if(checkneighbor(i-2,j+1,i,j)) {
				count++;
			}	
			if(checkneighbor(i+2,j+1,i,j)) {
				count++;
			}
			if(checkneighbor(i-2,j+2,i,j)) {
				count++;
			}
			if(checkneighbor(i-1,j+2,i,j)) {
				count++;
			}
			if(checkneighbor(i,j+2,i,j)) {
				count++;
			}
			if(checkneighbor(i+1,j+2,i,j)) {
				count++;
			}
			if(checkneighbor(i+2,j+2,i,j)) {
				count++;
			}
			
			//check if the neighbor is alive
			if(checkneighbor(i-1,j-1,i,j)) count++;
			if(checkneighbor(i,j-1,i,j)) count++;
			if(checkneighbor(i+1,j-1,i,j)) count++;
			
			if(checkneighbor(i-1,j,i,j)) count++;
			if(checkneighbor(i+1,j,i,j)) count++;
			
			if(checkneighbor(i-1,j+1,i,j)) count++;
			if(checkneighbor(i,j+1,i,j)) count++;
			if(checkneighbor(i+1,j+1,i,j)) count++;
			
			int x=i;
			int y=j;
			if (count>0)
				Life[i][j].numItems=count;
		}
	}
}