Esempio n. 1
0
        /// <summary>
        /// Makes a person and based on the variables it will be either a maid or a customer.
        /// </summary>
        /// <param name="product">What person it's gonna be.</param>
        /// <param name="tempPerson">The temperory variables for the person that is about to be created.</param>
        /// <returns>Either a maid or a customer.</returns>
        public IPerson GetPerson(string product, TempPerson tempPerson)
        {
            Type type = Type.GetType(product);

            if (type != null)
            {
                return((IPerson)Activator.CreateInstance(type));
            }
            else
            {
                string nspace = "Hotel";

                //qeury for all the types
                var q = from x in Assembly.GetExecutingAssembly().GetTypes()
                        where x.IsClass && x.Namespace == nspace
                        select x;

                List <string> types = new List <string>();
                //put the query in the list
                foreach (Type t in q)
                {
                    types.Add(t.ToString());
                }
                //search the list and if found return instance.
                foreach (string t in types)
                {
                    if (t.Contains(product))
                    {
                        type = Type.GetType(t);
                        return((IPerson)Activator.CreateInstance(type, tempPerson));
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
 }                              //store if the maid is busy with something
 /// <summary>
 /// copy the tempPerson and create a maid
 /// </summary>
 /// <param name="tempPerson">the tempperson which becomes a maid</param>
 public Maid(TempPerson tempPerson)
 {
     this.id       = tempPerson.id;
     this.busy     = tempPerson.busy;
     this.position = new Point(1, 0);
     modelPerson   = Image.FromFile(@"..\..\Assets\StephansDreamMaid.png"); //the model
     modelPerson.RotateFlip(RotateFlipType.Rotate180FlipX);                 //rotate so its displayed correctly
 }
Esempio n. 3
0
        }                                   //where roompref is stored

        /// <summary>
        /// copy the tempPerson and create a customer
        /// </summary>
        /// <param name="tempPerson">The tempPerson which becomes a Customer</param>
        public Customer(TempPerson tempPerson)
        {
            this.id       = tempPerson.id;
            this.roomPref = tempPerson.roomPref;
            this.position = new Point(1, 0);
            modelPerson   = Image.FromFile(@"..\..\Assets\Customer.png"); //the model of the Customer
            modelPerson.RotateFlip(RotateFlipType.Rotate180FlipX);        //flip the model so it is displayed correctly
        }
Esempio n. 4
0
        /// <summary>
        /// Generates the amount of maids you want which you have decided before the simulation started.
        /// </summary>
        private void GenerateMaids()
        {
            TempPerson temp = new TempPerson();

            for (int i = 0; i < amountOfMaids; i++)
            {
                temp.id = "Maid " + (1 + i).ToString();
                people.Add((Maid)personFactory.GetPerson("Maid", temp), null);
                people.Last().Key.currentRoom = coordinates[1, 0];//lobby
                people.Last().Key.checkedIn = true;
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// Notify functions to launch all the events.
        /// </summary>
        /// <param name="evt">The event that is launched.</param>
        public void Notify(HotelEvent evt)
        {
            if (evt.EventType == HotelEventType.CHECK_IN && evt.Data != null)                //Handles the check in event.
            {
                TempPerson tempPerson = new TempPerson();                                    //create a temp person
                tempPerson.id       = evt.Data.Keys.FirstOrDefault();                        //store id
                tempPerson.roomPref = evt.Data.Values.FirstOrDefault();                      //store roompref

                Room room = getRoom(tempPerson.roomPref);                                    //get the pref room
                people.Add((Customer)personFactory.GetPerson("Customer", tempPerson), room); //create the customer
                Customer current = (Customer)people.Keys.Last();
                current.currentRoom = coordinates[1, 0];                                     //set the currentroom the customer is in to lobby
                ///if a room is found
                ///start a pathfinding
                if (room != null)
                {
                    current.checkedIn = true;
                    current.room      = room;
                    IRoom start = current.currentRoom;
                    IRoom end   = current.room;
                    FindPath(start, end, current);
                }
            }

            else if (evt.EventType == HotelEventType.CHECK_OUT || evt.EventType == HotelEventType.CLEANING_EMERGENCY) //Handles the Check out and cleaning emergency events.
            {
                if (evt.EventType == HotelEventType.CLEANING_EMERGENCY)
                {
                    //look which room needs to be cleaned
                    foreach (var element in coordinates)
                    {
                        string roomData          = evt.Data.Values.FirstOrDefault().ToString();
                        string HTE_Factor_number = evt.Data.Values.LastOrDefault();
                        float  HTE_Factor        = float.Parse(HTE_Factor_number);
                        if (element != null)
                        {
                            ///if room is found
                            ///start the cleaning
                            if (element.id.ToString() == roomData)
                            {
                                StartClean(element, evt.EventType);
                                HotelEventManager.HTE_Factor = HTE_Factor;
                            }
                        }
                    }
                }
                else//else its a checkout event
                {
                    foreach (var element in people)
                    {
                        if (element.Key.id.Contains("Gast"))
                        {
                            string peopleData = evt.Data.Keys.FirstOrDefault().ToString() + evt.Data.Values.FirstOrDefault().ToString();

                            if (peopleData == element.Key.id)
                            {
                                element.Value.dirtyRoom = true;
                                StartClean(element.Value, evt.EventType);

                                Customer current = null;
                                foreach (KeyValuePair <IPerson, IRoom> person in people)
                                {
                                    if (person.Key == element.Key)
                                    {
                                        current = (Customer)person.Key;
                                    }
                                }
                                IRoom end   = coordinates[1, 0]; //lobby
                                IRoom start = current.currentRoom;
                                FindPath(start, end, current);   //path to lobby
                                current.checkedIn = false;

                                break;
                            }
                        }
                    }
                }
            }
            else if (evt.EventType == HotelEventType.GOTO_CINEMA) //Handles the Go to Cinema event.
            {
                string data = evt.Data.Keys.FirstOrDefault().ToString() + evt.Data.Values.FirstOrDefault().ToString();
                foreach (IPerson person in people.Keys)
                {
                    if (person.id == data)
                    {
                        Customer current = (Customer)person;
                        if (current.checkedIn == true)
                        {
                            string endAreaType = "Cinema";
                            //send to closest cinema
                            try
                            {
                                IRoom start = coordinates[current.eventQueue.LastOrDefault().Last().position.X, current.eventQueue.LastOrDefault().Last().position.Y];
                                FindPathUnkown(start, endAreaType, current);
                            }
                            catch
                            {
                                IRoom start = current.currentRoom;
                                FindPathUnkown(start, endAreaType, current);
                            }
                        }
                    }
                }
            }
            else if (evt.EventType == HotelEventType.NEED_FOOD) //Handles the need food event.
            {
                string data = evt.Data.Keys.FirstOrDefault().ToString() + evt.Data.Values.FirstOrDefault().ToString();
                foreach (IPerson person in people.Keys)
                {
                    if (person.id == data)
                    {
                        Customer current = (Customer)person;
                        if (current.checkedIn == true)
                        {
                            string endAreaType = "Restaurant";
                            //send to closest restaurant
                            try
                            {
                                IRoom start = coordinates[current.eventQueue.LastOrDefault().Last().position.X, current.eventQueue.LastOrDefault().Last().position.Y];
                                FindPathUnkown(start, endAreaType, current);
                            }
                            catch
                            {
                                IRoom start = person.currentRoom;
                                FindPathUnkown(start, endAreaType, current);
                            }
                        }
                    }
                }
            }
            else if (evt.EventType == HotelEventType.GOTO_FITNESS)
            {
                string data = evt.Data.Keys.FirstOrDefault().ToString() + evt.Data.Values.FirstOrDefault().ToString();
                foreach (IPerson person in people.Keys)
                {
                    if (person.id == data)
                    {
                        Customer current = (Customer)person;
                        if (current.checkedIn == true)
                        {
                            string endAreaType = "Fitness";
                            //send to closest fitness
                            try
                            {
                                IRoom start = coordinates[current.eventQueue.LastOrDefault().Last().position.X, current.eventQueue.LastOrDefault().Last().position.Y];
                                FindPathUnkown(start, endAreaType, current);
                            }
                            catch
                            {
                                IRoom start = person.currentRoom;
                                FindPathUnkown(start, endAreaType, current);
                            }
                        }
                    }
                }
            }
            else if (evt.EventType == HotelEventType.EVACUATE)
            {
                IRoom end = coordinates[1, 0];
                evacuation = true;
                foreach (IPerson element in people.Keys)
                {
                    element.eventStarted = false;//set to false so perons who are in a event can start a new event
                    IRoom start = element.currentRoom;
                    //find path
                    if (start.position == element.position)
                    {
                        FindPathEvacuation(start, end, element, true);
                    }
                    else
                    {
                        IRoom nextRoom = element.currentRoom.neighbours.Keys.First();
                        FindPathEvacuation(nextRoom, end, element, true);
                        element.position = nextRoom.position;
                    }

                    if (element.position == new Point(1, 0))
                    {
                        evacCounter++;
                    }
                }
            }
        }