예제 #1
0
 private static List <Boat> RemoveSailBoatFromParking(SailBoat sailBoat, List <Boat> parkedBoats)
 {
     var(parkingPlaceHasValue, parkingPlace) = ParkingPlaceHasFound(sailBoat);
     if (parkingPlaceHasValue)
     {
         harbour[parkingPlace.Key]     = null;
         harbour[parkingPlace.Key + 1] = null;
         parkedBoats.Remove(sailBoat);
         emptyParking += 2;
     }
     return(parkedBoats);
 }
예제 #2
0
        public static List <Boat> ReadBoatInfoFromFile()
        {
            var boats = new List <Boat>();

            const string filePath = @"C:\Visual Stadio\HarbourManagement\DockedBoatsInHarbor.csv";

            foreach (string boat in File.ReadLines(filePath, System.Text.Encoding.UTF7))
            {
                char[]   delimiterChars = { ' ', ',', '(', ')' };
                string[] boatData       = boat.Trim().Split(delimiterChars);
                if (boatData[1] == "RowingBoat")
                {
                    var rowingBoat = new RowingBoat(boatData[1], boatData[3],
                                                    int.Parse(boatData[5]), int.Parse(boatData[7]), int.Parse(boatData[9]), int.Parse(boatData[11]));
                    rowingBoat.ParkingPlace       = boatData[13];
                    BerthManagement.emptyParking -= .5;
                    boats.Add(rowingBoat);
                }
                else if (boatData[1] == "MotorBoat")
                {
                    var motorBoat = new MotorBoat(boatData[1], boatData[3],
                                                  int.Parse(boatData[5]), int.Parse(boatData[7]), int.Parse(boatData[9]), int.Parse(boatData[11]));
                    motorBoat.ParkingPlace        = boatData[13];
                    BerthManagement.emptyParking -= 1;
                    boats.Add(motorBoat);
                }
                else if (boatData[1] == "SailBoat")
                {
                    var sailBoat = new SailBoat(boatData[1], boatData[3],
                                                int.Parse(boatData[5]), int.Parse(boatData[7]), int.Parse(boatData[9]), int.Parse(boatData[11]));
                    sailBoat.ParkingPlace         = boatData[13];
                    BerthManagement.emptyParking -= 2;
                    boats.Add(sailBoat);
                }
                else if (boatData[1] == "CargoShip")
                {
                    var cargoShip = new CargoShip(boatData[1], boatData[3],
                                                  int.Parse(boatData[5]), int.Parse(boatData[7]), int.Parse(boatData[9]), int.Parse(boatData[11]));
                    cargoShip.ParkingPlace        = boatData[13];
                    BerthManagement.emptyParking -= 4;
                    boats.Add(cargoShip);
                }
            }
            return(boats);
        }
예제 #3
0
 private static void ParkSailBoat(SailBoat boat)
 {
     for (int i = 1; i <= harbour.Count; i++)
     {
         if (harbour[i] == null)
         {
             if (harbour.ContainsKey(i + 1))
             {
                 harbour[i]        = boat.IdentityNumber;
                 harbour[i + 1]    = boat.IdentityNumber;
                 boat.ParkingPlace = $"{ i }-{ i + 1}";
                 _parkedBoats.Add(boat);
                 emptyParking -= boat.RequiredParkingPlace;
                 dockedCount  += 1;
                 break;
             }
         }
     }
 }