Beispiel #1
0
        /// <summary>
        /// Park this Car.
        /// </summary>
        /// <returns>Successful park.</returns>
        public bool Park()
        {
            if (this.ParkingLot == null)
            {
                throw new Exception("This car needs to enter a parking lot before it can park.");
            }

            List <IParkingSpace> availableParkingSpaces = ParkingLot.GetAvailableParkingSpaces();

            if (availableParkingSpaces.Count == 0)              // Are spaces available?
            {
                return(false);
            }
            this.ParkingSpace = availableParkingSpaces[0];              // Take the first available spot
            return(this.ParkingSpace.Take());
        }
Beispiel #2
0
        /// <summary>
        /// Unpark this Car.
        /// </summary>
        public void Unpark()
        {
            if (this.ParkingLot == null)
            {
                throw new Exception("This car needs to park in a parking lot before it can unpark.");
            }

            if (this.ParkingSpace == null)
            {
                throw new Exception("This car needs to be parked before it can unpark.");
            }

            // Leave the parking space
            this.ParkingSpace.Vacate();
            this.ParkingSpace = null;
        }