// !Mainly used for manual testing with different vehicle types! // Adds a new Vehicle to the list of Vehicles - // Creates a new Vehicle instance and assigns it a free parking space if available // takes argument v_Vehicle - type of vehicle to be created // returns a string with the return message of the method public string ParkVehicle(v_Vehicle type) { // Checks if the garage is full, so we can exit earlier if the garage is full if (NumberOfParkingSpaces == m_Vehicles.Count) { return($"The garage is full."); } // Get the current date string dateNow = GetDate(); // the new vehicle to be added Vehicle vehicle; // = GenerateRandomVehicle(); switch (type) { case v_Vehicle.Bus: vehicle = new Bus() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.Car: vehicle = new Car() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.MC: vehicle = new MC() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.Truck: vehicle = new Truck() { regNr = getRandomRegNr(), dateTime = dateNow }; break; default: vehicle = null; break; } // so we can exit earlier if there's not enough space in the garage if (GetNumberOfFreeSpaces() < vehicle.vehicleSize) { return($"The garage is full!!."); } ParkingSpot index = FindFreeParkingSpace(vehicle.vehicleSize); // index used to find empty parking space // checks if we found a free parking space for the type of vehicle if (index.X == -1 && index.Y == -1) { return($"Not enough empty spaces in the garage for a vehicle of type: { vehicle.vehicleType.ToString()}."); } // sets the found parking space(s) to occupied/true for (int i = 0; i < vehicle.vehicleSize; i++) { m_ParkingSpaces[index.X, index.Y + i] = !m_ParkingSpaces[index.X, index.Y + i]; } // assigns the vehicle its parking space vehicle.parkingSpot = index; // add the new vehicle to the list m_Vehicles.Add(vehicle); return($"The vehicle of the type: {vehicle.vehicleType.ToString()} " + $"with the registration number: {vehicle.regNr} \nwas parked in the garage at " + $"parking space(s): {index.ToString()}" + (vehicle.vehicleSize > 1 ? $" to [{index.X + 1},{index.Y + vehicle.vehicleSize}]." : "")); }