/// <summary> /// Creates a function hotel /// </summary> /// <param name="layout">A file which contains a functioning layout</param> /// <param name="settings">The Settings for the simulation</param> /// <param name="TypeOfBuilder">A type of builder that can handle the provided file</param> public Hotel(List <JsonModel> layout, SettingsModel settings, IHotelBuilder TypeOfBuilder) { // Hotel will handle the CheckIn_events so it can add them to its list // making it possible to keep the list private HotelEventManager.Register(this); _hotelBuilder = TypeOfBuilder; // Build the hotel HotelAreas = _hotelBuilder.BuildHotel(layout, settings); HotelMovables = _hotelBuilder.BuildMovable(settings, this); // Set calculation properties HotelWidth = HotelAreas.OrderBy(X => X.Position.X).Last().Position.X; HotelHeight = HotelAreas.OrderBy(Y => Y.Position.Y).Last().Position.Y; _elevatorCart = (ElevatorCart)HotelMovables.Find(X => X is ElevatorCart); // Methods for final initialization Dijkstra.IntilazeDijkstra(this); HotelEventManager.Start(); }
/// <summary> /// Provide a generic file and an Settings model /// Through these parameters create a list of IAreas /// This method is also responsible for setting the neighbours /// </summary> /// <typeparam name="T"></typeparam> /// <param name="file">A file providing information to build an IArea list</param> /// <param name="settings">The Settings model used for the simulation</param> /// <returns></returns> public List <IArea> BuildHotel <T>(T file, SettingsModel settings) { #region Casting the file to a List<JsonModel> List <JsonModel> jsonModel; if (file is List <JsonModel> ) { jsonModel = file as List <JsonModel>; } else { // the provided file is incorrect // The error handling is not fully implemented return(null); } #endregion #region Read out the json file and add rooms to the layout foreach (JsonModel i in jsonModel) { int classificationNum = 0; if (i.Classification != null) { classificationNum = int.Parse(Regex.Match(i.Classification, @"\d+").Value); } IArea area = Factory.GetArea(i.AreaType); area.SetJsonValues(i.ID, i.Position, i.Capacity, i.Dimension, classificationNum); HotelAreas.Add(area); } HotelWidth = HotelAreas.OrderBy(X => X.Position.X).Last().Position.X + 1; HotelHeight = HotelAreas.OrderBy(Y => Y.Position.Y).Last().Position.Y + 1; #endregion #region Set constant objects // Set Elevator and staircase for (int i = 1; i < HotelHeight + 1; i++) { IArea elevator = Factory.GetArea("Elevator"); IArea staircase = Factory.GetArea("Staircase"); elevator.SetJsonValues(HotelAreas.Count() + 1, new Point(0, i), settings.ElevatorCapicity, new Size(1, 1), i); staircase.SetJsonValues(HotelAreas.Count() + 1, new Point(HotelWidth, i), 5, new Size(1, 1), 0); HotelAreas.Add(elevator); HotelAreas.Add(staircase); } // Set reception and lobby for (int i = 1; i < HotelWidth; i++) { if (i == 1) { IArea reception = Factory.GetArea("Reception"); reception.SetJsonValues(HotelAreas.Count() + 1, new Point(1, HotelHeight), 5, new Size(1, 1), 1); HotelAreas.Add(reception); } else { IArea Lobby = Factory.GetArea("Lobby"); Lobby.SetJsonValues(HotelAreas.Count() + 1, new Point(i, HotelHeight), 5, new Size(1, 1), i); HotelAreas.Add(Lobby); } } #endregion #region Settings infromation from the settings model and the neigbors foreach (IArea area in HotelAreas) { // Set Settings for cinema if (area is Cinema) { ((Cinema)area).Duration = settings.CinemaDuration; } // Set Settings for fitness else if (area is Fitness) { ((Fitness)area).Capacity = settings.FitnessCapicity; } // Set Settings for restaurant else if (area is Restaurant) { ((Restaurant)area).Capacity = settings.RestaurantCapicity; ((Restaurant)area).Duration = settings.RestaurantDuration; } else if (area is null) { HotelAreas.Remove(area); } // All neighbours weights are 1 since it has been stated in one // of the meetings with the PO that they can jump over the other rooms // it would be nicer to add a hallway tile and walk that way but there // was no time to do this // Add right neighbour for (int i = 1; i < HotelWidth; i++) { if (AddNeighbour(area, i, 0, 1)) { break; } } // Add left neighbour for (int i = 1; i < HotelWidth - 1; i++) { if (AddNeighbour(area, -i, 0, 1)) { break; } } if (area.Position.X == 0 || area.Position.X == HotelWidth) { // The elevator won't get any neighbours if (area is Elevator) { continue; } // Add top neighbour AddNeighbour(area, 0, 1, 1); // Add bottom neighbour AddNeighbour(area, 0, -1, 1); } } #endregion // Returning the hotel layout return(HotelAreas); }