//itt meg meg kellene vizsgalni, hogy az ut vegere ert-e
//eloszor is nezzuk meg, hogy elert-e valamelyik auto a keresztezodesig
if(vehicles.size() > 0){
for(int i = 0; i < vehicles.size(); i++){
Vehicle car = vehicles.get(i);
int currSpd = car.getCurrentSpeed();
int currPos = car.getPosition();
if((currPos + currSpd) > (length - vehiclesAtCross.size())){
if(car.getCarType() == carType.Robbery && i == 0){
//ha az ut vegere ert es mar belepne a keresztezodesbe, akkor berakjuk es eltavolitjuk az utrol
car.getCross().addVehicleToCross(car);
vehicles.remove(car);
} else if(car.getCarType() == carType.Robbery && vehiclesAtCross.size() > 0){
//mar belepett volna a keresztezodesbe, de voltak elotte
Game.getInstance().finishGame();
} else {
//hogyha a vegere ert[a hosszbol levonjuk a keresztezodesnel varakozokat]
//beallitjuk a keresztezodes elotti sorba,
//majd a mozgo autok tombjebol kiszedjuk
//es berakjuk a keresztezodes elott varakozoekba(0 sebeseggel)
car.setPosition(length - vehiclesAtCross.size());
car.setCurrentSpeed(0);
vehiclesAtCross.add(car);
vehicles.remove(car);
}
}
//TODO: [PROG] hogyha forditva halad a rablo az uton, akkor is vizsgalni, hogy 0-hoz ert-e
//ha megfordult es mondjuk, a kovetkezo lepesnel mar 0-nal jar
if(car.getCarType() == carType.Robbery){
if(currPos + currSpd < 0){
startCross.addVehicleToCross(car);
vehicles.remove(car);
}
}
}
}
//itt fogjuk lassitani, gyorsitani az autokat, akik meg "mozognak"
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();
//lekerdezzuk a sebessegeket, amivel mennek
int leader_currentSpd = leader_car.getCurrentSpeed();
int follower_currentSpd = follower_car.getCurrentSpeed();
//hogyha ezzel a sebesseggel, a kovetkezo lepesnel utolerne, akkor lassitsuk le
if(follower_car.getCarType() != carType.Robbery){
//ha a followerCar nem robbery, akkor lassitsuk le
if(follower_pos + follower_currentSpd >= leader_pos + leader_currentSpd){
follower_car.setCurrentSpeed(leader_currentSpd);
} else {
//ha nem erte utol, akkor probaljon meg a rendes sebessegevel haldani
int original_speed = follower_car.getSpeed();
if(follower_pos + original_speed < leader_pos + leader_currentSpd){
follower_car.setCurrentSpeed(original_speed);
}
}
}
}
}
//autok leptetese, itt mar csak azok maradnak es olyan sebeseggel, ami jo. :)
if(vehicles.size() > 0){
//vegigmegyunk az autokon es beallitjuk nekik a kovetkezo poziciojukat
for(int i = 0; i < vehicles.size(); i++){
Vehicle car = vehicles.get(i);
//uj poz = aktualis poz + lepesi tavolsag
int new_pos = car.getPosition() + car.getCurrentSpeed();
car.setPosition(new_pos);
}
}
}