public UserFacility AddFacility(Facility facility) { if (Facilities.Any(f => f.Facility.Id == facility.Id)) { throw new DomainException("Facility has already been added to user"); } var newUserFacility = new UserFacility(facility, this); Facilities.Add(newUserFacility); return(newUserFacility); }
public Farm() { FileHandler = new FileHandler(); SeedHarvester = new SeedHarvester(FileHandler); Composter = new Composter(FileHandler); MeatProcessor = new MeatProcessor(FileHandler); FeatherGatherer = new FeatherGatherer(FileHandler); EggGatherer = new EggGatherer(FileHandler); FileHandler.Facilities.ForEach(fac => { IFacility newFacility = null; string[] facilityData = fac.Split(":"); string type = facilityData[0]; string name = facilityData[1]; string data = facilityData[2]; switch (type) { case "Chicken House": newFacility = new ChickenHouse(name, data); break; case "Duck House": newFacility = new DuckHouse(name, data); break; case "Grazing Field": newFacility = new GrazingField(name, data); break; case "Plowed Field": newFacility = new PlowedField(name, data); break; case "Natural Field": newFacility = new NaturalField(name, data); break; default: throw new Exception("Invalid data"); } Facilities.Add(newFacility); }); }
private RoomTypeDesignModel() { Title = "Custom one type"; Description = "A test one room type"; PricePerFit = 200; Area = 15.2; Fits = 2; Facilities.Add(new DataModels.Facility() { Title = "Option 1", Tag = "snow" }); Facilities.Add(new DataModels.Facility() { Title = "Option 2", Tag = "snow" }); Facilities.Add(new DataModels.Facility() { Title = "Option 3", Tag = "snow" }); }
//public List<IAnimalFacility> AnimalFacilities //{ // get // { // return Facilities.Where(fac => { // return fac is IAnimalFacility; // }).Cast<IAnimalFacility>().ToList(); // } //} //public int NumberOfAnimalFacilities { // get // { // return ChickenHouses.Count + DuckHouses.Count + GrazingFields.Count; // } } //public List<IAnimalFacility> AnimalFacilities { get // { // List<IAnimalFacility> output = new List<IAnimalFacility>(); // output.AddRange(); // } //} //public int NumberOfPlantFacilities //{ // get // { // return NaturalFields.Count + PlowedFields.Count; // } //} /* * This method must specify the correct product interface of the * resource being purchased. */ //public void PurchaseResource<T>(IResource resource, int index) //{ // Console.WriteLine(typeof(T).ToString()); // switch (typeof(T).ToString()) // { // case "Cow": // GrazingFields[index].AddResource(resource); // break; // default: // break; // } //} public void AddFacility(IFacility facility) { Facilities.Add(facility); }
/// <summary> /// This is where we create objects by reading a file /// Bases on the AreaType we can dynamically create objects of this Areatype /// We also create objects manually by creating the factory, we can send a string which identifies what kind of object we want to create /// We send the facility model to the being created object which he can initialize /// </summary> /// <param name="file"></param> private void CreateFactoryObjects(string file) { IFactory locationTypeFactory = Factory.AbstractFactory.Instance().Create("LocationType"); // This fileReader object is made to read files and make objects out of it FileReader fileReader = new FileReader(); // This code lets us write the layout into model List <Facility> facilitiesModels = fileReader.ReadLayoutFile(file); // We jump right into the models annd for every mode lwe create an object foreach (var item in facilitiesModels) { // Setting hte of the hte value in the facility model item.Hte = this.hte; // Bases on the areaytype we create items LocationType AreaType = locationTypeFactory.CreateCreatableObject(item.AreaType, item) as LocationType; // We add the item in an list so we can make use of it Facilities.Add(AreaType); } // get the object with the biggest x-position. Now we can add the x position and Dimension * width to give stairs te correct position LocationType biggest = Facilities.Aggregate((i1, i2) => i1.Position.X > i2.Position.X ? i1 : i2); // We need the max y-position from the facility list so we can create the correct amount of stairs and elevatorshafts int maxYposHotel = Facilities.Max(element => element.Position.Y); // We need to know the minimum x-position because if the lowest x-position is zero, then the elevatorshafts has to have a position aswell. int minXposHotel = Facilities.Min(element => element.Position.X); // If the lowest x-position is zero or lower, we subtract 1, now we got minus 1 or even lesser, depends on how low the x-position is. if (minXposHotel <= 0) { minXposHotel -= 1; } // Else we keep it at 0, we now can draw multiple layout files without having to worry about the positions given to us. else { minXposHotel = 0; } // In the method ChangePositionHotel, I will continiue this comment..... // Where we will store information to send to locationtype Facility specs; // Where we will store the created ID. Locationtype will set this as it's ID. int CreatedID = 0; // This is where lobby is created CreatedID = Facilities.Max(element => element.ID) + 1; specs = new Facility() { AreaType = "Lobby", Dimension = new Point(biggest.Position.X + Math.Abs(minXposHotel) + biggest.Dimension.X - 1, 1), Position = new Point(1 + minXposHotel, 0), ID = CreatedID, Hte = this.hte }; LocationType Lobby = locationTypeFactory.CreateCreatableObject("Lobby", specs) as LocationType; lobby = Lobby as Lobby; Facilities.Add(Lobby); // this is the elevatorhall where elevator moves in for (int i = 0; i <= maxYposHotel; i++) { CreatedID = Facilities.Max(element => element.ID) + 1; specs = new Facility() { AreaType = "ElevatorHall", Position = new Point(minXposHotel, i), Dimension = new Point(1, 1), ID = CreatedID, Hte = this.hte }; LocationType elevatorHall = locationTypeFactory.CreateCreatableObject("ElevatorHall", specs) as LocationType; Facilities.Add(elevatorHall); if (i == 0) { specs = new Facility() { ElevatorShaft = elevatorHall, Hte = this.hte }; elevator = locationTypeFactory.CreateCreatableObject("Elevator", specs) as Elevator; } (elevatorHall as ElevatorShaft).Attach(elevator); } // Staircase will be set on the last row of the hotel for (int i = 0; i <= maxYposHotel; i++) { CreatedID = Facilities.Max(element => element.ID) + 1; specs = new Facility() { AreaType = "Staircase", Position = new Point((biggest.Position.X + biggest.Dimension.X), i), Dimension = new Point(1, 1), ID = CreatedID, Hte = this.hte }; LocationType stairCase = locationTypeFactory.CreateCreatableObject("Staircase", specs) as LocationType; Facilities.Add(stairCase); } // Give Lobby the rooms because we see it as the reception, so the reception has to manage visitors. // Visitors dont leave the place so their world is all facilities combined. for (int i = 0; i < Facilities.Count; i++) { if (Facilities[i].AreaType.Equals("Room")) { lobby.GetRoom((Facilities[i] as Room)); } } pathfinding = new PathFinding(Facilities); // Change position from hotel if there are negative coordinations (like position.x = -1) ChangePositionLocationtypes(); InitialiseHotelDimension(); }