Doesn't seem to call function (Parking Lot)

edited December 2017 in Questions about Code

So I'm doing a parking simulator, and I have a lot of classes for it. One of these is the Car. Basically, inside the car I have functions that make it drive forward, if it wants to park it'll move into the parking lot, and also change a parkingstall's color to show that it is occupied.

Now, I'm trying to call upon a function that will move the car out at a random time. However...it doesn't seem like it's calling the function at all

So does anyone know what I'm doing wrong here?

class Car {
  int posX;
  int posY;
  int c_length = 45;
  int c_width = 30;
  int speed;
  int c;
  boolean parking;
  Date car_enter;
  Date car_exit;
  ParkingStall spot;

  Car (int x) {
    posX = x;
    posY = 175;
    speed = 1;
    c = color((int)random(256), (int)random(256), (int)random(256));
    if ((int)random(100)%3 == 0)
      parking = true;
    else
      parking = false; 
  }

  void DrawCar() {
    fill (c);
    stroke (0);
    strokeWeight(1);
    rect(posX, posY, c_length, c_width);
    if (parking && posY == 175 && Spaces > 0)
    {
      fill(255);
      textAlign(CENTER);
      textSize(10);
      text("PARKING", posX + 22, posY - 5);
    } 
  }

  void MoveCar() {
    if (posY == 175 || posY == 785)
      posX += speed;
    if (Spaces > 0 && parking == true && posX == 436)
          TurnCar();
    if (Spaces < 60)
      UnOccupy();
  }      

  void TurnCar() {
    c_length = 30;
    c_width = 45;
    posX = 436;
    posY += speed;
    if (posY == 225) {
      Occupy();
      posY = 1000;
      car_enter = current;
    }
  }

  void ExitCar() {
    posX = 438;
    posY = 785;
    car_exit = current;
    PriceCalculator c_price = new PriceCalculator (car_enter, car_exit);
    exit.fee = c_price.calc();
  } 

  void Occupy() {
    boolean not_parked = true;
    do
    {
      spot = findSpot();
      if (spot.occupied == false)
      {
        spot.occupied = true;
        Spaces--;
        not_parked = false;
      }
    } while (not_parked);
  }

  void UnOccupy() {
    if (frameRate % 20 == 0) {
      int r = (int)random(10000);
      if (r < 5) {
        spot.occupied = false;
        ExitCar();
      }
    }
  }

  ParkingStall findSpot() {
    int section = (int)random(6);
    int stall = (int)random(10);
    return Lot.ParkingLot[section].StallSection[stall];
  }
}

I feel like it may have something to do with the fact I changed the what Stall it was in, in a function. Is that the problem I have here?

Tagged:

Answers

  • Answer ✓

    I look at this line and scratch my head:

    if (frameRate % 20 == 0) {

    What would the frameRate have to do with anything?

    Maybe you wanted the frameCount?

  • edited December 2017

    That said, if cars are supposed to maybe unOccupy() with some chance every 20 frames, great. If the way they leave is more up to you, I would have them pick a random amount of time to stay once they enter, and then leave once that time has elapsed.

    • if (frameRate % 20 == 0): "do this single every frame if the sketch frameRate was set at 20, 40, or 60 etc. when the sketch started
    • if (frameCount % 20 == 0): "do this every 20th frame (when the frameCount is 20, 40, 60 etc.)"
  • Thanks for catching that guys. Can't believe I looked over it

Sign In or Register to comment.