//itt csak azt kell vizsgalni, hogy a rablo utkozott-e masik autoval, mivel a tobbi auto
//keruli az utkozest -> csak a rablo utkozhet
if(vehicles.size() > 1){
for(int i = 0; i < vehicles.size()-1; i++){
Vehicle leader_car = vehicles.get(i);//az az auto ami elorebb halad
Vehicle follower_car = vehicles.get(i+1);//az az auto, ami mogotte halad
//lekerdezzuk a poziciokat
int leader_pos = leader_car.getPosition();
int follower_pos = follower_car.getPosition();
//amolyan debug esetre
if(leader_pos == follower_pos){
if(leader_car.getCarType() == carType.Robbery || follower_car.getCarType() == carType.Robbery){
Game.getInstance().finishGame();
}
}
//lekerdezzuk a sebessegeket, amivel mennek
int follower_currentSpd = follower_car.getCurrentSpeed();
int leader_currentSpd = leader_car.getCurrentSpeed();
//megvizsgaljuk, hogy a rablo utkozne-e az elotte haladoval[follower = robbery, leader=otherCar]
if(follower_car.getCarType() == carType.Robbery){
//ha a rablo olyan sebeseggel halad, hogy a kovetkezo pozicioja annyi lenne
//mint az elotte halado autoe vagy attol nagyobb, akkor bizony utkozott es vege a jateknak
if(follower_pos + follower_currentSpd >= leader_pos + leader_currentSpd)
Game.getInstance().finishGame();
}
//megvizsgaljuk, hogyha a rablo forditva halad, akkor a "mogotte levobe" belemenne-e[follower = otherCar, leader = robbery, direction = false(hatrafele megy)]
if(leader_car.getCarType() == carType.Robbery){
//ha visszafele halad, akkor a sebessege negativ(tehat pl -90)
if(leader_pos + leader_currentSpd <= follower_pos + follower_currentSpd){
Game.getInstance().finishGame();
break;
}
}
if(follower_car.getCarType() == carType.Police && leader_car.getCarType() == carType.Robbery){
if(follower_pos + follower_currentSpd >= leader_pos + leader_currentSpd && !((RobberyCar)leader_car).getImmune()){
Game.getInstance().finishGame();
}
}
}