mainLoop:
while( true )
{ Object[] thePlanes = aircraft.toArray();
for( int a1 = 0; a1 < (thePlanes.length)-1; a1++ )
for( int a2 = a1+1; a2 < thePlanes.length; a2++ )
{ int howNear = close( (Aircraft)thePlanes[a1], (Aircraft)thePlanes[a2] );
if( howNear == NEAR_MISS )
{ ((Aircraft)thePlanes[a1]).radio( "Help! Another aircraft is close!" );
((Aircraft)thePlanes[a2]).radio( "What is that?" );
}
else if( howNear == CRASH )
{ ((Aircraft)thePlanes[a1]).radio( "OH NO !!" );
((Aircraft)thePlanes[a2]).radio( "Oh . . ." );
synchronized( aircraft )
{ aircraft.remove( thePlanes[a1] );
aircraft.remove( thePlanes[a2] );
}
continue mainLoop;
}
}
try
{ sleep( 1000 );
}
catch( Exception e )
{}
}