コード例 #1
0
 private Intersection findNextInter() {
   Road r = getRoad();
   if (getDir() == r.getDir()) nextInter = r.getEndIntersection();
   else nextInter = r.getStartIntersection();
   TrafficControl tc = nextInter.getTrafficControl();
   if (tc != null && tc.getType() == 0) {
     int oppDir = RoadGrid.getOppDir(getDir());
     synchronized (tc) {
       ((TrafficSignal) tc).addListener(this, oppDir);
     }
     watch_red = ((TrafficSignal) tc).getSignalState(oppDir) == 0;
   }
   return nextInter;
 }
コード例 #2
0
 private void make_Turn(int dir) {
   TrafficControl traf_cont = nextInter.getTrafficControl();
   int oppDir = RoadGrid.getOppDir(getDir());
   boolean listen = false;
   if (traf_cont != null && traf_cont.getType() == 0) listen = true;
   if (!watch_red && !nextInter.isOccupied()) {
     if (listen)
       synchronized (traf_cont) {
         ((TrafficSignal) traf_cont).removeListener(this, oppDir);
       }
     synchronized (nextInter) {
       crossIntersection(nextInter, dir);
       this.accelerate((getRoad().getSpeedLimit() - getSpeed()) * 10, 0);
     }
     findNextInter();
   }
 }