Exemplo n.º 1
0
        }                                 // Currently timeing is handeld in guest, it should be moved to Cinema

        // This can be used to cap the cinema on its capicity

        /// <summary>
        /// The Amount of Viewers in the cinema
        /// </summary>
        // public List<IMovable> MovablesInCinema { get; set; } = new List<IMovable>();
        #endregion

        /// <summary>
        /// The AreaFactory creation method.
        /// This creates and initilizes a new IArea.
        /// </summary>
        /// <returns>A new Cinema</returns>
        public IArea CreateArea()
        {
            Cinema newCinema = new Cinema();

            HotelEventManager.Register(newCinema);
            return(newCinema);
        }
Exemplo n.º 2
0
        private void HotelPB_Click(object sender, EventArgs e)
        {
            Point pos = new Point(Cursor.Position.X, Cursor.Position.Y);

            if (hotel.DidIClickOnTheReception(pos))
            {
                if (timer.Enabled) // if timer is enabled then stop timer
                {
                    timer.Stop();
                    frameTimer.Stop();
                    sw.Stop();
                    HotelEventManager.Pauze();
                    Console.WriteLine("Timer gestopt");
                    panelPauze.Visible = true;
                    panelPauze.BringToFront();
                    labelInfo.Text = hotel.Info();
                }
                else // if timer is disabled then start timer
                {
                    timer.Start();
                    frameTimer.Start();
                    sw.Start();
                    HotelEventManager.Start();
                    Console.WriteLine("Timer gestart");
                    panelPauze.Visible = false;
                    labelInfo.Text     = null;
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// game-specific content.
 /// </summary>
 protected override void UnloadContent()
 {
     _elevator.Detach(_cleaner);
     _elevator.Detach(_cleaner2);
     HotelEventManager.Stop();
     // TODO: Unload any non ContentManager content here
 }
Exemplo n.º 4
0
        public Form1(float hte, int cleaners, int cleaningTime, int movieDuration, int eatDuration, int elevatorDelay)
        {
            InitializeComponent();
            hotelStatus_label.Text = "Running";
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
            _Hotel = Hotel.GetInstance();
            _Hotel.CreateElevator(elevatorDelay);
            _Hotel.SetCleaners(cleaners, cleaningTime);
            _Hotel.SetScreeningTime(movieDuration);
            _Hotel.EatDuration = eatDuration;
            var hel = new HEListener();

            Paint += DrawHotel;

            HotelEventManager.Register(hel);
            HTE_Factor = hte;
            HotelEventManager.HTE_Factor = HTE_Factor;


            Timer = new System.Timers.Timer(1000 / HotelEventManager.HTE_Factor)
            {
                Enabled = true
            };
            Timer.Start();
            Stopwatch = new Stopwatch();
            Stopwatch.Start();

            HotelEventManager.Start();

            Timer.Elapsed += TimerHandler;
            Console.WriteLine(Timer.Interval);

            KeyUp += SpacePress;
        }
Exemplo n.º 5
0
        public SimulationForm(string fileLocation, Settings settings)
        {
            InitializeComponent();

            ImportLayout import = new ImportLayout();

            import.LayoutImport(fileLocation);

            Hotel.Settings = settings;


            Graph.CreateGraph();

            Hotel.Reception.HireCleaners(Hotel.Settings.CleanerAmount);

            _BackgroundBuffer = new Bitmap(Hotel.Floors[0].Areas.Length * 60 + 1, Hotel.Floors.Length * 55 + 1);
            _ForegroundBuffer = new Bitmap(Hotel.Floors[0].Areas.Length * 60 + 1, Hotel.Floors.Length * 55 + 1);
            _Wireframe        = new Bitmap(Hotel.Floors[0].Areas.Length * 60 + 1, Hotel.Floors.Length * 55 + 1);

            DrawBackground();

            HotelEventManager.Start();
            HotelEventManager.HTE_Factor = (float)Hotel.Settings.HTEFactor;

            TimerHTE.Interval = (int)(1000 / Hotel.Settings.HTEFactor);
            TimerHTE.Start();

            DrawForeground();

            BackgroundLayer.Size = _BackgroundBuffer.Size;
            Size = new Size(BackgroundLayer.Size.Width + BackgroundLayer.Location.X * 3, BackgroundLayer.Size.Height + BackgroundLayer.Location.Y * 3);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates an receptionist that can work with the hotel
 /// </summary>
 /// <param name="position">The position of the receptionist</param>
 /// <param name="hotel">The hotel in which the receptionist is located</param>
 public Receptionist(Point position, Hotel hotel)
 {
     Position = position;
     Hotel    = hotel;
     Area     = hotel.GetArea(typeof(Reception));
     Status   = MovableStatus.IDLE;
     HotelEventManager.Register(this);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Register as an eventlistener
 /// </summary>
 public void RegisterAs()
 {
     if (!Registerd)
     {
         HotelEventManager.Register(this);
         Registerd = true;
     }
 }
Exemplo n.º 8
0
        /// <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();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an instance of Reception with the given Parameters
        /// </summary>
        /// <param name="ID">ID of the Area</param>
        /// <param name="areaType">Type of Area</param>
        /// <param name="capacity">How many Humans can be in the Area at the same time</param>
        /// <param name="classification">The Classification of the Area</param>
        /// <param name="positionX">The horizontal point in the grid</param>
        /// <param name="positionY">The vertical point in the grid</param>
        /// <param name="width">The width of the Area</param>
        /// <param name="height">The height of the Area</param>
        public void Create(int ID, EAreaType areaType, int capacity, int classification, int positionX, int positionY, int width, int height)
        {
            this.ID   = ID;
            AreaType  = areaType;
            PositionX = positionX;
            PositionY = positionY;
            Width     = width;
            Height    = height;

            HotelEventManager.Register(this);
        }
Exemplo n.º 10
0
        public Simulation(List <LayoutJsonModel> layout, ConfigJsonModel ConfigJson)
        {
            InitializeComponent();
            // Setting form to fullscreen
            Rectangle resolution = Screen.PrimaryScreen.Bounds;

            this.Size        = resolution.Size;
            this.WindowState = FormWindowState.Maximized;

            // Placing Pauze panel on right location and hiding it
            panelPauze.Visible = false;
            double PauzeWidth  = resolution.Width * 0.20;
            double PauzeHeight = resolution.Height * 0.75;

            this.panelPauze.Size       = new Size((int)PauzeWidth, (int)PauzeHeight);
            this.panelPauze.Top        = (this.ClientSize.Height - panelPauze.Height) / 2;
            this.panelPauze.Left       = 10;
            this.labelGamePauzed.Width = this.panelPauze.Width;
            this.labelInfo.Width       = this.panelPauze.Width;
            this.labelInfo.Height      = this.panelPauze.Height - this.labelGamePauzed.Height;

            // initialize timer for hte
            timer.Tick += new EventHandler(OnTimedEvent);
            double MilisecondsPerHte = 1.0 / ConfigJson.HtesPerSecond;
            int    intervalOne       = Convert.ToInt32(MilisecondsPerHte * 1000); // van seconde milisecondes maken

            timer.Interval = (intervalOne >= 1) ? (int)intervalOne : 1;


            // initialize timer for frame updates
            frameTimer.Tick += new EventHandler(OnFrameTimerUpdate);
            int    FPS       = 60; // fps instelbaar
            double interval2 = (double)1000 / FPS;

            frameTimer.Interval = (interval2 >= 1) ? (int)interval2 : 1;

            // create hotel
            hotel = new Hotel(layout, ConfigJson, timer);
            hotel.Display(MainSimDisplay);
            hotel.hotelPB.Click += HotelPB_Click;
            hotel.AddMaid((int)ConfigJson.RoomCleaningHTE);
            hotel.AddMaid((int)ConfigJson.RoomCleaningHTE);

            // create eventmanager
            HotelEventManager.Register(new myEventListener(hotel));
            HotelEventManager.HTE_Factor = (int)ConfigJson.HtesPerSecond;

            // start simulation
            timer.Start();
            frameTimer.Start();
            sw.Start();
            HotelEventManager.Start();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Pauses the simulation
 /// </summary>
 private void Pause()
 {
     HotelEventManager.Pauze();
     if (HotelEventManager.Pauzed)
     {
         hotelStatus_label.Text = "Pauzed";
     }
     else
     {
         hotelStatus_label.Text = "Running";
     }
     Timer.Enabled = !HotelEventManager.Pauzed;
 }
Exemplo n.º 12
0
        public Manager(IRoom[,] coordinates, int amountOfMaids, MainForm main)
        {
            HotelEventManager.HTE_Factor = 1.5f;
            this.main          = main;
            this.amountOfMaids = amountOfMaids;
            this.coordinates   = coordinates;
            GenerateMaids();

            HotelEventManager.Register(this);
            dijkstra.CreateGraph(coordinates);

            TempPerson temp     = new TempPerson();
            Customer   customer = new Customer(temp);
        }
Exemplo n.º 13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Exit the simulation if there is no layout path.
            if (ServiceLocator.Get <ConfigLoader>().GetConfig().LayoutPath == null)
            {
                Environment.Exit(0);
            }

            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create new information window
            _informationWindow = new InformationWindow();

            // Make a new hotel.
            _hotel = new Hotel();

            // Register components to the roomfactory
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Room", new GuestRoomFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Empty", new EmptyRoomFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Lobby", new LobbyFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Cinema", new CinemaFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Restaurant", new CafeFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("ElevatorShaft", new ElevatorShaftFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Staircase", new StaircaseFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Fitness", new FitnessFactoryComponent());
            _hotel.HotelBuilder.RoomFactory.RegisterComponent("Pool", new PoolFactoryComponent());

            _hotel.BuildHotel();

            // Create other things.
            _camera             = new Camera(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            _camera.Controlable = true;
            _closeUpCamera      = new Camera(200, 200);

            // Create the handlers and managers and start throwing events.
            HotelEventManager.Start();
            HotelEventHandler hotelEventHandler = new HotelEventHandler(_hotel);

            _listener = new EventListener(hotelEventHandler);
            HotelEventManager.Register(_listener);

            // Create a background.
            _background = new Sprite();
            _background.LoadSprite("Background");
            _background.SetPosition(new Point(0, 0));
            _background.SetSize(new Point(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Pause the simulation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PauseButton_Click(object sender, EventArgs e)
 {
     if (buttonCounter % 2 == 0 || buttonCounter == 0)
     {
         HotelEventManager.Pauze();
         timer.Stop();
         pauseButton.Text = "Hervat";
         buttonCounter++;
     }
     else
     {
         HotelEventManager.Start();
         timer.Start();
         pauseButton.Text = "Pauze";
         buttonCounter++;
     }
 }
Exemplo n.º 15
0
        public MainForm(Settings settings)
        {
            this.settings          = settings; //store the selected settings
            timer.Interval         = 1000;     //set the tick frequency
            timerForMaids.Interval = 1000;
            roomFactory.GenerateEntity();
            manager = new Manager(roomFactory.coordinates, settings.amountOfMaids, this);

            //creating background and inintializing personLayout
            background   = draw.DrawLayout(roomFactory.coordinates);
            personLayout = new Bitmap(background.Width, background.Height);


            InitializeComponent();
            hotelMap.BackgroundImage = background; //set the background


            //Setup buttons
            int distanceButtons = 100;

            pauseButton.Location = new Point(background.Width + distanceButtons, hotelMap.Location.Y + distanceButtons);
            pauseButton.Size     = new Size(250, 100);
            pauseButton.Text     = "Pauze";
            pauseButton.Click   += new EventHandler(PauseButton_Click);
            speedButton.Location = new Point(background.Width + distanceButtons, pauseButton.Height + distanceButtons);
            speedButton.Size     = pauseButton.Size;
            speedButton.Text     = "Versnellen";
            speedButton.Click   += new EventHandler(SpeedButton_Click);
            stopButton.Location  = new Point(background.Width + distanceButtons, speedButton.Location.Y + distanceButtons);
            stopButton.Size      = pauseButton.Size;
            stopButton.Text      = "Stop";
            stopButton.Click    += new EventHandler(StopButton_Click);
            Controls.Add(pauseButton);
            Controls.Add(speedButton);
            Controls.Add(stopButton);

            //Start the hotel events
            HotelEventManager.Start();
            timer.Start();
            timerForMaids.Start();

            //call the update function after each timer tick.
            timer.Tick += new EventHandler(UpdateImage);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creating a maid to use in the hotel
        /// </summary>
        /// <param name="startLocation">The location in the hotel the maid is first put on after creation</param>
        /// <param name="hotel">The hotel the maid works in</param>
        public Maid(Point startLocation, Hotel hotel)
        {
            Hotel    = hotel;
            Position = startLocation;
            Area     = Hotel.GetArea(Position);

            Status = MovableStatus.IDLE;

            HotelEventManager.Register(this);

            Actions.Add(MovableStatus.IDLE, _IsSomthingInQueue);
            Actions.Add(MovableStatus.GOING_TO_ROOM, _GoToRoom);
            Actions.Add(MovableStatus.CLEANING, _Cleaning);
            Actions.Add(MovableStatus.ELEVATOR_REQUEST, _CallElevator);
            Actions.Add(MovableStatus.LEAVING_ELEVATOR, _LeavingElevator);
            Actions.Add(MovableStatus.WAITING_FOR_ELEVATOR, Idle);
            Actions.Add(MovableStatus.EVACUATING, _Evacuate);
            Actions.Add(MovableStatus.IN_ELEVATOR, null);
        }
Exemplo n.º 17
0
 /// <summary>
 /// When pressed on the pause button the simulation goes into pause state and once pressed again it resumes
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     if (!_pauseResume)
     {
         _pauseResume  = true;
         pauseBtn.Text = "Resume";
         label1.Text   = "Simulation has been paused";
         _timer.Stop();
         HotelEventManager.Pauze();
     }
     else
     {
         _pauseResume  = false;
         pauseBtn.Text = "Pause";
         label1.Text   = "Simulation is running on " + HotelEventManager.HTE_Factor + "Events per " + _timer.Interval + "milisecond";
         _timer.Start();
         HotelEventManager.Pauze();
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// imitialize hotelsimulation
 /// </summary>
 public HotelSimulation()
 {
     _roomQueue     = new Queue <Room>();
     _eventChecker  = new EventChecker();
     _huidigeCinema = new Cinema();
     _customers     = new List <Customer>();
     _reception     = new Reception();
     _hotel         = new Hotel();
     _simplePath    = new SimplePath();
     listener       = new EventListener();
     HotelEventManager.Register(listener);
     HotelEventManager.HTE_Factor = 4;
     HotelEventManager.Start();
     graphics = new GraphicsDeviceManager(this);
     //uncomment for fullscreen
     //graphics.IsFullScreen = true;
     //graphics.HardwareModeSwitch = false;
     _isPaused             = false;
     Content.RootDirectory = "Content";
 }
Exemplo n.º 19
0
        public void CheckEventManagerStart_OfTypeHotelEvent_IsActive()
        {
            // Arrange
            Hotel              hotel              = new Hotel();
            HotelEventManager  hotelEventManager  = new HotelEventManager();
            HotelEventObserver hotelEventObserver = new HotelEventObserver(hotel);
            bool expected = true;
            bool result   = false;

            // Act
            HotelEvents.HotelEventManager.Start();
            HotelEvents.HotelEventManager.Register(hotelEventObserver);
            while (result == false)
            {
                result = HotelEvents.HotelEventManager.Running;
            }
            HotelEvents.HotelEventManager.Stop();
            HotelEvents.HotelEventManager.Deregister(hotelEventObserver);
            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 20
0
        /// <summary>
        ///     Allows the game to perform any initialization it needs to before starting to run.
        ///     This is where it can query for any required services and load any non-graphic
        ///     related content.  Calling base.Initialize will enumerate through any components
        ///     and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            //add/create a new hotel
            hotel = new Hotel();

            //instantiate new listeners
            _checkInListener  = new CheckInListener(ref hotel);
            _checkOutListener = new CheckOutListener(ref hotel);

            //register listeners to HotelEventManager
            HotelEventManager.Register(_checkInListener);
            HotelEventManager.Register(_checkOutListener);

            //start HotelEventManager
            HotelEventManager.Start();

            this.IsMouseVisible = true;

            base.Initialize();
        }
Exemplo n.º 21
0
        /// <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();
        }
Exemplo n.º 22
0
        /// <summary>
        /// This is the constructor off the hotel
        /// </summary>
        /// <param name="file"></param>
        public Hotel(string file, Settings hte)
        {
            // Setting the settingsfile of this class
            this.hte = hte;

            // Definitions
            HotelTimer = new Stopwatch();
            Facilities = new List <LocationType>();

            // Methods
            CreateFactory();
            CreateFactoryObjects(file);
            LinkLocationTypes();
            CreateCleaners();

            // We add this class to the listener list so it can be updated
            HotelEventManager.Register(this);
            // Setting the HTE on how fast the events should come in
            HotelEventManager.HTE_Factor = hte.Hte;
            // Start the events
            HotelEventManager.Start();
            // Start the timer
            HotelTimer.Start();
        }
Exemplo n.º 23
0
        private void UserControlls()
        {
            // Reset the color of the object that was being hovered over
            if (_mouseIsOver != null)
            {
                _mouseIsOver.Sprite.Color = Color.White;
            }

            // Get the object the mouse is hovering.
            _mouseIsOver = _hotel.GetObject(_camera.ScreenToWorld(Input.Instance.GetMousePos()));

            if (_wasSelected != null)
            {
                _closeUpCamera.CamPosition = new Vector2(-_wasSelected.Position.X - _wasSelected.Sprite.DrawDestination.Width / 2, _wasSelected.Position.Y - _wasSelected.Sprite.DrawDestination.Height / 2);
            }

            // If a mouseover object is found
            if (_mouseIsOver != null)
            {
                // Highlight the sprite.
                _mouseIsOver.Sprite.Color = Color.LightGreen;

                // When the left mouse is clicked
                if (Input.Instance.OnLeftMouseButtonRelease())
                {
                    if (_mouseIsOver is Lobby)
                    {
                        Paused = !Paused;
                        HotelEventManager.Pauze();
                    }

                    // Check if the information window is already showing some data.
                    if (!_informationWindow.IsShowingInfo)
                    {
                        // Set the object as selected and show its information
                        _wasSelected = _mouseIsOver;
                        _informationWindow.ShowInformation(_mouseIsOver);
                    }
                    else
                    {
                        // Hide the information window
                        if (_wasSelected.Equals(_mouseIsOver))
                        {
                            _informationWindow.HideInformation();
                        }
                        else
                        {
                            // Update the information window
                            _wasSelected = _mouseIsOver;
                            _informationWindow.HideInformation();
                            _informationWindow.ShowInformation(_mouseIsOver);
                        }
                    }
                }
            }
            else
            {
                // Hide the information window
                if (Input.Instance.OnLeftMouseButtonRelease())
                {
                    _informationWindow.HideInformation();
                }
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Stop the simulation and go back to setting menu
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void StopButton_Click(object sender, EventArgs e)
 {
     HotelEventManager.Stop();
     this.Hide();
     settings.Show();
 }
Exemplo n.º 25
0
 /// <summary>
 /// Resuming the simulation and starting the events again
 /// </summary>
 private void _startSimulation()
 {
     _timer.Start();
     HotelEventManager.Start();
 }
Exemplo n.º 26
0
 private void CloseOnClick(object sender, EventArgs e)
 {
     this.Hide();
     if (cmbHTE_Time.Text != "")
     {
         HotelEventManager.HTE_Factor = (float)Math.Pow(2, Convert.ToInt32(cmbHTE_Time.Text) - 1);
     }
     if (cmbStairsSpeed.Text != "")
     {
         Stairs.Weight = -(Convert.ToInt32(cmbStairsSpeed.Text) - 6);
     }
     if (cmbStairsSpeed.Text != "")
     {
         SimplePath = new SimplePath();
         Hotel.AddToGraph(SimplePath);
     }
     if (Movie_Runtime_TXT.Text != "")
     {
         int parsedValue;
         if (int.TryParse(Movie_Runtime_TXT.Text, out parsedValue))
         {
             MovieTime = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(Movie_Runtime_TXT.Text, "[^\\d]")));
             foreach (Cinema cinema in Hotel.Areas.Where(r => r.AreaType == "Cinema"))
             {
                 Cinema TempCin = (Cinema)cinema;
                 TempCin.RunTime = MovieTime;
             }
         }
     }
     if (Eating_Speed_TXT.Text != "")
     {
         int parsedValue;
         if (int.TryParse(Eating_Speed_TXT.Text, out parsedValue))
         {
             EatingSpeed = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(Eating_Speed_TXT.Text, "[^\\d]")));
             foreach (Restaurant restaurant in Hotel.Areas.Where(r => r.AreaType == "Restaurant"))
             {
                 Restaurant TempRes = (Restaurant)restaurant;
                 TempRes.EatSpeed = EatingSpeed;
             }
         }
     }
     if (Cleaning_Speed_TXT.Text != "")
     {
         int parsedValue;
         if (int.TryParse(Cleaning_Speed_TXT.Text, out parsedValue))
         {
             CleanSpeed = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(Cleaning_Speed_TXT.Text, "[^\\d]")));
             foreach (Cleaner cleaner in Cleaners)
             {
                 cleaner.CleaningSpeed = CleanSpeed;
             }
         }
     }
     foreach (IPerson person in Persons)
     {
         person.RoundPosition();
     }
     if (!HotelEventManager.Running)
     {
         HotelEventManager.Pauze();
     }
 }
Exemplo n.º 27
0
 /// <summary>
 /// Stopping the simulation from running new events
 /// </summary>
 private void _stopSimulation()
 {
     _timer.Stop();
     HotelEventManager.Stop();
 }
 /// <summary>
 /// Creates a GlobalEventManager and registers it to the HotelEventManager
 /// </summary>
 public GlobalEventManager()
 {
     HotelEventManager.Register(this);
 }
Exemplo n.º 29
0
 private void MainGame_Exiting(object sender, EventArgs e)
 {
     (_listener as EventListener).Exit();
     HotelEventManager.Stop();
 }
Exemplo n.º 30
0
        /// <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
        }