Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Garage garage = new Garage(2, 10);
            Random rnd    = new Random();

            Vechile[] vechiles = new Vechile[40];
            for (int i = 0; i < vechiles.Length; i++)

            {
                vechiles[i] = new Vechile()
                {
                    LicenseNo = "xteas" + i, Type = i % 2 == 0 ? VechileType.Car : VechileType.Bike, Model = "Model vechile" + i, Status = ParkingStatus.NotParked
                };
            }
            char c = ' ';

            while (c != 'C')
            {
                for (int i = 0; i < vechiles.Length; i++)
                {
                    if (vechiles[i].Status == ParkingStatus.NotParked)
                    {
                        garage.Park(vechiles[i]);
                    }
                    if (vechiles[i].IsReadyToExit())
                    {
                        garage.Exit(vechiles[i]);
                    }
                }
                Console.WriteLine("Press C to end the Simulation or press any other character to continue");
                c = Console.ReadLine()[0];
            }
        }
Exemplo n.º 2
0
 public void Exit(Vechile vechile)
 {
     foreach (var level in _Levels)
     {
         if (level.HasVechile(vechile))
         {
             level.Exit(vechile);
             vechile.Status = ParkingStatus.NotParked;
             break;
         }
     }
 }
Exemplo n.º 3
0
        public void Park(Vechile vechile)
        {
            bool carParked = false;

            foreach (var level in _Levels)
            {
                if (level.HasFreeSlot())
                {
                    ParkingSlot slot = level.GetNearestFreeSlot();
                    slot.OccupySlot(vechile);
                    Console.WriteLine(string.Format("{0} {1} parked at level {2} slot {3}", vechile.Model, vechile.Type.ToString(), level.LevelNumber, slot.SlotNumber));
                    Console.WriteLine();
                    carParked      = true;
                    vechile.Status = ParkingStatus.Parked;
                    vechile.CountDownForExit();
                    break;
                }
            }
            if (!carParked)
            {
                Console.WriteLine(string.Format("{0} {1} is rejected because there is no free space at the garage", vechile.Model, vechile.Type.ToString()));
                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
 public bool IsOccupiedWith(Vechile vechile)
 {
     return(vechile == _Vechile);
 }
Exemplo n.º 5
0
 public void OccupySlot(Vechile vechile)
 {
     this._Vechile = vechile;
 }
Exemplo n.º 6
0
        public void Exit(Vechile vechile)
        {
            ParkingSlot slot = slots.Single(s => s.IsOccupiedWith(vechile));

            slot.FreeSlot();
        }
Exemplo n.º 7
0
 public bool HasVechile(Vechile vechile)
 {
     return(slots.Any(s => s.IsOccupiedWith(vechile)));
 }