package cross;
import game_timer.GameTimer;
import java.util.ArrayList;
import logger.Logger;
import map.Map;
import misc.carType;
import route.Route;
import vehicles.Vehicle;
import _main.Game;
/**
*
* A v�roshat�r kil�p�si pontjai; egy olyan keresztez�d�s,
* melyn�l csak bemen� utak tal�lhat�ak. Az aut�k �s a rend�r�k
* ide �rkezhetnek. Ha a bankrabl� egy ilyen helyet �rint, akkor v�ge
* a j�t�knak. A Map hozza l�tre.
*
*/
public class QuitPoint extends Cross {
private Map m;
private ArrayList<Route> inroutes = new ArrayList<Route>();
private ArrayList<Route> outroutes = new ArrayList<Route>();
private ArrayList<Vehicle> vehicleInCross = new ArrayList<Vehicle>();
private ArrayList<Vehicle> vehiclesAtCross = new ArrayList<Vehicle>();
Vehicle v1;
/**
*
* az id�l�ptet� f�ggv�ny; megh�vja a megfelel� f�ggv�nyeket adott id�k�z�nk�nt
*/
public void onTick() {
Logger.get().addOrdinaryMessage("[QuitPoint.OnTick]: called!");
Logger.get().addOrdinaryMessage("[QuitPoint.Constructor]: registering to observer...");
Logger.get().addMethodCall("\t", "GameTimer", "registObserver");
GameTimer.getInstance().registObserver(this);
Logger.get().addMethodReturn("\t", "GameTimer", "registObserver");
}
/**
* friss�ti a vehiclesAtCross-t a kil�p�si pont bemen� �tjain tal�lhat� aut�kr�l
*
*/
public void updateVehiclesAtCross() {
Logger.get().addMethodCall("", "QuitPoint", "updateVehiclesAtCross");
for(Route r : inroutes){//get dummy cars from the routes
vehiclesAtCross.add(r.test_getACar());
}
stepIntoCross();
if (v1.getCarType()==carType.Robbery)
{
Game.getInstance().finishGame();
}
else
{
Logger.get().addOrdinaryMessage("[Entry Pointok lekerese]");
ArrayList<EntryPoint> entrypoints = Game.getInstance().getMap().getEntryPoints();
Logger.get().addOrdinaryMessage("[EntryPoint kivalasztasa]");
EntryPoint e = entrypoints.get(0);
Logger.get().addOrdinaryMessage("[v1 hozzaadadasa az EntryPointhoz]");
e.addVehicleToCross(v1);
e.vehicleOut();
Logger.get().addMethodReturn("", "QuitPoint", "updateVehiclesAtCross");
}
}
/**
* egy �tr�l bel�ptet egy j�rm�vet a kil�p�si pontra
*/
public void stepIntoCross() {
Logger.get().addMethodCall("", "QuitPoint", "stepIntoCross");
Logger.get().addOrdinaryMessage("[QuitPoint.stepIntoCross]: A [vehiclesAtCross] tombbol a kovetkezo auto kivalasztasa, majd a bemeno uttol valo elkerese!");
v1 = inroutes.get(0).getAndRemoveLastCar(); // v1 aut� elk�r�se
vehicleInCross.add(v1);//get the car and add it to the cross
Logger.get().addMethodReturn("", "QuitPoint", "stepIntoCross");
}
/**
*
* a keresztez�d�sben l�v� aut�t kil�pteti
*/
public void vehicleOut() {
Logger.get().addMethodCall("", "QuitPoint", "vehicleOut");
Route selectedOutRoute = vehicleInCross.get(0).selectRoute(outroutes);
selectedOutRoute.addVehicle(vehicleInCross.get(0));
Logger.get().addMethodReturn("", "QuitPoint", "vehicleOut");
}
/**
* az inroutes t�mbh�z hozz�ad egy bemen� utat
* @param r bemen� �t hozz�ad�sa
*/
public void addInRoutes(Route r) {//TODO: addInRoute es nem Routes
Logger.get().addOrdinaryMessage("[QuitPoint.addInRoutes]: Called! and [inRoute added!]");
inroutes.add(r);
}
/**
* az outroutes t�mbh�z hozz�ad egy bemen� utat
* @param r kimen� �t hozz�ad�sa
*/
public void addOutRoutes(Route r) {//TODO: addOutRoute es nem Routes
Logger.get().addOrdinaryMessage("[QuitPoint.addOutRoutes]: Called! and [outRoute added!]");
outroutes.add(r);
}
/**
* Aut�t tesz a keresztez�d�sbe
* @param v a keresztez�d�sbe teend� aut�
*/
public void addVehicleToCross(Vehicle v) {
Logger.get().addMethodCall("", "QuitPoint", "addVehicleToCross");
Logger.get().addOrdinaryMessage("visszaadja v1 autot");
vehicleInCross.add(v);
}
}