Package exercise3.exercise3_10.vehicles

Examples of exercise3.exercise3_10.vehicles.Vehicle


    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].changeSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedListImpl<Vehicle> startNode = new LinkedListImpl<Vehicle>(vehicles[0]);
   
    LinkedListImpl<Vehicle> node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(vehicles[i]);
      node = node.next;
    }
   
    LinkedListImpl<Vehicle> cloned = startNode.clone();
    ((Vehicle)cloned.next.value).setOwner("CHANGE");
    cloned.next.next.next = new LinkedListImpl<Vehicle>(new Vehicle("CHANGE"));
   
    System.out.println(startNode.toString());
    System.out.println(cloned.toString());
  }
View Full Code Here


    final String OWNER = "Kubota";
    Vehicle[] vehicles = new Vehicle[VEHICLE_NUM];
   
    
    for(int i = 0; i < vehicles.length; i++) {
      vehicles[i] = new Vehicle();
      vehicles[i].setOwner(OWNER);
      vehicles[i].changeSpeed(Math.random() * i);
      vehicles[i].setDirection(Math.random() * i);
    }
   
    LinkedList startNode = new LinkedList(vehicles[0]);
   
    LinkedList node = startNode;
    for(int i = 1; i < vehicles.length; i++) {
      node.setNext(new LinkedList(vehicles[i]));
      node = node.next;
    }
   
    LinkedList cloned = startNode.clone();
    ((Vehicle)cloned.next.value).setOwner("CHANGE");
    cloned.next.next.next = new LinkedList(new Vehicle("CHANGE"));
   
    System.out.println(startNode.toString());
    System.out.println(cloned.toString());
  }
View Full Code Here

   * egy �tr�l bel�ptet egy j�rm�t a keresztez�d�sbe (a megadott szab�lyok alapj�n,
   * mely a keresztez�d�s t�pus�t�l f�gg
   */
  public void stepIntoCross(Route r) {
    if(r != null){
       Vehicle car = r.getAndRemoveLastCar();
      if(vehicleInCross == null){
        vehicleInCross = car;
      } else {
        if(vehicleInCross.getCarType() == carType.Robbery){
          //ha nem ures a cross(a bankrablo van benne)
View Full Code Here

    String carId = params.get(0);
    String crossId = params.get(1);
   
   
   
    Vehicle car = ObjectStore.getInstance().getVehicle(carId);
    Cross cross = ObjectStore.getInstance().getCross(crossId);
   
    //eltavolitjuk az utrol
    car.getRoute().removeCarFromRoute(car);
   
    //hozzaadjuk a crosshoz
    cross.addVehicleToCross(car);
   
    //itt mar a tobbit intezi az addVehivleToCross...
View Full Code Here

    Cross c = ObjectStore.getInstance().getCross(crossId);
    if(c == null){
      return MessageBox.get().getMessage(Messages.NotFound);
    }
   
    Vehicle v = c.getVehicleFromCross();
    if(v == null){
      return MessageBox.get().getMessage(Messages.EmptyCross);
    }
   
    String vId = "";
    vId +="Vehicle id: " + ObjectStore.getInstance().getVehicleId(v);
   
    String specificId = "";
    //auto tipustol fuggoen az id
    if(v.getCarType() == carType.Ordinary){
      specificId += " OrdinaryCar: " + ObjectStore.getInstance().getOrdinaryId((OrdinaryCar) v);
    } else if(v.getCarType() == carType.Police){
      specificId += " OrdinaryCar: " + ObjectStore.getInstance().getOrdinaryId((OrdinaryCar) v);
    } else if(v.getCarType() == carType.Robbery){
      specificId += " RobberyCar: nincs Id-je, getRobberyCarDetails()-el elerhetoek az informaciok!";
    }
   
    return vId + specificId + "\r\n";
  }
View Full Code Here

    //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);
      }
    }
  }
View Full Code Here

   
    //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();
          }
        }
      }
View Full Code Here

    if(vehiclesAtCross.size() > 0 ){
      //TODO:[PROG] elkepzeleseim szerint egy 100 hosszu uton, a keresztezodesnel levo autok,
      //a kovetkezo sorrendben helyezkednek el: 100 99 98 stb...
     
      //get and remove last car
      Vehicle removed_car = vehiclesAtCross.get(0);
      vehiclesAtCross.remove(0);
     
      //ha azon a valakin kivul meg mas is van a keresztezodesnel
      //akkor egyel elorebb tokjuk oket
      if(vehiclesAtCross.size() > 1){
View Full Code Here

   * egy �tr�l bel�ptet egy j�rm�t a keresztez�d�sbe (a megadott szab�lyok alapj�n,
   * mely a keresztez�d�s t�pus�t�l f�gg
   */
  public void stepIntoCross(Route r) {
    if(r != null){
      Vehicle car = r.getAndRemoveLastCar();
      if(vehicleInCross == null){
        vehicleInCross = car;
      } else {
        if(vehicleInCross.getCarType() == carType.Robbery){
          //ha nem ures a cross(a bankrablo van benne)
View Full Code Here

    //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);
      }
    }
  }
View Full Code Here

TOP

Related Classes of exercise3.exercise3_10.vehicles.Vehicle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.