public void AddHotelEdge() { HotelNodeSet = HotelNodeSet.OrderBy(n => n.RoomData.Position.Y).ThenBy(n => n.RoomData.Position.X).ToList(); // Orders the list so edges can be added easily. for (int index = 0; index < HotelNodeSet.Count; index++) // For each HotelNode add edges. { HotelNode hotelNode = HotelNodeSet[index]; if (index < HotelNodeSet.Count - HotelNodeSet[index].RoomData.Dimension.X) // Checks if HotelNodeSet is not out of range. { HotelNode neighbourHotelNode = HotelNodeSet[index + 1]; // Finds the next node in the orded HotelNodeSet list. if (neighbourHotelNode.RoomData.Position.Y == hotelNode.RoomData.Position.Y) // Adds all horizontal neighbours for the rooms. { hotelNode.RoomNeighbour.Add(new HotelEdge(hotelNode, neighbourHotelNode)); neighbourHotelNode.RoomNeighbour.Add(new HotelEdge(neighbourHotelNode, hotelNode)); } if (hotelNode.RoomData.AreaType.Equals("Stairwell") || hotelNode.RoomData.AreaType.Equals("Elevator")) // Adds all upper and lower neighbours for the starwell/elevator. { HotelNode ElevatorNeighbours = HotelNodeSet.FirstOrDefault(n => n.RoomData.Position.Y.Equals(HotelNodeSet[index].RoomData.Position.Y + 1) && n.RoomData.Position.X.Equals(HotelNodeSet[index].RoomData.Position.X)); // Finds the next Elevator/Stair neightbour in the orded HotelNodeSet list. if (ElevatorNeighbours != null) { hotelNode.RoomNeighbour.Add(new HotelEdge(hotelNode, ElevatorNeighbours)); ElevatorNeighbours.RoomNeighbour.Add(new HotelEdge(ElevatorNeighbours, hotelNode)); } } } } }
public Fitness(HotelNode hotelNode) { Sprite = Image.FromFile(@"..\..\Resources\Images\Fitness.png"); this.hotelNode = hotelNode; Occupied = false; HumanList = new List <IHuman>(); }
public Room(HotelNode hotelNode) { Sprite = Image.FromFile(@"..\..\Resources\Images\Room.png"); spriteOccupied = Image.FromFile(@"..\..\Resources\Images\Room occupied.png"); this.hotelNode = hotelNode; Occupied = false; HumanList = new List <IHuman>(); }
public void RoomEventFinder(HotelNode GoToNode, HotelEvent evt) { if (evt.EventType.Equals(HotelEventType.CHECK_OUT) || evt.EventType.Equals(HotelEventType.EVACUATE)) // Checks if this events has to leave the hotel and make the rooms not full. { hotelRoom.Occupied = false; leaveHotel = true; MyRoom.hotelNode.BackgroundImage = Image.FromFile(@"..\..\Resources\Images\Room.png"); } hotelRoomDestination = (IHotelRoom)GoToNode.HotelObject; specificRoomDirections = RoomPathFinder.PathToRoom(hotelNode, GoToNode, hotelNodes); // Uses Dijkstra to find the shortest path to a room. (Location of Human, location of destination, hotel graph) }
public static List <HotelNode> PathToRoom(HotelNode source, HotelNode destination, List <HotelNode> graph) { List <HotelNode> fastestRout = new List <HotelNode>(); Dictionary <HotelNode, int> distanceToNode = new Dictionary <HotelNode, int>(); Dictionary <HotelNode, HotelNode> lastNode = new Dictionary <HotelNode, HotelNode>(); List <HotelNode> queue = new List <HotelNode>(); graph.ForEach(node => queue.Add(node)); foreach (HotelNode node in queue) { distanceToNode.Add(node, int.MaxValue); // The distance to the other vertices is unknown so they get the temporary value of null. } distanceToNode[source] = 0; // The distance from the source node to the source node is always 0. while (queue.Count != 0) { // Find vertex with smallest distance and remove it from queue. HotelNode smallNode = queue.OrderBy(node => distanceToNode[node]).FirstOrDefault(); queue.Remove(smallNode); // For each edge adjacent to smallnode add edge cost to get to neighboring vertex. foreach (HotelEdge edge in smallNode.RoomNeighbour) { int distance = distanceToNode[smallNode] + 1; // If edge cost to neighbor is bigger than current distance, overwrite value for the edge.destination, set key to edge.destination and value to smallNode. if (distance < distanceToNode[edge.RoomDestination]) { distanceToNode[edge.RoomDestination] = distance; lastNode[edge.RoomDestination] = smallNode; } } // If smallNode has reached the destination break. if (smallNode == destination) { break; } } while (lastNode.ContainsKey(destination)) { fastestRout.Add(destination); destination = lastNode[destination]; } // Reverses rout because fastestRout finds the fastest rout backwards. fastestRout.Reverse(); return(fastestRout); }
public void LoadObjects() { lobbyNode = hotelGraph.HotelNodeSet.FirstOrDefault(n => n.RoomData.AreaType.Equals("Lobby")); // Keeps the hotelNode where the lobby is on. HotelRoomFactory hotelRoomFactory = new HotelRoomFactory(); foreach (HotelNode hotelNode in hotelGraph.HotelNodeSet) { Controls.Add(hotelNode); hotelNode.HotelObject = hotelRoomFactory.HotelRooms(hotelNode); } eventManager = new HotelEventManager(); listener = new HotelEventObserver(this); eventManager.StartEvents(); // Starts the hotel events. eventManager.RegisterListener(listener); // Registers the listener to the event manager. hotelTickrate.Start(); }
public Cleaner(HotelNode hotelNode, Dictionary <string, string> Data, List <HotelNode> hotelNodes) { if (hotelNode != null && hotelNodes != null) { Sprite = Image.FromFile(@"..\..\Resources\Images\Cleaner.png"); this.hotelNode = hotelNode; this.hotelNodes = hotelNodes; this.hotelNode.Image = Sprite; leaveHotel = false; hotelNodeDestination = FindSpecificOpenRoom(Data, hotelNodes); MyRoom = (Room)hotelNodeDestination.HotelObject; specificRoomDirections = RoomPathFinder.PathToRoom(hotelNode, hotelNodeDestination, hotelNodes); // Uses Dijkstra to find the shortest path to a room. (Location of guest, location of destination, hotel graph) hotelRoom = (IHotelRoom)hotelNode.HotelObject; // Casts this hotelNodes object as a IHotelRoom. hotelRoom.AddHuman(this); // Add this instance of a cleaner to a concrete room type. } }
public void Move() { if (leaveHotel == true && hotelRoom == hotelRoomDestination) { hotelRoom.RemoveHuman(this); if (hotelRoom.HumanList.Count == 0) { hotelNode.Image = null; } } if (specificRoomDirections.Count > 0) { HotelNode NextHotelNode = specificRoomDirections.FirstOrDefault(n => hotelNode.RoomNeighbour.Any(e => e.RoomDestination == n)); // Finds the neighbouring hotelnode that equals the first HotelNode in the specificRoomDirections List. hotelRoom.RemoveHuman(this); if (hotelRoom.HumanList.Any(h => h is Guest)) { hotelNode.Image = Image.FromFile(@"..\..\Resources\Images\Guest.png"); } else { hotelNode.Image = Image.FromFile(@"..\..\Resources\Images\Cleaner.png"); } if (hotelRoom.HumanList.Count == 0) // Checks if this hotelRooms HumanList has any humans in it. { hotelNode.Image = null; // Sets this hotelNodes image to null. } hotelRoom = (IHotelRoom)NextHotelNode.HotelObject; // Casts the NextHotelNodes object to this humans hotelRoom. hotelRoom.AddHuman(this); NextHotelNode.Image = Sprite; if (hotelRoom.HumanList.Any(h => h is Guest) && hotelRoom.HumanList.Any(h => h is Cleaner)) { NextHotelNode.Image = Image.FromFile(@"..\..\Resources\Images\CombinedCleanerGuest.png"); } specificRoomDirections.Remove(NextHotelNode); // Removes the NextHotelNode from the specificRoomDirections list so next move instructions will be of the next HotelNode in the list. hotelNode = NextHotelNode; } else { hotelNode.Image = null; // When Cleaner reached Destination image disapears as if going into their room. } }
public IObject HotelRooms(HotelNode hotelNode) { IObject hotelNodeObject = null; if (hotelNode.RoomData.AreaType.Equals("Room")) { hotelNodeObject = new Room(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Lobby")) { hotelNodeObject = new Lobby(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Restaurant")) { hotelNodeObject = new Restaurant(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Elevator")) { hotelNodeObject = new Elevator(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Stairwell")) { hotelNodeObject = new Stairwell(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Cinema")) { hotelNodeObject = new Cinema(hotelNode); } else if (hotelNode.RoomData.AreaType.Equals("Fitness")) { hotelNodeObject = new Fitness(hotelNode); } else { return(null); } return(hotelNodeObject); }