Plugging it all together

It’s not often you get to write code as ugly as this (unless you’re me that is, in which case it’s very often):


for(GeneBlock block : this.geneBlocksInPlay){
if(block != currentBlock){

List neighbouringBlocks = new ArrayList();

int[][] tiles = block.getTiles();
for(int t = 0; t < tiles.length; t ++){

int locX = block.getX() + tiles[t][0];
int locY = block.getY() + tiles[t][1];

for(int x = -1; x <= 1; x ++){
for(int y = -1; y <= 1; y ++){
if(!(x == 0 && y == 0)){
int realX = Math.min(this.geneBlocksWidth,Math.max(0,locX + x));
int realY = Math.min(this.geneBlocksHeight,Math.max(0,locY + y));

GeneBlock neighbourBlock = this.geneBlocks[realX][realY];

if(neighbourBlock != block){
neighbouringBlocks.add(neighbourBlock);
}
}
}
}
}

block.registerNeighbours(neighbouringBlocks);
}
}

Comments

willh
26. Aug 2012 · 16:56 UTC
Not sure why my pictures are all squashed.