Пример #1
0
        public static void ParkBoats()
        {
            const string filePath = @"C:\Visual Stadio\HarbourManagement\DockedBoatsInHarbor.csv";

            if (File.Exists(filePath) && filePath.Length > 0)
            {
                _parkedBoats = FileSystem.ReadBoatInfoFromFile().Select(x => x).ToList();
                _parkedBoats.ForEach(x =>
                {
                    var parkingPlaces = x.ParkingPlace.Split("-").ToList();
                    parkingPlaces.ForEach(p =>
                    {
                        if (int.TryParse(p, out var parkingIndex))
                        {
                            harbour[parkingIndex] = x.IdentityNumber;
                        }
                    });
                });
                DisplayDockInformation.DisplayInfo(_parkedBoats);
            }

            while (addBoatsToDock == true)
            {
                var WaitingBoats = ArrivedBoatsInDock.RandomBoats();
                DisplayDockInformation.WaitingBoatsInHarbourToPark(WaitingBoats);
                var key = Console.ReadKey();
                if (key.KeyChar == 'a')
                {
                    foreach (var boat in WaitingBoats)
                    {
                        switch (boat)
                        {
                        case RowingBoat rowingBoat:
                            if (emptyParking >= rowingBoat.RequiredParkingPlace)
                            {
                                ParkRowingBoat(rowingBoat);
                            }
                            else
                            {
                                DisplayDockInformation.CouldNotParkMassage(rowingBoat);
                            }

                            break;

                        case MotorBoat motorBoat:
                            if (emptyParking > motorBoat.RequiredParkingPlace)
                            {
                                ParkMotorBoat(motorBoat);
                            }
                            else
                            {
                                DisplayDockInformation.CouldNotParkMassage(motorBoat);
                            }
                            break;

                        case SailBoat sailBoat:
                            if (emptyParking >= sailBoat.RequiredParkingPlace)
                            {
                                ParkSailBoat(sailBoat);
                            }
                            else
                            {
                                DisplayDockInformation.CouldNotParkMassage(sailBoat);
                            }
                            break;

                        case CargoShip cargoShip:
                            if (emptyParking >= cargoShip.RequiredParkingPlace)
                            {
                                ParkCargoShip(cargoShip);
                            }
                            else
                            {
                                DisplayDockInformation.CouldNotParkMassage(cargoShip);
                            }
                            break;

                        default:
                            break;
                        }
                        refusedFromDock = WaitingBoats.Count - dockedCount;
                    }
                    DisplayDockInformation.DisplayInfo(_parkedBoats);
                    NextDay();
                }
                else if (key.KeyChar == 'q')
                {
                    FileSystem.CreatSpreadsheet();
                    Console.WriteLine();
                    Environment.Exit(0);
                }
                else if (key.KeyChar == 'n')
                {
                    NextDay();
                }
            }
        }
Пример #2
0
        private static void NextDay()
        {
            refusedFromDock = 0;
            dockedCount     = 0;
            Console.WriteLine("....................................................................................................................................");
            Console.WriteLine("Press [N] next Day and [Q] to Quit ");
            ConsoleKeyInfo key = Console.ReadKey();

            if (key.KeyChar == 'n')
            {
                TotalDayCount += 1;
                var parkedBoatsCopy = new List <Boat>();
                _parkedBoats.ForEach(b =>
                {
                    b.DaysCount -= 1;
                    parkedBoatsCopy.Add(b);
                });

                foreach (var parkBoat in _parkedBoats)
                {
                    switch (parkBoat)
                    {
                    case RowingBoat rowingBoat:
                        if (rowingBoat.DaysCount == 0)
                        {
                            parkedBoatsCopy = RemoveRowingBoatFromParking(rowingBoat, parkedBoatsCopy);
                        }
                        break;

                    case MotorBoat motorBoat:
                        if (motorBoat.DaysCount == 0)
                        {
                            parkedBoatsCopy = RemoveMotorBoatFromParking(motorBoat, parkedBoatsCopy);
                        }
                        break;

                    case SailBoat sailBoat:
                        if (sailBoat.DaysCount == 0)
                        {
                            parkedBoatsCopy = RemoveSailBoatFromParking(sailBoat, parkedBoatsCopy);
                        }
                        break;

                    case CargoShip cargoShip:
                        if (cargoShip.DaysCount == 0)
                        {
                            parkedBoatsCopy = RemoveCargoShipFromParking(cargoShip, parkedBoatsCopy);
                        }
                        break;

                    default:
                        break;
                    }
                }
                _parkedBoats = parkedBoatsCopy.Where(x => x.DaysCount > 0).Select(x => x).ToList();
            }
            else if (key.KeyChar == 'q')
            {
                FileSystem.CreatSpreadsheet();
                addBoatsToDock = false;
            }
            DisplayDockInformation.DisplayInfo(_parkedBoats);
        }