예제 #1
0
        public Ticket TryPark(Car car, out string message)
        {
            if (car == null ||
                Boys.SelectMany(boy => boy.Lots)
                .Any(lot => lot.HaveCar(car)) ||
                Lots.Any(lot => lot.HaveCar(car)))
            {
                message = "Please provide valid car.";
                return(null);
            }

            var boy = Boys.Concat(new List <Boy>()
            {
                this
            })
                      .Where(boy => boy.FindLotWithStrategy() != null).FirstOrDefault();

            if (boy != null)
            {
                return(boy.Park(car, out message));
            }
            else
            {
                message = "Not enough position.";
                return(null);
            }
        }