public void Handle(HandleGrid handleGrid) { for (int x = 0; x < NUM_CELLS; x++) { for (int y = 0; y < NUM_CELLS; y++) { Entity entity1 = cells[x][y]; while (entity1 != null) { handleEntity(entity1, entity1.Next, handleGrid); if (x > 0 && y > 0) { handleEntity(entity1, cells[x - 1][y - 1], handleGrid); } if (x > 0) { handleEntity(entity1, cells[x - 1][y], handleGrid); } if (y > 0) { handleEntity(entity1, cells[x][y - 1], handleGrid); } if (x > 0 && y < NUM_CELLS - 1) { handleEntity(entity1, cells[x - 1][y + 1], handleGrid); } entity1 = entity1.Next; } } } }
private void handleEntity(Entity entity1, Entity entity2, HandleGrid handleGrid) { while (entity2 != null) { handleGrid(entity1, entity2); entity2 = entity2.Next; } }