Tell me, please, is it possible to replace Iterator somehow with Stream. If not, then you can somehow shorten the code:
private boolean moveMan(Direction direction){ int numberCollisionWithWalls=0; Iterator<Man> iterator = mans.iterator(); while (iterator.hasNext()) { Man man = iterator.next(); Position oneStep = direction.next(man.getPosition()); GameObject gameObject = new GameObject(oneStep.getX(), oneStep.getY()); if (walls.contains(gameObject)) { numberCollisionWithWalls++; continue; } if (badWalls.contains(gameObject)) { gameOver(); return false; } Position twoStep = direction.next(oneStep); if (mans.contains(gameObject)&& walls.contains(new GameObject(twoStep.getX(), twoStep.getY()))) { gameOver(); return false; } if (getTarget().equals(gameObject)) { iterator.remove(); continue; } man.setPosition(oneStep); } if(numberCollisionWithWalls!=mans.size()) { numbertStep++; } return true; }