コード例 #1
0
  protected void goToBusStop(int destinationBusStopNumber, Point location) {

    print("Going to bus Stop " + gui.getClosestBusStopNumber());
    gui.doGoToBusStop();
    // Finish the GUI version of it
    try {
      atCityDestination.acquire();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    print("At bus Stop " + gui.getClosestBusStopNumber() + ". Now waiting");
    Phonebook.getPhonebook()
        .getAllBusStops()
        .get(gui.getClosestBusStopNumber())
        .waitingForBus(this);
    try {
      waitingAtBus.acquire();
      // waitingAtBus.acquire();
      // maybe have to do double acquires?
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    print(
        "Telling "
            + Phonebook.getPhonebook()
                .getAllBusStops()
                .get(gui.getClosestBusStopNumber())
                .getCurrentBus()
                .getName()
            + " that I'm getting on to go to bus stop # "
            + destinationBusStopNumber);
    Phonebook.getPhonebook()
        .getAllBusStops()
        .get(gui.getClosestBusStopNumber())
        .getCurrentBus()
        .msgGettingOnBus(this, destinationBusStopNumber);
    gui.setInvisible();
    try {
      beingTransported.acquire();
      // beingTransported.acquire();
      // maybe have to do double acquires?
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    print("Arriving at destination Bus Stop: " + destinationBusStopNumber);
    gui.getOffBus(destinationBusStopNumber);
    gui.setxDestination(location.x);
    gui.setyDestination(location.y);
  }