You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 rivejä
1.5 KiB

  1. /*
  2. */
  3. package roadtrip;
  4. /**
  5. *
  6. * @author dejvino
  7. */
  8. public class VehicleInstance
  9. {
  10. final static int WEAK = 1;
  11. final static int TRUCK = 2;
  12. final static int SPORT = 3;
  13. static int getVehicleTypesCount() {
  14. return SPORT;
  15. }
  16. int carType;
  17. float accelerationForce = 200.0f;
  18. float brakeForce = 100.0f;
  19. float steeringValue = 0;
  20. float accelerationValue = 0;
  21. float accelerationSmooth = 0;
  22. VehicleInstance(int carType, float accelerationForce, float brakeForce)
  23. {
  24. this.carType = carType;
  25. this.accelerationForce = accelerationForce;
  26. this.brakeForce = brakeForce;
  27. }
  28. public static class WeakVehicle extends VehicleInstance
  29. {
  30. WeakVehicle()
  31. {
  32. super(WEAK, 200.0f, 100.0f);
  33. }
  34. }
  35. public static class TruckVehicle extends VehicleInstance
  36. {
  37. TruckVehicle()
  38. {
  39. super(TRUCK, 1400.0f, 200.0f);
  40. }
  41. }
  42. public static class SportVehicle extends VehicleInstance
  43. {
  44. SportVehicle()
  45. {
  46. super(SPORT, 20000.0f, 200.0f);
  47. }
  48. }
  49. static VehicleInstance createVehicle(int i) {
  50. switch (i + 1) {
  51. case WEAK: return new WeakVehicle();
  52. case TRUCK: return new TruckVehicle();
  53. case SPORT: return new SportVehicle();
  54. default: throw new RuntimeException("Unknown vehicle type " + i);
  55. }
  56. }
  57. }