Exemplo n.º 1
0
        public Level(int flr, int numberSpots)
        {
            floor = flr;
            spots = new ParkingSpots[numberSpots];
            int largeSpot    = numberSpots / 4;
            int bikeSpots    = numberSpots / 4;
            int compactSpots = numberSpots - largeSpot - bikeSpots;

            //Allocate spots for parking on each level according to size/type of vehicle
            for (int i = 0; i < numberSpots; i++)
            {
                //Motorcycle can fit in any spot
                VehicleSize sz = VehicleSize.Motorcycle;
                if (i < largeSpot)
                {
                    //Large vehicle can only fit in Large Spot
                    sz = VehicleSize.Large;
                }
                else if (i < largeSpot + compactSpots)
                {
                    //Compact vehicle can fit in Compact & Large spot
                    sz = VehicleSize.Compact;
                }
                int row = i / SPOTS_PER_ROW;
                spots[i] = new ParkingSpots(this, row, i, sz);
            }
            availableSpots = numberSpots;
        }
Exemplo n.º 2
0
        //Find a spot to park this vehicle; return index of spot -1 on failure
        public int findAvailableSpots(Vehicle vehicle)
        {
            int spotsNeeded = vehicle.getSpotsNeeded();
            int lastRow     = -1;
            int spotsFound  = 0;

            for (int i = 0; i < spots.Length; i++)
            {
                ParkingSpots spot = spots[i];
                if (lastRow != spot.getRow())
                {
                    spotsFound = 0;
                    lastRow    = spot.getRow();
                }
                if (spot.canFitVehicle(vehicle))
                {
                    spotsFound++;
                }
                else
                {
                    spotsFound = 0;
                }
                if (spotsFound == spotsNeeded)
                {
                    return(i - (spotsNeeded - 1));
                }
            }
            return(-1);
        }
Exemplo n.º 3
0
 //Park vehicle int the spot
 public void parkInSpot(ParkingSpots spot)
 {
     parkingSpots.Add(spot);
 }