Ejemplo n.º 1
0
  private void try_transition(Dir dir) {
    // No transition yet.
    if (percentage < 1 - straight_per_inc) {
      return;
    }

    TrackPiece newLocation = null;

    switch (dir) {
      case LEFT:
        newLocation = myLocation.getLeft();
        break;
      case UP:
        newLocation = myLocation.getUp();
        break;
      case DOWN:
        newLocation = myLocation.getDown();
        break;
      case RIGHT:
        newLocation = myLocation.getRight();
        break;
    }

    if (newLocation == null) {
      handle_end_of_track();
    } else {
      myLocation = newLocation;
      percentage = 0;

      // Make sure we keep track of which direction the car is currently going in.
      myDir = dir;
    }
  }