/// <summary> /// UnloadContent will be called once per game and is the place to unload /// game-specific content. /// </summary> protected override void UnloadContent() { //unregister listeners HotelEventManager.Deregister(_checkInListener); HotelEventManager.Deregister(_checkOutListener); //stop HotelEventManager HotelEventManager.Stop(); hotel.StopTimer(); }
/// <summary> /// Moves the Customer depending on what their Status is. /// </summary> public void Move() { //Since the applications is Multi-Threaded (runs on multiple threads due to the HotelEventManager) //This can't be added to the HotelEventManager when created through an Event //That's why it's called on the Main Application thread and not on the HotelEventManger thread if (!IsRegistered) { HotelEventManager.Register(this); IsRegistered = true; } //Since the Customer can Die, we check if the Customer is waiting and if their DeathTimer does not exceed the given TimeBeforeDeath if (IsWaiting == true && DeathTimer >= Hotel.Settings.TimeBeforeDeath) { //If the Customer needs to die we can remove all instances of him in the Lists //That way the C# Garbage Collector will collect it's poor soul GlobalStatistics.Customers.Remove(this); HotelEventManager.Deregister(this); } //If the Customer needs to wait for something (Eating, Fitnessing, Taking the Stairs) they will not move until this task is completed (WaitingTime = 0) if (WaitingTime > 0) { WaitingTime--; } //If the Customer doesn't need to wait for anything to finish else if (WaitingTime == 0) { if (Path != null) { #region ToElevator //If the Customer is in front of the Elevator we will check if it's still efficient to use the Elevator or the Stairs if (Path.RouteType == ERouteType.ToElevator && Hotel.Floors[PositionY].Areas[PositionX - 1].AreaType == EAreaType.ElevatorShaft) { GetRoute(); } //If the Customer is not in front of the Elevator yet, they will walk towards the Elevator by Dequeueing Nodes else if (Path.RouteType == ERouteType.ToElevator && Path.PathToElevator.Count != 0) { //The Node contains all the info for the Customer to move forward (an X and Y co-ordinate) Node moveNode = Path.PathToElevator.Dequeue(); PositionX = moveNode.Area.PositionX; PositionY = moveNode.Area.PositionY; } #endregion #region Elevator if (Path.RouteType == ERouteType.Elevator) { //If the Customer isn't in the Elevator we're going to try and request it if (!IsInElevator) { //If the Customer is in front of the Elevator they will enter the Elevator and request the floor (int) that they need to go too if (Hotel.Elevator.GetElevatorInfo().Item2 == PositionY && Hotel.Floors[PositionY].Areas[PositionX - 1].AreaType == EAreaType.ElevatorShaft && !IsInElevator) { //Customer Requests the Elevator with their desired Floor Hotel.Elevator.RequestElevator(Destination.Floor); //If the Elevator is on their left side, all they have to do is step to the left (meaning X - 1) PositionX--; IsInElevator = true; //Reset RequestedElevator so that the Customer can request the Elevator again RequestedElevator = false; //Add the Customer to the Elevator so the Customer's position is updated with every HTE with the position of the Elevator Hotel.Elevator.InElevator.Add(this); } //If the Customer is in front of the ElevatorShaft they request the Elevator to their current position else if (Hotel.Floors[PositionY].Areas[PositionX - 1].AreaType == EAreaType.ElevatorShaft && !IsInElevator) { if (!RequestedElevator) { Hotel.Elevator.RequestElevator(PositionY); RequestedElevator = true; } } } //If the Customer is in the Elevator then we need to check if they need to get out the Elevator or not else { //If the Customer is on the Floor (int) that they need to be then she will step out of the Elevator and set their path to FromElevator if (PositionY == Destination.Floor) { Hotel.Elevator.InElevator.Remove(this); Path.RouteType = ERouteType.FromElevator; IsInElevator = false; } } } #endregion #region FromElevator //If the Customer has stepped out of the Elevator, they need to continue their Path to their Destination else if (Path.RouteType == ERouteType.FromElevator && Path.PathFromElevator.Count != 0) { //This is done by Dequeueing Node's and setting the Customer's current position to that of the Node Node moveNode = Path.PathFromElevator.Dequeue(); PositionX = moveNode.Area.PositionX; PositionY = moveNode.Area.PositionY; } #endregion #region Stairs //If the Customer has decided to take the Stairs instead of the Elevator if (Path.RouteType == ERouteType.Stairs) { //And the Stair Path is still filled with Node's if (Path.Path.Count != 0) { //By Dequeueing a Node, the Customer can move by making their X and Y co-ordinate the same as the Node's Node moveNode = Path.Path.Dequeue(); PositionX = moveNode.Area.PositionX; PositionY = moveNode.Area.PositionY; //If the Customer moves into a Node, their waiting time should be set to the StairTime (StairTime can be set in the ReceptionScreen) if (moveNode.Area.AreaType == EAreaType.Staircase) { WaitingTime = WaitingTime + Hotel.Settings.StairCase - 1; } } } #endregion } //If the Path is null (for some reason) the Customer goes back to their Room else { Path = Graph.QuickestRoute(Hotel.Floors[PositionY].Areas[PositionX].Node, AssignedRoom.Node, true, true); } //If the Customer doesn't have anywhere to go, they will get their QuickestRoute to their Room if (Destination == null) { Path = Graph.QuickestRoute(Hotel.Floors[PositionY].Areas[PositionX].Node, AssignedRoom.Node, true, true); } } //If the Customer is not in an IArea then it should be drawn if (InArea == null) { IsVisible = true; } //If the Customer isn't in an IArea then it shouldn't be drawn else { IsVisible = false; } //If the Customer has arrived on their Destination if (Hotel.Floors[PositionY].Areas[PositionX].Node == Destination) { //If the Destination is a Restaurant if (Destination.Area.AreaType == EAreaType.Restaurant) { //They will enter the Area and set their WaitingTime to the Restaurant's EatingTime (EatingTime can be changed for every restaurant) WaitingTime = ((Restaurant)Destination.Area).EatingTime; InArea = Destination.Area; //Their Destination is set to their Room //If the Customer is done Eating they will automatically go back to their Room Destination = AssignedRoom.Node; Path = Graph.QuickestRoute(Hotel.Floors[PositionY].Areas[PositionX].Node, Destination, true, true); } //If the Destination is a Cinema else if (Destination.Area.AreaType == EAreaType.Cinema) { //The Customer will check if the Movie has started or not if (!((Cinema)Destination.Area).MovieStarted) { //If the Movie hasn't started it will put itself in the WaitingLine of the Cinema ((Cinema)Destination.Area).WaitingLine.Add(this); //The IsWaiting will be set to true (Customers can die if they wait too long) IsWaiting = true; } //If the Movie has already started, poor Customer :( else { //Their Destination will be set to their Room and they'll travel back to it Destination = AssignedRoom.Node; Path = Graph.QuickestRoute(Hotel.Floors[PositionY].Areas[PositionX].Node, Destination, true, true); } } //If the Destination is a Fitness else if (Destination.Area.AreaType == EAreaType.Fitness) { //Their WaitingTime will be set to their FitnessTime and they'll enter the Area //FitnessTime is given with the GOTO_FITNESS HotelEvent WaitingTime = FitnessTime; InArea = Destination.Area; //Their Destination is set to their Room //If the Customer is done Fitnessing they will automatically go back to their Room Destination = AssignedRoom.Node; Path = Graph.QuickestRoute(Hotel.Floors[PositionY].Areas[PositionX].Node, Destination, true, true); } //If the Destination is their AssignedRoom else if (Hotel.Floors[PositionY].Areas[PositionX] == AssignedRoom) { //It will enter their Room InArea = AssignedRoom; } } else if (WaitingTime == 0) { InArea = null; } //If the Customer's status is CHECK_OUT (meaning they want to check out) and they're standing on the Reception if (Status == HotelEventType.CHECK_OUT && Hotel.Floors[PositionY].Areas[PositionX] == Hotel.Reception) { //They'll remove themselves from any Lists reffering to them and the Garbage Collector will delete them from existence GlobalStatistics.Customers.Remove(this); HotelEventManager.Deregister(this); } #region DeathTimer //We check if their current position is the same as their last one //If that's true and their not inside an Area if (LastLocation == Hotel.Floors[PositionY].Areas[PositionX].Node && InArea == null) { //The IsWaiting will be set to true and the DeathTimer increases IsWaiting = true; DeathTimer++; } //If this is false else { //The IsWaiting will be set to false and their DeathTimer will be reset IsWaiting = false; DeathTimer = 0; } //And their LastLocation will be saved LastLocation = Hotel.Floors[PositionY].Areas[PositionX].Node; #endregion }
/// <summary> /// Deregisters a HotelEventListener /// </summary> /// <param name="newGuest">HotelEventListener class</param> public void Deregister(Eventadapter newGuest) { HotelEventManager.Deregister(newGuest); }