Exemple #1
0
 private static List <Boat> RemoveCargoShipFromParking(CargoShip cargoShip, List <Boat> parkedBoats)
 {
     var(parkingPlaceHasValue, parkingPlace) = ParkingPlaceHasFound(cargoShip);
     if (parkingPlaceHasValue)
     {
         harbour[parkingPlace.Key]     = null;
         harbour[parkingPlace.Key + 1] = null;
         harbour[parkingPlace.Key + 2] = null;
         harbour[parkingPlace.Key + 3] = null;
         parkedBoats.Remove(cargoShip);
         emptyParking += 4;
     }
     return(parkedBoats);
 }
Exemple #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);
        }
Exemple #3
0
 private static void ParkCargoShip(CargoShip boat)
 {
     for (int i = 1; i <= harbour.Count; i++)
     {
         if (harbour[i] == null)
         {
             if (harbour.ContainsKey(i + 1) && harbour.ContainsKey(i + 2) && harbour.ContainsKey(i + 3))
             {
                 harbour[i]        = boat.IdentityNumber;
                 harbour[i + 1]    = boat.IdentityNumber;
                 harbour[i + 2]    = boat.IdentityNumber;
                 harbour[i + 3]    = boat.IdentityNumber;
                 boat.ParkingPlace = $"{ i }-{ i + 1}-{ i + 2}-{ i + 3}";
                 _parkedBoats.Add(boat);
                 emptyParking -= boat.RequiredParkingPlace;
                 dockedCount  += 1;
                 break;
             }
         }
     }
 }